Jump to content

Mysql Query Help!


alexville

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.