SQL select problem in PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

SQL select problem in PHP

Post by Charles256 »

Code: Select all

$query2="SELECT DISTINCT `kart_no`,`kart_name` FROM kart ORDER BY `kart_no` ASC ";
				$sql2=mysql_query($query2);
				while ($test=mysql_fetch_object($sql2))
				{
					echo ("<option value='$test->kart_no'");
					if (isset($model))
					{
						if ($model==$test->kart_no)
						{
							echo " selected";
						}
					}
					echo (">$test->item_no $test->kart_name</option>");
				}
the problem is i need another colum `item_no` to be grabbed also, however, if i add item_no in the select it effectivelly ignores the distinct kart_no command because that's what I really really need to be distinct...is it possible to do all this with SQL? or am I going to have to do some kind of weird processing afterwards? the manual on DISTINCT doesn't discuss the possibility of something being distinct and something else not being distinct..unless I just read over it...my friend google isn't being very open about the subject either.... any suggestions?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

GROUP BY `kart_no` ?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

yes yes yes yes yes! THANK YOU!!! :-D :: slips jenk a five, in monopoly money.:: guess it helps to know what command your looking for:-D
Post Reply