Jump to content
Larry Ullman's Book Forums

Assigning Mysql Row Value To Php Variable


Recommended Posts

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

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

  • Upvote 1
Link to comment
Share on other sites

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...