View Single Post
Old 03-22-2008, 04:41 PM   #7 (permalink)
maZtah
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

Quote:
Originally Posted by freenity View Post
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!

:)
maZtah is offline  
Reply With Quote