SQL question
- Started
- Last post
- 3 Responses
- section_014
I'm trying to receive 2 results from 1 field in 1 statement. Here's my code:
SELECT categories_name FROM categories_description WHERE categories_id IN (21,30)
However, it's only retrieving one record. I don't use the "IN" statement that much, but from what I've read I'm doing it right. 21 & 30 are integers in the db so they don't need quotes. Even if I manually put numbers in other than those two it always returns the first only.
I'm using mysql_query to run the query and mysql_fetch_array to get an array and print_r to view the array(or lack there of).
Thanks
- acescence0
mysql_fetch_array only returns one row at a time. you need to loop thru the result to get all of the rows
- acescence0
$result = mysql_query( "SELECT blah" );
while ( $row = mysql_fetch_array($result, MYSQL_NUM) ) {
print_r( $row );
}
- section_0140
oh, I didn't realize it only returned one result. I thought it returned an array, hence the name. I know the number of rows ahead of time and was using it like:
echo $row[0];
echo $row[1];Weird.