Jump to content

Probelm Printing From Database


dzhax

Recommended Posts

It doesn't work any idea how to fix?I'm trying the grab the data from the name field in the settings table

<?php$con = mysql_connect('localhost', 'username, 'password');if (!$con)	die("Could not connect...");$forumSetting = mysql_query("SELECT * FROM `settings`",$con);print("Forum Name: " . $forumSetting['name']);mysql_close($con);?>

All that is printing out is:

Forum Name:

I replaced the mysql_connect with fake values... the actual connect is different values. so dont worry bout that. it connects just fine.

Link to comment
Share on other sites

Guest FirefoxRocks
<?php$con = mysql_connect('localhost', 'username, 'password');if (!$con) {	die("Could not connect...");}$query = mysql_query("SELECT * FROM `settings`",$con);$forumSettings = mysql_fetch_assoc($query);print("Forum Name: " . $forumSetting['name']);mysql_close($con);?>

Or you can use mysql_fetch_row, which returns an array with numerical keys, or mysql_fetch_object, which returns an object. mysql_fetch_assoc in my code returns an associative array.

Link to comment
Share on other sites

I see why YOURS doesn't work, but FirefoxRocks' sample should work. What do you get if you do

$query = mysql_query("SELECT * FROM `settings`",$con);$forumSettings = mysql_fetch_assoc($query);var_dump($forumSettings);

?If you get "array()", it means that your query is simply not returning any results.

Link to comment
Share on other sites

thanks anyway boen the other guys worked.Seems like you know alot in this area would u mind taking a look at my most recent post in sql section?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...