want to use distinct but getting problem.

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

want to use distinct but getting problem.

Post by itsmani1 »

Code: Select all

$OrdQry = "select * from product order by Pname";
		$ResOrd = mysql_db_query($db,$OrdQry,$cid);
		$OrdNum = mysql_num_rows($ResOrd);
see the above coad :) it gives me each and evey thing present in table.

Code: Select all

$OrdQry = "select distinct * from product order by Pname";
		$ResOrd = mysql_db_query($db,$OrdQry,$cid);
		$OrdNum = mysql_num_rows($ResOrd);
in the 2nd bunch of coad i get distinct result not repeation based on all field present in db.
but i want some thing else i want select *(each and evey thing) but i want to apply distinct on only
one field something like this.

Code: Select all

$OrdQry = "select * distinct isbn from product order by Pname";
		$ResOrd = mysql_db_query($db,$OrdQry,$cid);
		$OrdNum = mysql_num_rows($ResOrd);
in last case i want to get eacha and every thing but with distinct isbn. but i am get it corrent :(
help please.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$OrdQry = "SELECT distinct(`isbn`) FROM `product` ORDER BY `Pname`";
		$ResOrd = mysql_db_query($db,$OrdQry,$cid);
		$OrdNum = mysql_num_rows($ResOrd);
Try this?
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

Jcart wrote:

Code: Select all

$OrdQry = "SELECT distinct(`isbn`) FROM `product` ORDER BY `Pname`";
		$ResOrd = mysql_db_query($db,$OrdQry,$cid);
		$OrdNum = mysql_num_rows($ResOrd);
Try this?
if i try this then tell me one thing will I be able to select other values from other fields like pname etc . i don't think so...
i want $product,$name also to be selected what i do in this case.??

Code: Select all

$OrdQry = "select * from product order by Pname";
		$ResOrd = mysql_db_query($db,$OrdQry,$cid);
		$OrdNum = mysql_num_rows($ResOrd);
		if($OrdNum > 0)
		{
			while($OrdRow = mysql_fetch_object($ResOrd))
			{
				$product = $OrdRow -> Pname;
				$isbn = $OrdRow -> isbn;
				$name = "text".$countr;
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$OrdQry = "SELECT distinct(`isbn`),`othercolumn`,`othercolumn` FROM `product` ORDER BY `Pname`";
		$ResOrd = mysql_db_query($db,$OrdQry,$cid);
		$OrdNum = mysql_num_rows($ResOrd);
I'm not the best at mysql :wink:
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

Jcart wrote:

Code: Select all

$OrdQry = "SELECT distinct(`isbn`),`othercolumn`,`othercolumn` FROM `product` ORDER BY `Pname`";
		$ResOrd = mysql_db_query($db,$OrdQry,$cid);
		$OrdNum = mysql_num_rows($ResOrd);
I'm not the best at mysql :wink:
Sorry Please its does not work....
Post Reply