using query_strings in sql
| From: | mayo | Date: | Wed, 21 Jan 2004 18:41:09 +0000 |
| Subject: | using query_strings in sql | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-32550@lists.php.net to get a copy of this message | ||
I'm a cold fusion refugee and am having incredible problems with something
that I think is relatively easy -- so I must be missing something basic.
I would like to pull info from a query string and use it inside a database
call.
I can pull the query string into a general variable:
<?php echo $section; ?>
now I would like to use it in a SQL statement, or in
if/else clauses to modifiy results from queries.
examples below:
USE query_string in SQL :
<?php
function whatever(){
$username = "";
...
// setting the default variables
if(!isset($category)){$category="Something";}
if(!isset($section)){$section="SomethingElse";}
$connection=@mysql_connect($hostname,$username,$password);
mysql_select_db($database);
$selection = mysql_query("
SELECT *
FROM classes
WHERE
classCategory = '$category'
ORDER BY $reorder $order
")
...
?>
The PHP SQL call below work nicely:
while ($row = mysql_fetch_array($selection)){
echo $row["sectionName"];
}
now I would like to do an if/else to modifiy it:
while ($row = mysql_fetch_array($selection)){
if (section == $sectionName){
echo "<b>" . $row["sectionName"] . "</b>";
}else{
echo $row["sectionName"];
}
Nothing is working. I must be missing something basic over here.
thx, Gil