mysql_fetch_array only returns first of three total rows?

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
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

mysql_fetch_array only returns first of three total rows?

Post 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']);
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: mysql_fetch_array only returns first of three total rows?

Post 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>';
}
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: mysql_fetch_array only returns first of three total rows?

Post 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);
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: mysql_fetch_array only returns first of three total rows?

Post 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>';
}
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: mysql_fetch_array only returns first of three total rows?

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: mysql_fetch_array only returns first of three total rows?

Post by VladSun »

Jab??? mysql_fetch_array() returns only single row of the SQL result set of rows ...
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: mysql_fetch_array only returns first of three total rows?

Post 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:
Post Reply