Solved

PHP MYSQL: Get Row Values from Recordset

Posted on 2007-12-03
4
6,168 Views
Last Modified: 2013-12-12
An example recordset comprises two columns ("id" from one to five and "value") and five rows.

The need is to extract each row value separately and assign that value to a variable which can then be used in further calculations within PHP.

Those calculations will work with similarly extracted row values form a second separate recordest.
mysql_select_db($database_conn_mysqlretailpoll, $conn_mysqlretailpoll);
$query_rst_example = "SELECT * FROM regweight";
$rst_example = mysql_query($query_rst_example, $conn_mysqlretailpoll) or die(mysql_error());
$row_rst_example = mysql_fetch_assoc($rst_example);
$totalRows_rst_example = mysql_num_rows($rst_example);

Open in new window

0
Comment
Question by:air4casts
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20395636
I added the required code, to fill in the array $values, so after the fetching of the result set, you have that array as needed.
mysql_select_db($database_conn_mysqlretailpoll, $conn_mysqlretailpoll);
$query_rst_example = "SELECT * FROM regweight";
$rst_example = mysql_query($query_rst_example, $conn_mysqlretailpoll) or die(mysql_error());
$totalRows_rst_example = mysql_num_rows($rst_example); 
$values = array();
while ($row_rst_example = mysql_fetch_assoc($rst_example))
{
  $values[$row_rst_example["id"]] = $row_rst_example["value"];
}

Open in new window

0
 

Author Comment

by:air4casts
ID: 20395858
Very fast thank you. Would you take a dumb question?

How to extract the value for id=3 for example as in "$fc3 = ...."?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 20395895
$values[3]  or $values["3"]  should do it...

$fc3 = $values[3];
0
 

Author Closing Comment

by:air4casts
ID: 31412326
very rapid response
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question