owaisakber Posted October 27, 2014 Share Posted October 27, 2014 Hi all, I'm new to PHP have written some code to extract data from mysql. here it is<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8" /> <title></title> </head> <body> <?php echo "Testing Database....<br>"; $con = mysqli_connect('localhost', 'db_id', 'my_pw', 'mysql_db'); $result = $con->query("SELECT user_id FROM users"); echo "Number of users : ".$result->num_rows."<br><br>"; $row = mysqli_fetch_row($result); echo $row[0]."<br>"; echo $row[1]."<br>"; echo $row[2]."<br>"; ?> </body></html>in result number of rows its giving right, but when i fetch the result in row, its giving only first row. rest all are empty.then further i have tested few more things like, i change the query as below'SELECT * FROM users'now this is giving another strange result. It selected first row of the table and making array for all available columns. i have attached herewith image of my table, and result of both of my queries. Could someone guide me on this issue... Link to comment https://forums.phpfreaks.com/topic/292091-fetch-array-result/ Share on other sites More sharing options...
tryingtolearn Posted October 27, 2014 Share Posted October 27, 2014 The result is an array so without a loop you will only get 1 result replace $row = mysqli_fetch_row($result); echo $row[0]."<br>"; echo $row[1]."<br>"; echo $row[2]."<br>"; with /* fetch associative array */ while ($row = mysqli_fetch_row($result)) { echo $row[0]."<br />"; } Link to comment https://forums.phpfreaks.com/topic/292091-fetch-array-result/#findComment-1494907 Share on other sites More sharing options...
Barand Posted October 27, 2014 Share Posted October 27, 2014 Could someone guide me on this issue... Had you considered reading the manual? http://uk1.php.net/manual/en/function.mysql-fetch-row.php Link to comment https://forums.phpfreaks.com/topic/292091-fetch-array-result/#findComment-1494918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.