Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts

    MySQL Field Reading, can you improve my code?

    Hello,

    My code for receiving forum name from mysql table:
    PHP Code:
    $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?
    PHP 5 & MySQL 5 (Y)

  • #2
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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) ?
    PHP 5 & MySQL 5 (Y)

  • #4
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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' ?
    PHP 5 & MySQL 5 (Y)

  • #6
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by kaisellgren

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •