FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Help SQL Sort





fizzo
Code:
<?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright 2002 - 2006 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------*/
require_once "maincore.php";
require_once "subheader.php";
require_once "side_left.php";
opentable("WBA l League Leaders - Points Per Game");
$con = mysql_connect("DATABASE CONNECTION");
mysql_select_db('DATABASE');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$team = mysql_query("SELECT * FROM Stats ORDER BY Ppg");

  echo"<table border='0'><b><font size=2>TEAM STATS</font>
<tr>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1 face=Verdana color=white></th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1 face=Verdana color=white>PLAYER</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1 face=Verdana color=white>GP</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1 face=Verdana  color=white >GS</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>PPG</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>RPG</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>APG</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>SPG</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>BPG</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>ORPG</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>DRPG</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>Pts</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>Reb</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>Ast</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>Blk</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>Stl</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>TO</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>PF</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>Min</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>FG/Att</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>FG%</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>3P/Att</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>3P%</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>FT/Att</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>FT%
</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>OR
</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>DR
</th>
<th style=border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium bgcolor=black><font size=1  color=white face=Verdana>Sea
</th>
</tr></font>";
 while($row = mysql_fetch_array($team))
{
  echo "<tr>";
  echo "<td bgcolor=#666666>"."</td>";
  echo "<td bgcolor=#666666>"."<b>". $row['Name']."</b>";
  echo "<td bgcolor=#666666>" . $row['Gp'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Gs'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Ppg'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Rpg'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Apg'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Spg'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Bpg'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Orpg'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Drpg'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Pts'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Rebs'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Ast'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Blk'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Stl'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['To'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Fouls'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Mins'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Fgatt'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Fg'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['3patt'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['3p'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Ftatt'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Ft'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['OReb'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['DReb'] . "</td>";
  echo "<td bgcolor=#666666>" . $row['Seasonid'] . "</td>";
  echo "</tr>";
}
echo "</table>";
mysql_close($con);

closetable();

require_once "side_right.php";
require_once "footer.php";
?>


Code:
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$team = mysql_query("SELECT * FROM Stats ORDER BY Ppg");


Ill just ask about my Query code when I have this script on my site that will sort out the Stats Table on my database by Ppg (Points Per Game) It seems that it doesnt sort it out ascending order.. even If I use the DESC after the Ppg It still shows the same? Anyone can help me with this? I just need to sort this one using the Ppg (Points Per Game) to be the base.. Thanks!
mathiaus
Code:
$team = mysql_query("SELECT * FROM `Stats` ORDER BY `Ppg` ASC");

Maybe trying to tell it ascending (which is normally default)?
fizzo
I found out that when using the ORDER By DESC or ASC it just sorts out numbers from 1 to 9 if there are datas stored more than 9 it wont be sorted out..

Check this two pages...

The first link sorts out the PPG field.. that has greater than 9 data stored on the database. But it still not sorted from the highest to the lowest..

http://www.ayc.frih.net/UBA/leadpoints.php


The second link sorts out the BPG field.. that has records not greater than 9.. Thats why it sorts out easily and correct from the Highest to the lowest..

http://www.ayc.frih.net/UBA/leadblocks.php


What will i do if the field i will sort has data or records stored greater than 9? Thanks I hope you help me.
kv
Actually, it is not the problem of the value being greater or less than 9. I guess the Ppg field in the database is a string (text) instead of number. So it is sorting using text sort, not number sort.

For example, if you text sort numbers 1,2 and 10, you will get

Code:

1
10
2


and this is correct for text sort, not number sort.

You can try this

Code:

$team = mysql_query("SELECT * FROM Stats ORDER BY to_num(Ppg)");


But I am not sure if it works. converting ppg to a numeric field will solve the problem.
fizzo
What specific numeric field will i use in this kind of data? ex. 30.8?

Thanks!
kv
You can use FLOAT. If the number is too big (exceeding 9 digits), you can go for DOUBLE.
Related topics
Help: SQL error after uploading new files(thread updated)
Script to automatically restart Apache (for server 1)
Suicides, a way out or just stupid? What do you think?
CS Project
Brittneys Extream Makeover
Pagination
Which of these layouts is good?
help needed with css & javascript
Writing
Is philosophy a science?
The Medical web
help, SQL Stored procedure - ASTM rouding rule
Help me find scholarships.
Is China started occupaining India ????
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.