piotr Posted June 27, 2009 Share Posted June 27, 2009 Hi, I have a simple loop which displays records from my database: <? $i=1; while($cdata=mysql_fetch_array($cres)){ echo "<a href='cat,$cdata[id].html'>".output_fields($cdata['title'])."</a>"; if($i!=$cnum) echo ", "; $i++; } ?> The loop works fine but it displays all records so there are some repeated things. How can I get only records which diffrent names? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/163867-solved-while-loop/ Share on other sites More sharing options...
trq Posted June 27, 2009 Share Posted June 27, 2009 You need to format your query to only retrieve unique results. Can we see your query? Link to comment https://forums.phpfreaks.com/topic/163867-solved-while-loop/#findComment-864586 Share on other sites More sharing options...
piotr Posted June 27, 2009 Author Share Posted June 27, 2009 So first I take categories: $csql ="SELECT categories .* FROM `categories` , category WHERE categories.id = category.category_id AND category.item_id ='$item_id'"; $cres = mysql_query($csql); $cnum = mysql_num_rows($cres); $cdatares = mysql_query($cdatasql); $catdata = @mysql_result($cdatares,0,'title'); $catdataid = @mysql_result($cdatares,0,'id'); Next I put while loop from first post. Then I put that loop for subcategories. Some items has the same category but diffrent subcategory so it displays category twice Link to comment https://forums.phpfreaks.com/topic/163867-solved-while-loop/#findComment-864594 Share on other sites More sharing options...
SetToLoki Posted June 27, 2009 Share Posted June 27, 2009 So first I take categories: $csql ="SELECT categories .* FROM `categories` , category WHERE categories.id = category.category_id AND category.item_id ='$item_id'"; $cres = mysql_query($csql); $cnum = mysql_num_rows($cres); $cdatares = mysql_query($cdatasql); $catdata = @mysql_result($cdatares,0,'title'); $catdataid = @mysql_result($cdatares,0,'id'); Next I put while loop from first post. Then I put that loop for subcategories. Some items has the same category but diffrent subcategory so it displays category twice $csql = select distinct category from categories; Link to comment https://forums.phpfreaks.com/topic/163867-solved-while-loop/#findComment-864613 Share on other sites More sharing options...
piotr Posted June 27, 2009 Author Share Posted June 27, 2009 Yes, it works. Thanks guys Link to comment https://forums.phpfreaks.com/topic/163867-solved-while-loop/#findComment-864785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.