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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.