Sead1 wrote:
> 1. line 5 "SELECT * FROM Listings ORDER BY date DESC,
does work
> 2. line 3 "SELECT * FROM Listings WHERE state = %s ORDER
BY date
> DESC" does NOT work
>
> In line 3 the %s is standing in for what the DW search
page sends to the
> database (that would be a state code, ie. CO, NM, PA).
That's what you want, but it's not how you've written the
code. For %s
to represent the value passed through the $_POST array, you
need to use
sprintf() in the same way as Dreamweaver does. What's more,
your code is
in the wrong order.
The main part of it should look like this:
$colname_rsState = "-1";
if (isset($_POST['searchfor'])) {
$colname_rsState = (get_magic_quotes_gpc()) ?
$_POST['searchfor'] :
addslashes($_POST['searchfor']);
}
if($_POST['searchfor'] != "All") {
$query_R1 = sprintf("SELECT * FROM Listings WHERE state = %s
ORDER BY
date DESC", GetSQLValueString($colname_rsState, "text"));
} else {
$query_R1 = "SELECT * FROM Listings ORDER BY date DESC";
}
mysql_select_db($database_connCareers, $connCareers);
$query_rsState = "$query_R1";
Note that by adding a conditional clause into the recordset
code like
this will prevent Dreamweaver from recognizing the recordset,
and the
Bindings panel will no longer show the column names. So you
should make
this change only after you have finished laying out your
page.
--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/