Jump to content

[SOLVED] while loop


piotr

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.