Jump to content

Probelm Printing From Database


dzhax
 Share

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.

Edited by boen_robot
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?

Edited by dzhax
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...