I'm working on a news system for a website. I used the news system from this tutorial: http://pixelcode.co.uk/tutorials/php/mysql-news-system/
So to display the news I use this line of code:
if(!$_GET['id'])
{
$query = mysql_query("SELECT * FROM news ORDER BY id DESC");
while($output = mysql_fetch_assoc($query))
{
echo '<div id="nieuws">';
echo '<a href="?id='.$output['id'].'" id="link">';
echo '<h1>'.$output['title'].'</h1>';
echo '<span id="date">'.date('d-m-y', $output['date']).'</span><br / >';
echo $output['shortnews'].'<br / >';
echo '</a>';
echo '</div>';
}
}
else
{
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM news WHERE id='$id'");
$output = mysql_fetch_assoc($query);
?>
<form method="post" action="?id=<? echo $output['id']; ?>">
<h1><? echo $output['title']; ?></h1>
<? echo '<span id="date">'.date('d-m-y', $output['date']).'</span><br / >' ?>
<? echo $output['news']; ?>
</form>
<?php } ?>
I can do: if(!$_GET['id'] = 6) but I can't do this: if(!$_GET['id'] > 6). What's the problem? Or is there another code for bigger then an id?
Thanks for replying, MARCH
Operator precedence: ! binds tighter than ==, so you're effectively doing
(not($_GET) == 6)
That's why there's != for inequality tests.
If you'd used proper bracketing, e.g
(!($_GET['id'] == 6))
then you'd be doing
not(id == 6)
and get your expected results, because that's logically/functionally equivalent to id != 6
And note that you're vulnerable to sql injection attacks and are using an obsolete/deprecated DB interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With