c_pattle Posted July 14, 2010 Share Posted July 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/207700-mysql_fetch_array-help/ Share on other sites More sharing options...
trq Posted July 14, 2010 Share Posted July 14, 2010 Because I have already used the result set called "product_details_rs" before does this mean I can't use it again? Not at all. If its still got data in it. How many records are you expecting your query to return? Quote Link to comment https://forums.phpfreaks.com/topic/207700-mysql_fetch_array-help/#findComment-1085757 Share on other sites More sharing options...
c_pattle Posted July 14, 2010 Author Share Posted July 14, 2010 Thanks. I'm expecting each query to just return one record as they are all just getting one product by an id number. Quote Link to comment https://forums.phpfreaks.com/topic/207700-mysql_fetch_array-help/#findComment-1085778 Share on other sites More sharing options...
trq Posted July 14, 2010 Share Posted July 14, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/207700-mysql_fetch_array-help/#findComment-1085780 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.