#1
  1. Always Spell Chek
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Location
    NJ, USA
    Posts
    338
    Rep Power
    13

    Selecting row where column value true.


    I have a table in MYSQL which contains 4 fields. It is a settings table for my website. I have a title, varname, value, and id field. What I am trying to do is get the value field by calling the varname.

    Like this:

    Row:

    ID=1
    Title=Website Title
    Varname=title
    Value=MyTitle

    What I would like to include in my template is $setting[title]

    I am trying to fetch row values in the same row as the varname which I have named. What is the process I need to be looking into to do this?

    1. Connect to database
    2. Read Array
    3. Get Array Value
    4. Compare Array Value to column values in "Varname"
    5. If true get "Value" from same row.
    6. Return "Value"
    7. Format "Value"

    Am I right about that and can you tell me if I am expecting the right result using an associative array?
    Programming is easy. It's the thinking that's hard.

    Search the forums before you ask your question.
    PHP | MySQL websites. Visit them, read them, cherish them.
    Read the posting rules, before you post.
    See if your question has been answered already.
  2. #2
  3. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    3,608
    Rep Power
    27
    You would just issue a query like
    SELECT value FROM table WHERE Varname='$varname'

    Then you'll just get one variable returned (value) which could be fetched with mysql_result(). If you want to grab all fields for that row you would get them in an associative array, yes.

    Or am I misunderstanding you?

    //NoXcuz
    UN*X is sexy!
    who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep
  4. #3
  5. Always Spell Chek
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Location
    NJ, USA
    Posts
    338
    Rep Power
    13
    I am sorry I didn't respond here earlier. I have a solution for this in PHP.

    PHP Code:
    $settings $DB_local->query("SELECT varname,value FROM settings WHERE varname != ''");
    while(
    $row mysql_fetch_object($settings)){
    $setting[$row->varname] = $row->value;

    Thanks for your help anyway.
    Programming is easy. It's the thinking that's hard.

    Search the forums before you ask your question.
    PHP | MySQL websites. Visit them, read them, cherish them.
    Read the posting rules, before you post.
    See if your question has been answered already.

IMN logo majestic logo threadwatch logo seochat tools logo