Jump to content

mysql_fetch_array() - Need help


c_323_h

Recommended Posts

Hey everyone, I have a question about how mysql_fetch_array...

 

My PHP code looks like this:

 

$query = "my query here";

$result = mysql_query($query);

$row = mysql_fetch_array($result,MYSQL_NUM);

 

I ran a MySQL query through the client and it returns this (which is how I want it):

 

+--------------------------+-----------------------------+

|          date                    |                name                  |

+--------------------------+-----------------------------+

|          Wednesday            |                  Bill                  |

|          Wednesday            |                  Bob                  |

|          Thursday              |                  Joe                  |

+--------------------------+-----------------------------+

 

Where date and name are the two columns.

 

Now, how would I reference these values after using mysql_fetch_array()? I tried

 

echo $row[0]. " " .$row[1]; but it doesn't output anything.

 

 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/42873-mysql_fetch_array-need-help/
Share on other sites

That should work, but it would only show one row. To get all three, you would need to put the mysql_fetch function in a loop. Also, I prefer to use the mysql_fetch_assoc() function.

 

<?php
$query = "my query here";
$result = mysql_query($query) or die("Problem with the query <pre>$query</pre><br>" . mysql_error());
while ($row = mysql_fetch_assoc($result))
    echo $row['date'] . ' ' . $row['name'] . '<br>';
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.