Page 1 of 1

[SOLVED] Limiting mulitple database entries to one

Posted: Thu Jan 13, 2005 12:50 pm
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.

Posted: Thu Jan 13, 2005 1:03 pm
by feyd

Code: Select all

SELECT * FROM `cars` WHERE `model` = 'Celica' GROUP BY `year` ORDER BY `year`

Posted: Thu Jan 13, 2005 1:11 pm
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?

Posted: Thu Jan 13, 2005 1:22 pm
by feyd
post the code you tried, please. Please post the error you received as well.

Posted: Thu Jan 13, 2005 1:29 pm
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

Posted: Thu Jan 13, 2005 1:36 pm
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());

Posted: Thu Jan 13, 2005 1:45 pm
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