Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP MYSQL: Get Row Values from Recordset

Posted on 2007-12-03
4
6,167 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 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