$row[0]

Hello,

I know this may sound like a stupid question, but I just want to make sure I understand correctly.

After a query, what does $row[0] stand for/ result in?

Is my understanding correct that $row[0] shows ALL results?

HERE ARE EXAMPLES:

[php]$query = “SELECT count(commentid) from comments where jokeid = $jokeid”;

$result = mysql_query($query);

$row=mysql_fetch_array($result);

if ($row[0] == 0)

{

echo “No comments posted yet.  \n”;

} else

{

echo $row[0] . “\n”;
echo " comments posted.  \n";[/php]

AND THIS ONE

[php]$query = “Select count(prodid) from products where catid = $catid”;
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if ($row[0] == 0)
{
echo “


Sorry, there are no products in this category

\n”;
}
else
{
$totrecords = $row[0];[/php]

Thanks in advance,
Chris

No, not as I understand it.

Think of $result as a software object consisting of a collection of rows. Then when you use mysql_fetch_array() function and save the result to $row, I think all you do is take one of the rows. I’m not sure if it’s the first or the last, I guess that’s another question for someone more experienced. <–Update: Tizag says it’s the first.

So you have one of the rows of your database, and you can choose whether you want to access it as a regular or associative array. Usually people will do so as associative, but in the examples you give, they do so as a regular array.

in sum, I would say:
$row[0] returns the first (“zeroeth”) field of the first row to satisfy your query. Does that make sense?

Sponsor our Newsletter | Privacy Policy | Terms of Service