1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can someone please help me figure out how to sort sql properly?

Discussion in 'Databases' started by Kaediem, Apr 5, 2007.

  1. #1
    Hi, I bought a script and although it seems to be working properly for the most part, it does have it's glitches.

    It's a "linkexperiment" script and it's supposed to display the links in the database by Amount (highest to lowest) and then by the order in which it was entered (first to last)

    I've looked at the database and the information stored is

    link_id
    description
    website
    amount

    in a table called link_data_tb

    It is sorting by amount but other than that I can't figure out what it's sorting by.... but it's not link_id

    The code is
    <?php
    			$rs = @mysql_query("select * from link_data_tb order by amount desc");
    			$cnt = 0;
    			while($row = @mysql_fetch_array($rs))
    			{
    			?>						
    			  <tr>								
    				<td valign="top" align="right"><?php print $cnt+1; ?></td>
    				<td valign="top" nowrap><a href="<?php print $row['website']; ?>" target="_blank"><?php print stripslashes($row['description']); ?></a></td>				
    				<td valign="top" align="right"><?php print "$".$row['amount']; ?></td>
    			  </tr>	 	 				
          		<?php
    				$cnt++;
    			}
    			if($cnt==0)			
    				print "<tr><td align='center' style='color: #cc0000' colspan='5'>No data found....</td></tr>"			
    			?>		
    
    
    Code (markup):
    I tried changing the first line of that to be ...

    $rs = @mysql_query("select * from link_data_tb order by amount link_id");
    Code (markup):
    but then I get "no data found"

    I would greatly appreciate any suggestions or assistance anyone could offer - it seems "logical" to me but it's not working the way "I" think it should work.

    Thanks in advance

    Lisa
     
    Kaediem, Apr 5, 2007 IP
  2. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #2
    $rs = @mysql_query("select * from link_data_tb order by link_id ASC");

    sorts by link id (first to last)

    I think the following will also do the same:
    $rs = @mysql_query("select * from link_data_tb");

    Bye :)
     
    JEET, Apr 5, 2007 IP
  3. Kaediem

    Kaediem Well-Known Member

    Messages:
    1,128
    Likes Received:
    118
    Best Answers:
    0
    Trophy Points:
    150
    #3
    Thanks Jeet - I actually figured it out and what I needed was to do this...

    $rs = @mysql_query("select * from link_data_tb order by amount desc, link_id asc")

    So it sorts the links by amount payed (highest first) and then by the order recieved (link_id) oldest first

    I was missing (apparently) the asc desc syntax and a comma between (at least it works with the comma so I assume that was required as well).

    Thanks

    Lisa
     
    Kaediem, Apr 5, 2007 IP
  4. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #4
    Oh, I thought you wanted 2 "different tables"...
     
    JEET, Apr 5, 2007 IP
    Kaediem likes this.
  5. Kaediem

    Kaediem Well-Known Member

    Messages:
    1,128
    Likes Received:
    118
    Best Answers:
    0
    Trophy Points:
    150
    #5
    I see, well thanks for at least trying ;)

    Lisa
     
    Kaediem, Apr 5, 2007 IP