wframe Posted March 30, 2011 Share Posted March 30, 2011 Hello guys, I was wondering if there is a way to read data from a mysql table and store it in a php variable. It seems simple but I can't quite get it together. Basically, I'd like to update a record in the database and retrieve it by passing it to a php variable. My table only has one column and row, so i don't need a "WHERE" function in my query (i.e. "SELECT * FROM table WHERE...) Something like below: $query="SELECT something FROM table"; ..... ..... somehow I need to set my variable to the data value in the table row...for example: $variable = mysql_query($query)... Any advice??? Link to comment Share on other sites More sharing options...
Jonathon Posted March 30, 2011 Share Posted March 30, 2011 hello wframe, $q = 'SELECT column_a, column_b FROM table'; $r = mysqli_query($dbc, $q); while (list($column_a, $column_ = mysqli_fetch_array($r, MYSQLI_NUM)) { // Do something with the listed variables } // End of while loop Is a way to assign mysql results and put them straight into a variable to use later on Hope that helps? Jonathon 1 Link to comment Share on other sites More sharing options...
wframe Posted March 30, 2011 Author Share Posted March 30, 2011 Hello, I tried the script and got the following errors: Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /home/content/01/7477001/html/join/rowtest2.php on line 6 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/content/01/7477001/html/join/rowtest2.php on line 7 below is what I typed: --------- <?php $con = mysql_connect('stuff', 'stuff','stuff'); // connect to database $query="SELECT something FROM table"; $result=mysqli_query($con, $query); while (list($url1_id) = mysqli_fetch_array($result, MYSQLI_NUM)); ?> Link to comment Share on other sites More sharing options...
Jonathon Posted March 30, 2011 Share Posted March 30, 2011 $con = mysql_connect('stuff', 'stuff','stuff'); // connect to database This line should be $con = mysqli_connect('stuff', 'stuff','stuff'); // connect to database 1 Link to comment Share on other sites More sharing options...
Paul Swanson Posted March 31, 2011 Share Posted March 31, 2011 You still need to select the database name. mysqli_select_db ($con, 'dbname'); And you will need to reference the column when updating. It's easiest if you know the name of the column: $query = "UPDATE tableName SET columnName='$newValue'"; 2 Link to comment Share on other sites More sharing options...
Recommended Posts