• 0

MySQL/PHP Retrieving Variables


Question

Hi guys,

I've taken a stab at a little web project, and now i've got some variables which i'd like to be able to change. I've put the variables in a MySQL table with 'id' 'variable' and 'value' as columns. Could someone please help me out with retreiving just the 'value' of each row? In a php config file i'd have something like:

$variablename = $result['blahblahblahblah'];

$variablename = $result['blahblahblahblah'];

$variablename = $result['blahblahblahblah'];

etc.

These would all be in the same table, at the moment i'm just getting the value of the last row.

Any help would be appreciated.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

$query = "SELECT value FROM tablename";
$sql = mysql_query($query, $db);

for ($i = 0; $i < mysql_num_rows($sql); $i++)
  $results[$i] = mysql_result($sql, $i, "value");

The values in the value column are now in the $results[] array with the array index being the row. Of course, you can extend the SQL statement to filter results, to order it and to limit it. If you don't need to use the value more than once, you could just do what you need to do with it in the for statement instead of using memory by saving it.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.