Jump to content

[SOLVED] arrange output by assending numbers


runnerjp

Recommended Posts

here is what my current form looks like

 

<?php
$result = mysql_query("SELECT * FROM pb where uid='".$getuser['ID']."' Order by pb") or die(mysql_error());
$num2 = mysql_num_rows($result);

echo "<table class=\"profilepbs\" width=195 align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
   <tr><td width=105 ><div align=\"center\">Distance</div></td><td width=125><div align=\"center\">Pb</div></td></tr>
   <tr>
     <td height=\"1\" colspan=\"2\" bgcolor=\"#000000\"></td>
     <td height=\"1\" colspan=\"2\" bgcolor=\"#000000\"></td>
   </tr>
   ";
while ( $row = mysql_fetch_array($result) ) {echo "<tr><td bgcolor=\"#FFFFFF\"><center>" . $row["distance"] . "</center></td><td bgcolor=\"#FFFFFF\"><center>" . $row["pb"] . "</center></td></tr>";
  }
  if($num2 < 1)
    {echo "<tr><td bgcolor=\"#FFFFFF\" ><center> N/A 
    </center></td><td bgcolor=\"#FFFFFF\"><center> N/A 
    </center></td></tr>";}
echo "</table>
<p>";
?> 

 

10k Road  32:10.1

100m  9.3

3000m  9:07.2

 

i would like it to go in time order so the  shorter the distances appear at the top like so

 

100m  9.3

3000m  9:07.2

10k Road  32:10.1

 

 

i just can figure out how to do this with the format thats used to enter the times


Link to comment
Share on other sites

If I understand the question correctly, you would need to change your order by to distance instead of pb. This is only going to work as you expect if all the distances are in the database in the same unit. eg 100 and 3000 mean 100 metres and 3000 metres. If you have entries like 100 metres and 3K, then its not going to work as expected.

Link to comment
Share on other sites

ok i came up with an idea... i have made it so the input into the db looks like this

 

<select name="distance" onchange="setDistance(this.value)">
				<option value="#|Distance">Select the distance</option>
				<option value='withoutMinutes|C:100m' >100m</option>
                    <option value='withoutMinutes|E:200m'>200m</option>
                    <option value='withoutMinutes|F:400m'>400m</option>
                    <option value='withoutHours|H:800m'>800m</option>
                    <option value='withoutHours|I:1500m'>1500m</option>
                    <option value='withoutHours|J:3000m'>3000m</option>
                    <option value='withoutHours|L:5000m'>5000m</option>
                    <option value='withoutHours|N:10,000m'>10,000m</option>
                    <option value='withoutHours|M:5k Road'>5k Road</option>
                    <option value='withoutHours|O:10k Road'>10k Road</option>
                    <option value='withHours|P:H Marathon'>H Marathon</option>
                     <option value='withHours|Q:Marathon'>Marathon</option>
                      <option value='withoutHours|K:3k S/Chase'>3k S/Chase</option>
                       <option value='withoutMinutes|D:110m Hurdles'>110m Hurdles</option>
                        <option value='withoutMinutes|G:400m Hurdles'>400m Hurdles</option>
                          <option value='withoutMinutes|A:60m (I)'>60m (I)</option>
                            <option value='withoutMinutes|2B:60m Hurdles'>60m Hurdles</option>
			</select>

 

so when i run an my script it should show reults in dec order..

 

a

b

c

d

e

ect

 

so i ran the script

 

<?php
$result = mysql_query("SELECT * FROM pb where uid='".$getuser['ID']."' Order by pb DESC") or die(mysql_error());
$num2 = mysql_num_rows($result);

echo "<table class=\"profilepbs\" width=195 align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
   <tr><td width=105 ><div align=\"center\">Distance</div></td><td width=125><div align=\"center\">Pb</div></td></tr>
   <tr>
     <td height=\"1\" colspan=\"2\" bgcolor=\"#000000\"></td>
     <td height=\"1\" colspan=\"2\" bgcolor=\"#000000\"></td>
   </tr>
   ";
while ( $row = mysql_fetch_array($result) ) {echo "<tr><td bgcolor=\"#FFFFFF\"><center>" . $row["distance"] . "</center></td><td bgcolor=\"#FFFFFF\"><center>" . $row["pb"] . "</center></td></tr>";
  }
  if($num2 < 1)
    {echo "<tr><td bgcolor=\"#FFFFFF\" ><center> N/A 
    </center></td><td bgcolor=\"#FFFFFF\"><center> N/A 
    </center></td></tr>";}
echo "</table>
<p>";
?>

 

the confusing thing is this is my output

123.jpg

 

why is J 1st :S

 

also i cant rember but whats the function so i can get rid of the 1st 2 thing so A:100m will become 100m

Link to comment
Share on other sites

  • 3 months later...
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.