Re: Selecting a special row from the database

From: Date: Fri, 04 May 2007 14:07:09 +0000
Subject: Re: Selecting a special row from the database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-254408@lists.php.net to get a copy of this message
On 04/05/07, Marcelo Wolfgang <marcelo@w3ol.com.br> wrote:
I'm building a news display page for a website, and since the user has 2 ways to arrive there, I want to know if this is possible: 1) the user arrive at news.php I will run a query at the db, and get the latest news to be the main one (full display) and display the others news in a list 2) the user arrived from a link to a specific news to news.php?id=10 It should display the news with id = 10 as the main news and get the latest ones to display in a list of other news
Here is the code I have so far, I hope it serve as a better explanation than mine!
<? $newsId = $_GET['id']; if (isset($newsID)){
        $whereClause = 'WHERE auto_id ='.$newsId;
} else {
        $whereClause = '';
} mysql_connect("localhost",$user,$pass) or die (mysql_error()); mysql_select_db ($db_table); $SQL = "SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC";
Yep, thats pretty classic. One thing I would do - assuming $newsId should always be an integer $whereClause = ''; if (isset($_GET['id']) { $newsId = intval($_GET['id']); if ($newsId) // if not 0 $whereClause = 'WHERE auto_id ='.$newsId; } ..... Alister

« previous php.general (#254408) next »