CodeMama Posted August 21, 2009 Share Posted August 21, 2009 I am trying to loop through results from my query and store 10 records to an array and then to session: $results = mysql_query($sql) or die(mysql_error()); // Grab results $top10 = $results; $rows = mysql_fetch_array($top10); while ($rows = mysql_fetch_array($top10)){ $rows < 10; $_SESSION['top10'] = $rows; } this is close but not quite right... Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted August 21, 2009 Share Posted August 21, 2009 ah... what you're doing here is re-defining the session called "top10" over and over... though I'm unsure why you're doing $rows<10; Take out the first $rows=mysql_fetch_array($top10); I'd just say: $results = mysql_query($sql) or die(mysql_error()); // Grab results $top10 = $results; $i=10; $counter=0; while ($r= mysql_fetch_array($top10)){ if($counter<=$i){ $_SESSION['top10'][$counter]=$r['name']; $counter++; } } I think that this will work. Quote Link to comment Share on other sites More sharing options...
play_ Posted August 21, 2009 Share Posted August 21, 2009 $query = "select rating, product_name from products order by rating desc limit 10"; $result = mysql_query($query); $top10 = array(); while( $rows = mysql_fetch_assoc($result) ) { $top10[] = $row['something']; } $_SESSION['top10'] = $top10; Quote Link to comment Share on other sites More sharing options...
CodeMama Posted August 21, 2009 Author Share Posted August 21, 2009 one more question about this ... what is the proper syntax to pull the 3 fields while ($r= mysql_fetch_array($bottom10)){ if($counter<=$i){ $_SESSION['bottom10'][$counter]=$r['name']['cviolations']['inDate']; $counter++; } } that causes a fatal error Quote Link to comment 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.