Hi, i need help in some check

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Hi, i need help in some check

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Hi, i need help in some check

Post 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.
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Re: Hi, i need help in some check

Post by mekha »

ohhh man...thank u really....its great :) and worked :)
Post Reply