Hi all
if i have in catagory table,and there 20 catagory and in each catgory 10 campany, and for each company there are 20 artical , how can i view for each company 1 artical in page ?
| SitePoint Sponsor |
Hi all
if i have in catagory table,and there 20 catagory and in each catgory 10 campany, and for each company there are 20 artical , how can i view for each company 1 artical in page ?
here is the structure of the database and the action :
and here is the action :Code:Field Type Attributes Null Default Extra ID int(7) UNSIGNED No auto_increment title varchar(20) Yes date date Yes company_id int(7) No 0 catagory varchar(30) Yes news blob Yes readmore blob Yes link blob Yes act varchar(30) No filename varchar(30) No counter mediumint(8) UNSIGNED No 1
PHP Code:<?
if($action == "showcat"){
if(!$catagory){
error();
}
$query = mysql_query("Select * from $table where catagory='$catagory' ");
$count = mysql_num_rows($query);
for($i =0; $i < $count; $i++){
$h = mysql_fetch_array($query);
arttable("$h[title]","$h[news]","$h[readmore]");
echo "<br> $h[company_id] ";
echo "<a href=\"?action=showmore&company_id=$h[company_id]\">cccccc</a>";
}
}
?>


In your query...(the mysql query) use LIMIT 1 at the end of it...plus I have a small change in your for loop, so it looks better than a for() loop.
PHP Code:<?
if($action == "showcat"){
if(!$catagory){
error();
}
$query = mysql_query("Select * from $table where catagory='$catagory' ");
while ($h = mysql_fetch_array($query)) {
arttable("$h[title]","$h[news]","$h[readmore]");
echo "<br> $h[company_id] ";
echo "<a href=\"?action=showmore&company_id=$h[company_id]\">cccccc</a>";
}
}
?>
Bookmarks