Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP MYSQL: Get Row Values from Recordset

Posted on 2007-12-03
4
Medium Priority
?
6,183 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
[X]
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
  • 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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.
Suggested Courses

597 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