Solved

PHP MYSQL: Get Row Values from Recordset

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

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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to count occurrences of each item in an array.

861 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

Need Help in Real-Time?

Connect with top rated Experts

30 Experts available now in Live!

Get 1:1 Help Now