MySQL Query Results Aren't Visible

Hi there,
I’m kind of having the same problem as the poster before me.

I’m trying to display the query results in a table but as of right now all that is visible is the table border. Any advice would be greatly appreciated.

Thanks,

[code]

Untitled [/code] [php]<?php // Establish a connection with the database server $db = mysql_connect("localhost","icomdesign","arloguthrie")or die("ERROR.O1"); mysql_select_db("icomdesign")or die("ERROR. O2");
	$results=mysql_query($db,"SELECT * FROM ananda");

//echo $results;

print "

";

while($row=mysqli_fetch_array($results))
{
print "

"; } //echo "
" . $row['field1'] ." " . $row['field2'] ." " . $row['field3'] ."
";

//mysqli_close($db);

?>[/php]
[code]</table>
[/code]

You have a typo in your code…

[php]$results=mysql_query($db,“SELECT * FROM ananda”); // mysql_…
while($row=mysqli_fetch_array($results)) // mysqli_…
[/php]

You can’t mix mysql/mysqli like this, go with the mysqli, it’s safer and the old mysql is being depreciated.
Red :wink:

Thanks Red! I did a quick “replace all”. I am now seeing the ERROR_O2 message that I put in the code. I believe that error message means that i’m not selecting the datababase. What should I do now?

LP

[php]<?php
	// Establish a connection with the database server
	$db = mysqli_connect("localhost","icomdesign","arloguthrie")or die("ERROR.O1");
	mysqli_select_db("icomdesign"/*,$db*/)or die("ERROR. O2");
	
	$results=mysqli_query($db,"SELECT * FROM ananda");

//echo $results;

print "

";

while($row=mysqlii_fetch_array($results))
{
print "

"; } //echo "
" . $row['field1'] ." " . $row['field2'] ." " . $row['field3'] ."
";

//mysqlii_close($db);

?>[/php]

ahh, I forgot to mention it’s a slightly different syntax for a few things, take a look here at the manual at the subtle differences.
Yours is the way your connecting to the database :wink:

Well I didn’t understand most of what was on that link you posted. I tried going by w3schools connection example. I think i’m connected to the db now but nothing is being displayed.

[php]<?php
//create connection
$db=mysqli_connect(“icomdesign.com”,“icomdesign”,“arloguthrie”,“icomdesign”);

//check connection
if (mysqli_connect_errno($db))
(
echo "Failed to connect to MySQL: " . mysqli_connect_error();
)

mysqli_select_db("icomdesign"/*,$db*/)or die("ERROR.O2");
	
	$results=mysqli_query($db,"SELECT * FROM ananda");

//echo $results;

echo "

";

while($row=mysqlii_fetch_array($results))
{
echo "

"; } //echo "
" . $row['field1'] ." " . $row['field2'] ." " . $row['field3'] ."
";

//mysqlii_close($db);

?>
[/php]

a brief read through your code i see a typo:
[php]while($row=mysqlii_fetch_array($results)) // <<< double ii should be a single i: mysqli[/php]
Red :wink:

Thanks for your help. I reverted back to the old language and I finally got the results that I was expecting. See below:

http://www.icomdesign.com/Ananda/assignment5.html

I need to add a column to the table. I can do that with the ALTER TABLE statement. Does it need to be in a separate function or can I put it above the other statements in the already working function $sql?

When I read through your code below, I see an error with the brackets. You’re using () instead of {} in your error checking IF.

Here is a snippet written using mysqli.

(Note: Do NOT use the die statements in a live environment for security reasons.
When you finished testing and you’re setting the site loose on the public,
comment out the die() statements
. :wink: )

[php]<?php
// Setup a connection.
$dbc = mysqli_connect(“icomdesign.com”,“icomdesign”,“arloguthrie”,“icomdesign”) or die(mysqli_connect_error($dbc));
// Run a query.
$result = mysqli_query($dbc, “SELECT * FROM ananda”) or die(mysqli_error($dbc));
?>

<?php // Print the results. while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo ""; } ?>
" . $row['field1'] . " " . $row['field2'] . " " . $row['field3'] . "
[/php]

I’m not sure I understand your new question about altering the database,
Do you want to add a new column each time or just once?

Red.

Sponsor our Newsletter | Privacy Policy | Terms of Service