[SOLVED] Limiting mulitple database entries to one

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
thedro
Forum Newbie
Posts: 7
Joined: Thu Jan 13, 2005 12:38 pm

[SOLVED] Limiting mulitple database entries to one

Post by thedro »

This is my question,
I'm designing a database system that enables you to select your specific car. First you pick the model, then the year, then the engine type. What I want the user to be able to do is select the model and then it comes up with a list of years available. The way the database is set up is that there is the model and year are used multiple times in different rows. When the mysql is called for a specific year, I want it to be able to put that year once even though it is in the database multiple times. For example, if the user selects the model "A4" and there is 4 entries in the database for a 1999 A4. The next page will show all the years that the A4 is avaliable. I want it to just echo one year that the car is avaliable even if there is multiple entries of that year. Is this possible? If you need more explination please reply and I'll explain in more detail. Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

SELECT * FROM `cars` WHERE `model` = 'Celica' GROUP BY `year` ORDER BY `year`
thedro
Forum Newbie
Posts: 7
Joined: Thu Jan 13, 2005 12:38 pm

Post by thedro »

what delimiter do you recommended for this query. Ex. mysql_fetch_array, mysql_fetch_row. Both of the following cause errors, what would you recommend?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post the code you tried, please. Please post the error you received as well.
thedro
Forum Newbie
Posts: 7
Joined: Thu Jan 13, 2005 12:38 pm

Post by thedro »

Thanks feyd for your quick responses and helpfullness. The code is the following

Code: Select all

<?
// Connecting, selecting database
$link = mysql_connect('mysql.addr.com', 'autox', 'Audi4321')
   or die('Could not connect: ' . mysql_error());
mysql_select_db('autox') or die('Could not select database');
$query = "SELECT * FROM `cars` WHERE `model` = 'A4' GROUP BY `year` ORDER BY `year`";
$result = mysql_query($query);
while ($values = mysql_fetch_row($result))
&#123;
	echo "$values&#1111;year]<br>";
	&#125;
?>
For right now I am just having it echo the values given from the mysql.

This is the error I recieve:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /usr211/home/a/u/autox/public_html/content/includes/carselect.php on line 8
Please let me know what you think.

Thanks.

thedro
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd guess you have an error in the query syntax.. change the query line to:

Code: Select all

$result = mysql_query($query) or die(mysql_error());
thedro
Forum Newbie
Posts: 7
Joined: Thu Jan 13, 2005 12:38 pm

Post by thedro »

It worked perfectly. THe problem I had is I didn't notice I had the wrong table name. I fixed that and it works perfectly. Thanks so much for your help. :D
Post Reply