[SOLVED] Limiting SQL results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

[SOLVED] Limiting SQL results

Post by tristanlee85 »

Code: Select all

// Get list of authors for the sort menu
$authors_qry = "SELECT author FROM megasquirt";
$result=mysql_query($authors_qry);
$num=mysql_numrows($result);

if ($num==0)
{
	$authors = "<option> --- </option>";
}
else
{
$count=0;
while ($count < $num)
	{
	$authors .= "<option name='sort' value='" . mysql_result($result,$count,"author") ."'>". mysql_result($result,$count,"author") . "</option>";
	$count++;
	}
}
In the table 'megasquirt', there are currently 3 rows. Row 1 has an author of 'tristanlee85' and rows 2 and 3 have an author of 'Natedogg'. This script creates a drop-down menu with the "author" as an option. The problem is, this returns both options to select Natedogg as the author in my drop-down menu. I tried using isset() with no luck. Any suggestions?
Last edited by tristanlee85 on Thu Sep 28, 2006 12:59 am, edited 1 time in total.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Code: Select all

$authors_qry = "SELECT DISTINCT(author) FROM megasquirt";
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

I new it was something simple like that. I tried using LIMIT 1, but obviously that only limited my result to 1. Thank you!
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

I take it you are into Car stuff?
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Most definately.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Right on. I have a Turbocharged '89 Volvo 244. A lot of the guys over at Turbobricks.com are running MS. I'm going to use it for my next project.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

This won't help you any since it's a Saturn forum, but I've been writing a downloads section for the MegaSquirt files.

http://forums.plastikracing.net/downloads.php?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Ahh..... So you've got different tunes that can be downloaded by others?
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Yeh. A lot of the Saturn guys are turning to the MegaSquirt because they are cheap. Most of the people on my site run with the MS and by sharing each other's configurations, it helps to give a nice starting point for others who are new to the system.
Post Reply