Re: Selection problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since you didn't include the form, I'm going to have to make a couple of 
assumptions:

$nameb is the recipe field.
$pointsb is the points field. 

You want to use SQL statement 1 if they select points, 2 if they select 
recipies, but those aren't the only possibilities with the form. It sounds to 
me like you're running into an issue when they select BOTH points and 
recipies. So, you will need a 3 way if statement:

if ($nameb == "" && $pointsb != ""){ // if just points

 $query = "SELECT * FROM recipes WHERE points $pointsb";

} elseif ($pointsb == "" && $nameb != "") { // if just recipe

 $query = "SELECT * FROM recipes WHERE name = '$nameb'";

} else { // if both or neither, use the query you choose. 
	$query = ??

}

I may be wrong about what you intend here. You may want to add a if statement 
that corresponds to both fields being empty if you don't validate with 
Javascript or something. Sometimes I do it in the PHP anyways since there's 
no guaruntee that the user will have Javascript capabilities. 

-Micah

On Sun September 7 2003 3:43 pm, Chris Payne wrote:
> Hi there everyone,
>
> I'm having a strange problem, I have a form with 2 fields, 1 is for points
> (Weightwatcher points) and one is for recipe names.  If you select points
> (IE: 1-3, 3-6,6-9,9 and above) it works perfectly, displays the recipes and
> allows you to select a new points range from the dropdown.
>
> Next to it, on the same form, you can also select by recipe name and ignore
> the points instead selecting by the recipe name - this works fine, you can
> select 1, view it and then select another.
>
> The problem comes when you select a recipe from the dropdown and view it,
> then decide you want to select points instead - the points won't work once
> you have selected a recipe.  Can anyone see anything below that is wrong? 
> I am sure it's the if statement, i'm not sure how to handle it as you can
> select either option to get the result.
>
> Any help would really be appreciated, if I haven't confused you all to
> death
>
> :-)
>
> Regards
>
> Chris
>
> <?
>
> if ($nameb == ""){
>
>  $query = "SELECT * FROM recipes WHERE points $pointsb";
>
> } else {
>
>  $query = "SELECT * FROM recipes WHERE name = '$nameb'";
>
> };
>
>  $sql_result = mysql_query($query,$connection)
>  or die("Couldn't execute query.");
>
>  while ($row = mysql_fetch_array($sql_result)) {
>  $id = $row["id"];
>  $name = $row["name"];
>  $points = $row["points"];
>  $ingredients = $row["ingredients"];
>  $instructions = $row["instructions"];
>
> };
>
> ?>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux