Current location: Hot Scripts Forums » Programming Languages » PHP » Sorting By Varaiable


Sorting By Varaiable

Reply
  #1 (permalink)  
Old 10-25-09, 02:35 PM
smithygotlost smithygotlost is offline
Aspiring Coder
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 413
Thanks: 12
Thanked 3 Times in 3 Posts
Sorting By Varaiable

heya guys

ok what im doing is a comp on offering, the more offers u out in the higher you get. i have 1 table with all ursers details called stats and one with all the offers in called offer_comp.

now i list it using this

PHP Code:

<table border="1" cellspacing="5" cellpadding="5">

<?php
$offer_result 
mysql_query("select * from `stats` where `admin` = '0' and `suspend` ='0' limit 0,500")or die(mysql_error());
$i 0;
while(
$row=mysql_fetch_array($offer_result)){
$i += 1;
$offer_id $row["id"];
$name $row["charname"];
$hash $row["attackhash"];
$offer_grab mysql_query("select * from `offer_comp` where `userid`='$offer_id'");
$ammount mysql_num_rows($offer_grab);

if(
$cheat !=0){
echo 
"<tr><td>$i.</td>    <td><a href=\"profile.php?id=$offer_id&hash=$hash\">$name</a></td><td> $cheat </td></tr>";
} else {
echo 
"";
}
}
?>
</table>
but what i need to do is sort it by the ammount of offers variable $ammount

how do i got about this ?

thanks in advanced
Mike
Reply With Quote
  #2 (permalink)  
Old 10-26-09, 08:25 AM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
If I understand correctly, you're wanting to sort by the number of records (rows) retrieved by the query? I'm not sure what organization this would provide you since this has no connection with the fields of the DB's table. Maybe try putting a field in your table labelled "amount" and sort ASC or DESC by that?
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Reply With Quote
  #3 (permalink)  
Old 10-30-09, 05:48 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
PHP Code:

<table border="1" cellspacing="5" cellpadding="5">

<?php
$offer_result 
mysql_query("select * from `stats` where `admin` = '0' and `suspend` ='0' limit 0,500")or die(mysql_error());
$i 0;
while(
$row=mysql_fetch_array($offer_result)){
$i += 1;
$offer_id $row["id"];
$name $row["charname"];
$hash $row["attackhash"];
$offer_grab mysql_query("select * from `offer_comp` where `userid`='$offer_id'");
$ammount mysql_num_rows($offer_grab);

if(
$cheat !=0){
$storage[$ammount] = "<tr><td>$i.</td>    <td><a href=\"profile.php?id=$offer_id&hash=$hash\">$name</a></td><td> $cheat </td></tr>";
} else {
echo 
"";
}
}
ksort($storage);
$storage array_reverse($storagetrue);
foreach(
$storage as $value) {
    echo 
$value;
}
?>
</table>

This may work, is untested so who knows.  The way things have been lately, I wonder about myself.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting in php sunanurag PHP 3 09-10-09 03:05 PM
sorting in a custom grid view painthu ASP.NET 1 05-17-08 02:51 PM
Default Sorting of Listings currently is definitely wrong! jeveux Hot Scripts Forum Questions, Suggestions and Feedback 5 07-29-07 07:37 PM
sorting table using asp with vbscript. wsy_bin ASP 4 05-05-05 02:54 AM
How to do sorting and paging for search function lostinsight ASP.NET 1 11-14-04 11:44 PM


All times are GMT -5. The time now is 08:03 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.