Helpful Information
 
 
Category: Software Design
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?

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

I am sorry I didn't respond here earlier. I have a solution for this in PHP.



$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.










privacy (GDPR)