sanchez77 Posted August 3, 2009 Share Posted August 3, 2009 i read it, i read that, i re-read this, and I just don't get it. How do you query a table for a value and store that value as a variable in php? Link to comment https://forums.phpfreaks.com/topic/168716-solved-php-variables-and-mysql/ Share on other sites More sharing options...
TeNDoLLA Posted August 3, 2009 Share Posted August 3, 2009 <?php mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db('test_database') or die(mysql_error()); $sql = "SELECT id, name FROM test_table LIMIT 1"; // This will take only one row bcause of limit. $result = mysql_query($sql) or die(mysql_error()); $result = mysql_fetch_array($result); $myVariableName = $result[0]['name']; $myVariableId = $result[0]['id']; // print the variable contents echo 'Name: ' . $myVariableName . ' and ID: ' . $myVariableId; Link to comment https://forums.phpfreaks.com/topic/168716-solved-php-variables-and-mysql/#findComment-890118 Share on other sites More sharing options...
sanchez77 Posted August 3, 2009 Author Share Posted August 3, 2009 awesome, had to take out the [0] in $result and it worked. thanks alot cheers Link to comment https://forums.phpfreaks.com/topic/168716-solved-php-variables-and-mysql/#findComment-890127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.