Re: Genius help required with PHP MySQL problem
| From: | Miles Thompson | Date: | Fri, 22 Dec 2000 14:06:56 +0000 |
| Subject: | Re: Genius help required with PHP MySQL problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31564@lists.php.net to get a copy of this message | ||
I had a similar problem, and worked out the following. This is from "junk.php" so it's just enough to establish the principle. At the end the SQL reads as "select * from tablename $where" Pleases forgive any wrapping caused by Eudora.
<table>
<form method = "post" action = <? echo $PHP_SELF ?> >
<tr>
<td width=12% align="left">Display:</td>
<td width=12% align="left"><input type="radio" name="AuctionChoice" value = "open" <? is_checked( $AuctionChoice=='open') ?> > Open </td>
<td width=12% align="left"><input type="radio" name="AuctionChoice" value = "closed" <? is_checked( $AuctionChoice=='closed') ?> > Closed </td>
<td width=12% align="left"><input type="radio" name="AuctionChoice" value = "both" <? is_checked( $AuctionChoice=='both') ?> > Both </td>
<td>   </td>
<td width=15% align = "right">Class: </td>
<td width=20%><Select name="ClassChoice">
<? echo $option_class ?>
</select> </td>
<td width=15% align="center">
<input type = "submit" name = "refresh[]" value= "Refresh">
<input type = "submit" name = "refresh[]" value= "RefreshTwo"></td>
</tr>
</form>
</table>
<?
echo "<br>";
echo "AuctionChoice :", $AuctionChoice, "<br>" ;
echo "nClass : ", $nClass, "<br>";
echo "<br> and now the test of switch";
switch( $AuctionChoice )
{
case "open":
$auction_where = " lOnAuction = 1" ;
break;
case "closed":
$auction_where = " lOnAuction = 0 ";
break;
default:
unset( $auction_where);
}
// where clause fragment for the chosen class
if( $ClassChoice )
{
$class_where = " nClass = $ClassChoice ";} // assemble the _where clause fragments into a // coherent WHERE condition if( $auction_where && $class_where ) {
$sql_where = " WHERE $auction_where AND $class_where ";} elseif( $auction_where) {
$sql_where = " WHERE $auction_where ";} elseif( $class_where ) {
$sql_where = " WHERE $class_where ";} echo "Auction where is: $auction_where <br>"; echo "Class where is : $class_where <br>";
echo "SQL where is : $sql_where <br>";?> Hope this helps, and Merry Christmas - Miles Thompson At 04:22 PM 12/22/2000 +1300, Sefton wrote:
Hello Everybody, I am trying to return some results from MySql using PHP. What I have is this... SELECT * FROM cars WHERE make = It is after the equals that I want something that will select all of them. I know I could just have SELECT * FROM cars and leave it at that, but my problem occurs when I have another selection SELECT * FROM cars WHERE make = 'honda' AND trans = 'automatic' Becuase I am depending on what comes in from select boxes, if they don't select a make the code i have returns... SELECT * FROM car AND trans = 'automatic' This doesn't work for obvious reasons! So what I am after is something that will always if otherwise decided in the select box place WHERE make = Whatever command will list the lot. I have tried WHERE make = * WHERE make = '*' WHERE make = *.* etc Is it possible? Please Help Thanks Chris Alias Dr nick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net