Jump to content


Photo

Select records from 2 tables and order by...


  • Please log in to reply
1 reply to this topic

#1 Tjk

Tjk
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 01 July 2006 - 01:50 PM

$campaign= "test";

  $query= mysql_query("SELECT * from campaign INNER JOIN campaignd WHERE campaign.campaign='$campaign' campaignd.campaign='$campaign' ORDER BY minit LIMIT='1'")or die(mysql_error());
  while($row= mysql_fetch_array($query)){
    echo "<option value='".$row['commander']."'>". $row['commander']."</option>";
  }   

---------

Here I'm trying to select records from 2 tables- campaign and campaignd where the value of the row campaign is equal to the string stored in the variable of the name campaign, then ordering them by the row minit value (an integer) and setting the limit to 1 so it only selects the record with the highest value minit. It then echoes a select option with the value of the row commander.

I can't seem to get it to do what I want. When i try loading the page i don't get any errors but instead just get an empty select box. Could anyone show me where I'm going wrong?

regards
-Tjk


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 July 2006 - 06:35 PM

$query= mysql_query("SELECT * from campaign
INNER JOIN campaignd ON campaign.campaign = campaignd.campaign
WHERE campaign.campaign='$campaign'
ORDER BY minit DESC
LIMIT='1'")or die(mysql_error());
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users