Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6190
  • Last Modified:

PHP MYSQL: Get Row Values from Recordset

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
air4casts
Asked:
air4casts
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
air4castsAuthor Commented:
Very fast thank you. Would you take a dumb question?

How to extract the value for id=3 for example as in "$fc3 = ...."?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
$values[3]  or $values["3"]  should do it...

$fc3 = $values[3];
0
 
air4castsAuthor Commented:
very rapid response
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now