c_323_h Posted March 15, 2007 Share Posted March 15, 2007 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 More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 while ($row = mysql_fetch_array($result)) { // processing here } Link to comment https://forums.phpfreaks.com/topic/42873-mysql_fetch_array-need-help/#findComment-208207 Share on other sites More sharing options...
kenrbnsn Posted March 15, 2007 Share Posted March 15, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42873-mysql_fetch_array-need-help/#findComment-208214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.