Jump to content

how to display output from SELECT


attaboy

Recommended Posts

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

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.

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.