...

View Full Version : MySQL Field Reading, can you improve my code?



kaisellgren
06-15-2006, 03:53 PM
Hello,

My code for receiving forum name from mysql table:

$forumname = mysql_query("SELECT forumname FROM settings");
$a = mysql_fetch_assoc($forumname);
echo $a["forumname"];

I'm sure it can be improved, but I have no idea. Help?

Kid Charming
06-15-2006, 04:03 PM
Are you trying to get all of your forum names?

If so, you need to run your result set through a loop to pull out each name. If not, you should set up a WHERE clause or ORDER BY/LIMIT in your query to only return the name you want.

kaisellgren
06-15-2006, 04:08 PM
I have only one forumname that is stored in mysql, and I need to echo it to the forum logo. It works with that way, but I think that's not correct way to do it (with arrrays) ?

Kid Charming
06-15-2006, 04:14 PM
If you've only got the one row, the code you used is fine. You could make it slightly more efficient by using mysql_fetch_row() instead of *_assoc() and echoing $a[0] (using numeric indexes instead of strings).

But, for something like this, I wouldn't bother storing it in a db at all. Unless your forum name's going to be changing, I'd just hardcode it.

kaisellgren
06-15-2006, 04:18 PM
Ah okay. Thanks. I changed it to fetch_row, it works fine.

It seems that you are quite active in these forums :)

Are you moderator/admin/other 'php freak' ? :)

Kid Charming
06-15-2006, 04:20 PM
It seems that you are quite active in these forums :)

Are you moderator/admin/other 'php freak' ? :)

Nah, just a Kid. ;)

There are many others 'round here more active than I.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum