03-22-2008, 04:41 PM
|
#4 (permalink)
|
|
The Acquainted
Join Date: Oct 2007
Posts: 170
Thanks: 18
|
Quote:
Originally Posted by freenity
you have news.php?s=1 ; news.php?s=2, etc
so to select the section a possibility is using a switch, assign to a var say $query the query.
case1: $query = "select * from science";
case2: $query = "select * from sports"; ,etc
and then you just do:
mysql_query($query);
|
A better way would be:
PHP Code:
// It's not about the sprintf, just about $szSection
$szQuery = sprintf("SELECT * FROM %s", $szSection);
$pResult = mysql_query($szQuery);
This way you're not repeating peaces of code.
Anyways, ontopic:
I prefer the way I did the query above. This way, if a query is not working you can just do:
PHP Code:
$szQuery = sprintf("SELECT * FROM %s", $szSection);
echo $szQuery;
exit();
$pResult = mysql_query($szQuery);
And see what's wrong with the query!
:)
|
|
|
|