Page 1 of 1

Hi, i need help in some check

Posted: Sat Mar 31, 2012 6:55 am
by mekha
i have created a cms at php
articles
categories
-------
now i need to make a check that if there are articles in categories to show them...if not to echo'there is no articles in these category'..
i have this code that shows the articles:

Code: Select all

 <?php
$art_data = get_all_mekhas($arts_id);

 foreach($art_data as $lkey=>$lval)



{
	

	


echo '<li><a href="article.php?art='.$lval['pages_id'].'">'.$lval['pages_header'].'</a></li>';





}
 

 ?>
----
this is the function:

Code: Select all

function get_all_mekhas($arts_id)
{
	$query = "SELECT pages_id, pages_link, pages_header, thecategory FROM pages WHERE pages_appearance='yes' AND thecategory=".$arts_id." ORDER BY pages_id";
	mysql_query("SET NAMES 'utf8'");
	$result = mysql_query($query);
	if(!$result)
	return false;
	if(mysql_num_rows($result)==0)
	return false;
	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		 $returned_array[] = $row;
	}

	return $returned_array;
}
pages=articles
for ex:
pages_id = the id of the article

Re: Hi, i need help in some check

Posted: Sat Mar 31, 2012 7:02 am
by Celauran
$art_data will be false if there are no articles.

Code: Select all

if ($art_data)
{
    foreach ($art_data as $article)
    {
    // whatever
    }
}
else
{
    echo 'No articles to display.';
}
You should probably also add some validation and escaping to that function. Right now you can pass any argument right into that query and it will run.

Re: Hi, i need help in some check

Posted: Sat Mar 31, 2012 7:09 am
by mekha
ohhh man...thank u really....its great :) and worked :)