Jump to content

Mysql Query Help!


alexville

Recommended Posts

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
Share on other sites

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
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
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
Share on other sites

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.