mysql query - WHERE ... AND WHERE possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MuffinMan
Forum Newbie
Posts: 7
Joined: Tue Apr 22, 2003 4:12 am
Location: Germany
Contact:

mysql query - WHERE ... AND WHERE possible?

Post by MuffinMan »

I am quite desperately trying to do a query like that:

Code: Select all

<?php
$query = "SELECT * FROM chess_1 WHERE row='$row' AND column='$column'";
$result = mysql_query($query, $connection) or die('error making query');
for ($b=0;$b<5;$b++)
{
         $row = mysql_fetch_row($result);		
}

?>
$row and $column contain a number, row and column fields are tinyint, filled with numbers between 0 and 63, unique, null and default NULL

first of all, is it possible at all to do a WHERE AND WHERE or is it some other operator or something i really don't know what else to try, tried about every way to write it and searched for code snippets and all but couldn't find anything... plz help! :roll:
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

First of all you are doi'ng:

Code: Select all

for ($b=0;$b<5;$b++) 
&#123; 
         $row = mysql_fetch_row($result);       
&#125;
How do you know that there are 5 results? Never do this.

Instead use:

Code: Select all

<?php 
$query = "SELECT * FROM `chess_1` WHERE `row`='$row' AND `column`='$column'"; 
$result = mysql_query($query, $connection) or die('error making query'); 
while($row = mysql_fetch_array($result))&#123;
  $b++;
  // enz
&#125;
?>
About the query, are you sure that $row AND $column has values in them?
Just echo the $query to make sure that it's exectly what you want.

Maybe manualy check in the database if the values are in the database if the query is correct.

PS: issent row a reserved word?
MuffinMan
Forum Newbie
Posts: 7
Joined: Tue Apr 22, 2003 4:12 am
Location: Germany
Contact:

Post by MuffinMan »

many many thanks man! this has solved the problem i took your version and changed the row-field to some other name, and now it works! btw: can you build multi-dimensional arrays with php? something like int [][][]arrayname in c for example, is that possible in php? 2 - dimensions would be enough though, just curious...?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can have multi-dimensional arrays in PHP, have a read of:
http://www.php.net/manual/en/language.types.array.php

Mac
MuffinMan
Forum Newbie
Posts: 7
Joined: Tue Apr 22, 2003 4:12 am
Location: Germany
Contact:

Post by MuffinMan »

ah thanks! - i see, i would have been able to create such an array then but i would definitely have run into this error!
Post Reply