嘿我在构建这个mysql查询时遇到了麻烦,现在我已经把我困住了大约一个星期,我希望有人有答案,可以帮助我学习!
我的表看起来像这样: {{0}}
我想要什么 我希望从我的表中获取所有值的用户名或电子邮件='abc123'以及攻击强度防御敏捷等的值......等等。 0
所以基本上我怎么才能得到我的列中的值大于0并且值与正确的用户名和电子邮件相关联的行
任何帮助将不胜感激!我不确定我是否解释了这个最好的方式,但id爱帮助澄清!
这是我到目前为止所做的工作
SELECT Attack, Strength, Defense, Magic, Ranged, Prayer, Runecrafting, Dungeoneering, Construction, Constitution, Agility, Herblore, Thieving, Crafting, Slayer, Hunter, Mining, Smithing, Fishing, Cooking, Firemaking, Woodcutting, Farming, Summoning FROM experience WHERE email = abc123 OR username = abc123
答案 0 :(得分:1)
SELECT Attack, Strength, Defense, Magic, Ranged, Prayer, Runecrafting, Dungeoneering, Construction, Constitution, Agility, Herblore, Thieving, Crafting, Slayer, Hunter, Mining, Smithing, Fishing, Cooking, Firemaking, Woodcutting, Farming, Summoning FROM experience WHERE (email = "abc123" OR username = "abc123") AND Attack > 0 AND Strength > 0 AND Defense > 0 AND *etc*
答案 1 :(得分:1)
为什么这不起作用? where (email = 'abc123' OR username = 'abc123') and attack > 0 and strength > 0 and
。 。
如果符合以下条件,则如下所示:
if( (email == 'abc123' || username == 'abc123') && stength > 0)
“()”与“||”之间的第一部分意味着最后一个条件必须是真实的。和&&外表示最后一个条件也必须为真。
我还建议您使用用户ID,因为它确实比用户名/电子邮件更好
答案 2 :(得分:0)
SELECT Attack, Strength, Defense, Magic, Ranged, Prayer, Runecrafting, Dungeoneering, Construction, Constitution, Agility, Herblore, Thieving, Crafting, Slayer, Hunter, Mining, Smithing, Fishing, Cooking, Firemaking, Woodcutting, Farming, Summoning FROM experience WHERE (email = abc123 OR username = abc123) AND (Attack + Strength + Defense + Magic + Ranged + Prayer + Runecrafting + Dungeoneering + Construction + Constitution + Agility + Herblore + Thieving + Crafting + Slayer + Hunter + Mining + Smithing + Fishing + Cooking + Firemaking + Woodcutting + Farming + Summoning > 0);
不幸的是,除非你有一个列来总结所有的统计数据,否则实现你想要的唯一方法是手动比较所有,在这种情况下我使用+
来总结它。
答案 3 :(得分:0)
无法找到一种方法从我想要的方式将数据从数据库中取出,所以我决定最好从表中提取所有数据并使用php过滤它
$stmt2 = $DB_con->prepare("SELECT * FROM experience WHERE username = :uname OR email = :email");
$stmt2->execute(array(':uname' => $_SESSION['username'], ':email' => $_SESSION['email']));
$rowExperience = $stmt2->fetch(PDO::FETCH_ASSOC);
$skills = array("Attack", "Strength", "Defense", "Magic", "Ranged", "Prayer", "Runecrafting", "Dungeoneering", "Construction",
"Constitution", "Agility", "Herblore", "Thieving", "Crafting", "Fletching", "Slayer", "Hunter", "Mining", "Smithing","Fishing", "Cooking", "Firemaking", "Woodcutting", "Farming", "Summoning");
for($i = 0; $i < count($skills); $i++) {
if(intval($rowExperience[$skills[$i]]) > 0) {
echo '<td style="color:grey;">' . $skills[$i] . ' - ' . $rowExperience[$skills[$i]] . '</td>';
}
}