Jump to content

Recommended Posts

I have the following code at the top of my page before any html which selects some data from a table. 

 

$id = $_GET['key3'];
$product_detail_qry = "select * from product_list where id=" . $id . "";
$product_detail_rs = mysql_query ( $product_detail_qry, $conn ) or die ('error query1' . mysql_error());

$row = mysql_fetch_array ( $product_detail_rs );
	$_SESSION['sim_prod1'] = $row['sim_prod1'];
	$_SESSION['sim_prod2'] = $row['sim_prod2'];
	$_SESSION['sim_prod3'] = $row['sim_prod3'];

 

However then further down the page I have this line.  Because I have already used the result set called "product_details_rs" before does this mean I can't use it again?  It's just that when I try to get data from the table the second time it's not displaying. 

 

while ( $row = mysql_fetch_array ( $product_detail_rs ) ) {

 

Let me know if I haven't explained this very well.  Thanks

Link to comment
https://forums.phpfreaks.com/topic/207700-mysql_fetch_array-help/
Share on other sites

Thanks.  I'm expecting each query to just return one record as they are all just getting one product by an id number. 

 

Sounds very inefficient. Your much better off getting all the data you need in one query.

 

Anyway, if you have called mysq_fetch_assoc once and it only has one record then you will need to rewind its internal pointer if you expect to get the data out of it again. You'd be better off using the $row array again though instead (it already has the data you want).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.