RE: [PHP-WIN] SELECT & FETCH ARRAY
| From: | Matt Williams | Date: | Thu, 14 Sep 2000 14:38:54 +0000 |
| Subject: | RE: [PHP-WIN] SELECT & FETCH ARRAY | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-2650@lists.php.net to get a copy of this message | ||
Hi Karl
What you could do is build your query around which options are selected
Create an option in your list called all or something like that then do
something like
$query = "SELECT * FROM Accomodation WHERE ";
if($Town != "Any") {
$query .= "town LIKE '$Town' and ";
}
if($Grade != "Any") {
$query .= "grade LIKE '$Grade' and ";
}
$search= substr($query, 0, strlen($query)-4);
$results =mysql_query($search) etc...
you will have to do some checking to make sure that they choose at least one
option for the above to work
m@
-----Original Message-----
q> From: Karl Phillipson [mailto:karl@zenton.co.uk]
q> Sent: Thursday, September 14, 2000 03:00
q> To: PHP
q> Subject: [PHP-WIN] SELECT & FETCH ARRAY
q>
q>
q> Okay PHP gurus I have a problem and I am hoping someone can help me
q> with it.
q>
q> I have the script below connecting to a db to extract info based on a
q> particular town($Town) and then on the type ($Grade) of accommodation
q> available in that town.
q> What happens is that if I select from my drop down menus the Town and
q> the Grade of accommodation I get what I want. However, if I neglect to
q> specify either of the two, that being Town or Grade I get nothing, what
q> I would like is all in either category to be displayed if one of the
q> select options is NULL.
q>
q> On a final note, this is probably a really crap question - ( I ask them
q> on occasion) - but I seem to have trouble containing a returned table
q> within say a defined area of 600 px width. Even whn I specify a table
q> width it always overides it. The table always stretches to 100% of a
q> given area. It works within frames where I can specify the master frame
q> width but I am trying to avoid the use of frames.
q>
q> I thank you in advance for what is more than likely easy answers to some
q> of you out there.
q>
q> Regards,
q>
q> Karl
q>
q>
q> <?
q>
q> $cursor = mysql_query("SELECT * FROM Accommodation WHERE Town = '$Town'
q> AND Grade = '$Grade'");
q> if (!$cursor)
q> {
q> echo("<H3>MySQL error: " . mysql_error() . "</H3>");
q> exit();
q> }
q>
q> while ( $row = mysql_fetch_array($cursor) )
q>
q> {
q>
q> print("<TR><TD><b>" . $row["Grade"] .
q> "</b><BR><BR></TD></TR>");
q> print("<TR><TD><b>" . $row["Establishment"] .
q> "</b><BR></TD></TR>");
q> print("<TR><TD>" . $row["Town"] .
q> "<BR></TD></TR>");
q> print ("<HR>");
q> }
q>
q> ?>
q>
q>
q>
q> --
q> PHP Windows Mailing List (http://www.php.net/)
q> To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net
q> For additional commands, e-mail: php-windows-help@lists.php.net
q> To contact the list administrators, e-mail: php-list-admin@lists.php.net
q>