attaboy Posted September 3, 2012 Share Posted September 3, 2012 This code works fine till I put in this "print($res);" <?php $mysqli = mysqli_connect('localhost', 'root', '', 'jquery'); if(mysqli_connect_errno()) { printf('Connect failed: %s\n', mysqli_connect_error()); exit(); } else { $sql = "SELECT * FROM users"; $res = mysqli_query($mysqli, $sql); if($res) { $number_of_rows = mysqli_num_rows($res); printf("Result set has %d rows.\n", $number_of_rows); } else { printf("Could nor retreve records: %s\n", mysqli_error($mysqli)); } printf($res); // I want to display the results of the SELECT, how is it done? mysqli_free_result($res); mysqli_close($mysqli); } ?> I don't know how to display the output from a SELECT statement. Link to comment https://forums.phpfreaks.com/topic/267930-how-to-display-output-from-select/ Share on other sites More sharing options...
Jessica Posted September 3, 2012 Share Posted September 3, 2012 Did you look at the examples on mysqli_query? Link to comment https://forums.phpfreaks.com/topic/267930-how-to-display-output-from-select/#findComment-1374769 Share on other sites More sharing options...
attaboy Posted September 3, 2012 Author Share Posted September 3, 2012 Thanks for your reply. I found something that works. <?php $mysqli = mysqli_connect('localhost', 'root', '', 'jquery'); if(mysqli_connect_errno()) { printf('Connect failed: %s\n', mysqli_connect_error()); exit(); } else { $sql = "SELECT * FROM users"; $res = mysqli_query($mysqli, $sql); if($res) { $number_of_rows = mysqli_num_rows($res); printf("Result set has %d rows.<br>", $number_of_rows); } else { printf("Could nor retreve records: %s\n", mysqli_error($mysqli)); } while($row = mysqli_fetch_array($res)){ echo $row[0].' '; echo $row[1].' '; echo $row[2]; echo '<br>'; } mysqli_free_result($res); mysqli_close($mysqli); } ?> It's only been a few months since my PHP class and already I forgot about the mysqli_fetch_array thing. Link to comment https://forums.phpfreaks.com/topic/267930-how-to-display-output-from-select/#findComment-1374774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.