Kleidi
August 15, 2010, 11:30am
1
Hello there,
I’m playing around (again ) with my article script that i’m creating but i’m blocked somewhere. I have the display page that checks if and ID is queried, if yes, displays the article that correspond with that id, if not, displays all the article page with the last articles added. But, what’s happens if the ID queried does not exist? It mess up the page and does not display any error. What i need to do is an if statement to check first of all if the id exists and then display it, and if the id does not exist, to appear a “Article does not exist” message on the page.
Also, in the article db i have a table that stores if the article should be active or not for the visitors. In the mysql statement i have “Where Active=Yes” and the visitors can see only the active articles, but, when a visitor changes the id on the URL manually and puts there an article id that is inactive, the article is shown . How to prevent this? I need to do something than, when a visitor tried to access an article that is inactive (Where Active=NO), to appear a message on the page that tells the user that the id is looking for is inactive, or has no access to show it.
Can you PLEASE help me on this complicated think for me? Please!
Thank you in advance
Kleidi
September 18, 2010, 10:19am
2
Any one can help me with a concrete example, PLEASE?
Kleidi
August 16, 2010, 7:51pm
4
The full code is this:
<?php
session_start();
include("functions/functions.php");
include('functions/dbconn.php');
include('koka.php');
if(isset ($_GET['lajmeid'])) {
$lajmeid = intval($_GET['lajmeid']); //make sure its an integer
// $sql="SELECT B.katemri, A.id AS prodid, A.prodimg AS prodimg, A.prodinfo AS prodinfo, A.prodemri AS prodemri FROM p_produkte A LEFT JOIN p_kategori B ON A.katid = B.id WHERE B.id = ".$catId;
$sql = "SELECT B.LKatEmri, A.LajmeID AS LajmeID, A.LajmeEmri AS LajmeEmri, A.LajmeLink AS LajmeLink, A.LajmeIntro AS LajmeIntro, A.LajmeTxt AS LajmeTxt, A.LajmeTag AS LajmeTag, A.LajmeImg AS LajmeImg, A.LajmeVideo AS LajmeVideo, A.LajmeAktiv AS LajmeAktiv, A.KatLajmeID AS KatLajmeID FROM lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE B.LKatID = KatLajmeID AND A.LajmeID='$lajmeid' AND A.LajmeAktiv='PO'";
$result=mysql_query($sql);
if(mysql_num_rows($result) > 0) //products found
{
while($row = mysql_fetch_assoc($result)) //Loop through the procusts and display them
{
?>
<body>
<div class="trupi">
<?php include('koka1.php'); ?>
<?php include('koka2.php'); ?>
<div class="indexqender">
<div class="trupimajtas">
<div class="lajmehot">Lajmi fundit - HOT</div>
<div class="lajmetqender">
<div id="kokakuqe"> <p>Informohu! Eshte e drejta jote...</p></div>
<div class="menupkokakuqe"><?php echo $row['LKatEmri']; ?></div>
<div class="artikullqender">
<div class="artikulllajmi">
<h1><?php echo $row['LajmeEmri']; ?></h1>
<h3> <?php echo $row['LajmeIntro']; ?></h3>
<div class="teksti"> <img src="imazhet/artikuj/<?php echo $row['LajmeImg']; ?>" width="250" height="200" border="0" vspace="3" hspace="5" align="right" alt="<?php echo $row['LajmeEmri']; ?>" title="<?php echo $row['LajmeEmri']; ?>" /> <?php echo $row['LajmeTxt']; ?> </div>
<div class="video"> <?php echo $row['LajmeVideo']; ?> </div>
<div class="tag">Fjalët Kyçe: <?php echo $row['LajmeTag']; ?></div>
<?php
}
}
}
else{ // Nese nuk eshte marre asnje id lajmi shfaqet si me poshte ?>
<body>
<div class="trupi">
<?php include('koka1.php'); ?>
<?php include('koka2.php'); ?>
<div class="indexqender">
<div class="trupimajtas">
<div class="lajmehot">Lajmi fundit - HOT</div>
<div class="lajmetqender">
<div id="kokakuqe"> <p>Informohu! Eshte e drejta jote...</p></div>
<div class="menupkokakuqe">Artikujt e fundit</div>
<div class="artikullqender">
<div class="artikulllajmi">
<?php
echo lajmetfundit ();
} //Mbyllet else
?>
</div>
<div class="artikulllajmidjathtas">
<div class="menu">
<ul>
<li><a href="#">List Item 1</a></li>
<li><a href="#">List Item 1</a></li>
<li><a href="#">List Item 1</a></li>
<li><a href="#">List Item 1</a></li>
<li><a href="#">List Item 1</a></li>
</ul>
</div>
</div>
</div>
<div class="pastro"></div>
<div class="bllokposhtelajme"> Bllok poshte lajmeve</div>
</div>
</div>
<div class="trupidjathtas">
<div class="bllokd">
<div class="bllokdtitulli">Parashikimi Motit </div>
<div class="bllokdcontent">
<div class="bllokdcontenttxt">
<img src="http://l.yimg.com/a/i/us/we/52/<?=$currentImage;?>.gif" align="right" />
Temperatura: <?=$currentTemperature;?>°C <br />
Me e larta: <?=$currentHigh;?>°C<br />
Me e ulta: <?=$currentLow;?>°C<br />
Lindja Djellit: <?=$currentSunrise;?><br />
Perendimi Djellit: <?=$currentSunset;?><br />
</div><div class="pastro"></div>
</div>
</div>
<div class="bllokd" style="margin-top:5px">
<div class="bllokdtitulli">Kembimi Valutor </div>
<div class="bllokdcontent">
<div class="bllokdcontenttxt"><center><p>
<img src="imazhet/ikona/ikona_europe.jpg" width="30" align="left" hspace="3" /><b>Euro - </b> <?php echo kv_euro (); ?> Lek</p>
<p><img src="imazhet/ikona/ikona_usa.gif" width="30" align="left" hspace="3" /><b>USD - </b> <?php echo kv_dollare (); ?> Lek</p>
<p><img src="imazhet/ikona/ikona_angli.gif" width="30" align="left" hspace="3" /><b>GBP - </b> <?php echo kv_gbp (); ?> Lek </p>
</center>
</div><div class="pastro"></div>
</div>
</div>
<?php
echo reklama_2 (); // Shfaq reklama te rastesishm ne te djathte.
include('includet/rss.php');
?>
</div>
</div>
</div>
<?php
include('fundi.php');
?>
Can you please help me on do it like i need it, and comment the new code, PLEASE?
Thank you very very much!
[fphp]empty/fphp would perform both those checks for you.
write your code …
you can also try this
if(isset($id) && $id!=''){
// display articles
}else{
// message
}
I use empty() all the time
Without any code it’s impossible to help you.