alexville Posted August 3, 2008 Share Posted August 3, 2008 Hey there, I can't find a way to grab the first 10 records of a mysql table and then put the 10 records into individual variables in php... example: variable1 = first row of mysql table varible2 = second row of mysql table variable3 = third row of mysql table Please Help! ??? Link to comment https://forums.phpfreaks.com/topic/117940-mysql-query-help/ Share on other sites More sharing options...
cooldude832 Posted August 3, 2008 Share Posted August 3, 2008 You want to add a LIMIT to your query and then use the php syntax of <?php $q = "Select Var1 from `table` Where 1 LIMIT 0,10"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); $rows = array(); $i = 0; while($row = mysql_fetch_assoc($r)){ foreach($row as $key=>$value){ $rows[$i][$key] = $value; } $i++; } print_r($rows); ?> Link to comment https://forums.phpfreaks.com/topic/117940-mysql-query-help/#findComment-606804 Share on other sites More sharing options...
alexville Posted August 3, 2008 Author Share Posted August 3, 2008 So what would that output? Link to comment https://forums.phpfreaks.com/topic/117940-mysql-query-help/#findComment-606850 Share on other sites More sharing options...
cooldude832 Posted August 3, 2008 Share Posted August 3, 2008 How would I know its your table? Link to comment https://forums.phpfreaks.com/topic/117940-mysql-query-help/#findComment-606853 Share on other sites More sharing options...
alexville Posted August 3, 2008 Author Share Posted August 3, 2008 What Im trying to do is show the first 10 lowest total_times in my flash program, but Im using php to passon the varibles. What I need to do is get the "user" and "total_time" data into individual variables starting from 1st (the lowest time) up to the 10th. My database structure: user | date | track | total_time | best_lap Variables I need: I was thinking the php variables should start like from names like "$lowest_time1" then "$lowest_time2" etc. The variables should hold the two columns of data: user and total_time, just separated by a "-" Thanks for your help Link to comment https://forums.phpfreaks.com/topic/117940-mysql-query-help/#findComment-606867 Share on other sites More sharing options...
cooldude832 Posted August 3, 2008 Share Posted August 3, 2008 its called an array and if u run that with a proper query you should have what you want Link to comment https://forums.phpfreaks.com/topic/117940-mysql-query-help/#findComment-606868 Share on other sites More sharing options...
alexville Posted August 3, 2008 Author Share Posted August 3, 2008 Okay, got the query: $q = "SELECT `user`,`total_time` FROM `racer` WHERE track = 'track1' ORDER BY `racer`.`total_time` ASC LIMIT 0 , 10"; But Im getting a really werid output that is hard to understand: Array ( [0] => Array ( [user] => alex [total_time] => 01.47.97 ) [1] => Array ( [user] => austin [total_time] => 01.49.26 ) [2] => Array ( [user] => austin [total_time] => 01.50.89 ) [3] => Array ( [user] => alex [total_time] => 02.02.82 ) ) Im trying to clean this up so I can make flash able to understand this, thanks Link to comment https://forums.phpfreaks.com/topic/117940-mysql-query-help/#findComment-606877 Share on other sites More sharing options...
cooldude832 Posted August 3, 2008 Share Posted August 3, 2008 The print_r($rows) was added so you can read the array to view its what you want If you don't know how to use an array in php you should go look on php.net to see hwo they are used. Link to comment https://forums.phpfreaks.com/topic/117940-mysql-query-help/#findComment-606879 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.