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
    Jul 2004
    Location
    Tampa
    Posts
    223
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Storing Site Verbiage in a Table

    I am setting up a site I want to use for a few clients. I want to be able to edit the verbiage in a table and it update the language everywhere it is used sitewide. I setup a table like this:

    langid
    langname
    langecho
    langstatus

    I have the langid as the primary key with autoincrement on. The name is what I use to identify it, then the langecho is the actual verbiage and the langstatus is what is going I was going to use to say this is a top menu button, a left menu button, etc. I have it as an int and have another table that stores what each int is for.

    What I would like to be able to do is query the table for the top menu include and pull out just the top menu items.

    Code:
    $buttonlang = mysql_query("SELECT langname, langecho from language WHERE langstatus = 1") or die(mysql_error());
    $return mysql_fetch_assoc($buttonlang);
    Then in the page, assign the langecho to the variable for whatever is in the langname field so

    Code:
    $langname = $buttonlang['langecho']
    and repeat it for all results so that the variable for langname has the value of the lang echo.

    I hope this makes sense.

    Any help would be greatly appreciated.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Look into variable variables.
    Something like this should work:
    PHP Code:
    while($row mysql_fetch_assoc($result))
    {
        
    $langname $row['langname'];
        $
    $langname $row['langecho'];
    }

    // or make a language array
    $lang = array();
    while(
    $row mysql_fetch_assoc($result))
    {
        
    $lang[$row['langname']] = $row['langecho'];
    }

    // echo $lang['buttonname']; 
    Not tested.

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Location
    Tampa
    Posts
    223
    Thanks
    23
    Thanked 0 Times in 0 Posts
    OKay, so I have this so far...

    Code:
    <?php
    $buttonlang = mysql_query("SELECT langname, langecho from language WHERE langstatus = 1") or die(mysql_error());
    $row_buttonlang = mysql_fetch_assoc($buttonlang);
    
    while($row_buttonlang = mysql_fetch_assoc($buttonlang))
    {
        $langname = $row_buttonlang['langname'];
        $$langname = $row_buttonlang['langecho'];
    }
    ?>
    but when I echo this

    Code:
    <?php echo $langname['butt_mytimeoff']; ?>
    All that comes out is the letter "b" but the value of langecho is "My Time Off"

    Any thoughts? Also, what does the double dollar sign do?

    Thanks for your help!

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by dprichard View Post
    OKay, so I have this so far...

    Code:
    <?php
    $buttonlang = mysql_query("SELECT langname, langecho from language WHERE langstatus = 1") or die(mysql_error());
    $row_buttonlang = mysql_fetch_assoc($buttonlang);
    
    while($row_buttonlang = mysql_fetch_assoc($buttonlang))
    {
        $langname = $row_buttonlang['langname'];
        $$langname = $row_buttonlang['langecho'];
    }
    ?>
    but when I echo this

    Code:
    <?php echo $langname['butt_mytimeoff']; ?>
    All that comes out is the letter "b" but the value of langecho is "My Time Off"
    If you're going to use something like that look at my second example. I already laid it out for you.

    Quote Originally Posted by dprichard View Post
    Also, what does the double dollar sign do?
    Quote Originally Posted by Inigoesdr View Post

  • #5
    Regular Coder
    Join Date
    Jul 2004
    Location
    Tampa
    Posts
    223
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Thank you for your help. This was my final solution:

    Code:
    <?php
    $lang = mysql_query("SELECT langname, langecho from language WHERE langstatus = 1") or die(mysql_error());
    $row_lang = mysql_fetch_assoc($lang);
    
    do 
    {
        $langname = $row_lang['langname'];
    	$$langname = $row_lang['langecho'];
    } 
    while($row_lang = mysql_fetch_assoc($lang));
    ?>
    Then i put the results in the page like this:

    Code:
    <?php echo $buttonname; ?>
    buttonname being the value in the column langname that corresponded with the langecho I wanted. The results showed the contents of the langecho column.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    If you use a while() loop instead of do/while you won't need to have that first $row_lang = mysql_fetch_assoc(); line.


  •  

    Posting Permissions

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