Page 1 of 1

want to use distinct but getting problem.

Posted: Thu May 12, 2005 7:12 am
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.

Posted: Thu May 12, 2005 7:15 am
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?

Posted: Thu May 12, 2005 7:18 am
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;

Posted: Thu May 12, 2005 7:23 am
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:

Posted: Thu May 12, 2005 7:37 am
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....