Page 1 of 1

mysql_fetch_array only returns first of three total rows?

Posted: Fri Nov 21, 2008 3:49 pm
by JAB Creations
For some reason the following PHP only returns the first of three rows of data. It should return "36", "37", "38" as the exact query returns in phpMyAdmin though only returns "36". I've also tried putting the static command that works in phpMyAdmin in to $query1 so I'm at a loss right now. Suggestions please?

Code: Select all

$query1 = "SELECT tag_id FROM blog_tags WHERE tag_name='".implode("' OR tag_name='",$tags_remove)."'";
$mysql_query1 = mysql_query($query1);
$row1 = mysql_fetch_array($mysql_query1);
print_r($row1['tag_id']);

Re: mysql_fetch_array only returns first of three total rows?

Posted: Fri Nov 21, 2008 3:58 pm
by JAB Creations
I would have thought print_r would have displayed the entire array...isn't there an array equivalent to print_r then I vaguely recall?

Code: Select all

$query1 = "SELECT tag_id FROM blog_tags WHERE tag_name='".implode("' OR tag_name='",$tags_remove)."'";
$mysql_query1 = mysql_query($query1);
 
while($row1 = mysql_fetch_array($mysql_query1))
{
 echo '<div>';
 print_r($row1['tag_id']);
 echo '</div>';
}

Re: mysql_fetch_array only returns first of three total rows?

Posted: Fri Nov 21, 2008 4:12 pm
by JAB Creations
Right, var_dump...

Code: Select all

$query1 = "SELECT tag_id FROM blog_tags WHERE tag_name='".implode("' OR tag_name='",$tags_remove)."'";
$mysql_query1 = mysql_query($query1);
 
 $row1 = mysql_fetch_array($mysql_query1);
var_dump($row1);

Re: mysql_fetch_array only returns first of three total rows?

Posted: Fri Nov 21, 2008 4:13 pm
by Mark Baker
JAB Creations wrote:I would have thought print_r would have displayed the entire array...isn't there an array equivalent to print_r then I vaguely recall?
print_r() will display the entire array... when you pass it the entire array rather than just one value in the array

Code: Select all

$query1 = "SELECT tag_id FROM blog_tags WHERE tag_name='".implode("' OR tag_name='",$tags_remove)."'";
$mysql_query1 = mysql_query($query1);
 
while($row1 = mysql_fetch_array($mysql_query1))
{
 echo '<div>';
 print_r($row1);
 echo '</div>';
}

Re: mysql_fetch_array only returns first of three total rows?

Posted: Fri Nov 21, 2008 4:21 pm
by JAB Creations
...while in a loop. I originally tried it without specifying any rows...

Code: Select all

$query1 = "SELECT tag_id FROM blog_tags WHERE tag_name='".implode("' OR tag_name='",$tags_remove)."'";
$mysql_query1 = mysql_query($query1);
$row1 = mysql_fetch_array($mysql_query1);
print_r($row1);
...with the exact same results.

Re: mysql_fetch_array only returns first of three total rows?

Posted: Fri Nov 21, 2008 4:31 pm
by VladSun
Jab??? mysql_fetch_array() returns only single row of the SQL result set of rows ...

Re: mysql_fetch_array only returns first of three total rows?

Posted: Fri Nov 21, 2008 4:40 pm
by JAB Creations
The array will be merged in to another...though I'm going to start a fresh thread because my OP considered this thread has technically been resolved. On to merging arrays! :mrgreen:

Yes...blog tags has really warped my mind of late so please tolerate my oddness for just a wee bit longer. :twisted: