Jump to content
Larry Ullman's Book Forums

snickers123

Members
  • Posts

    3
  • Joined

  • Last visited

snickers123's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I have two arrays one with values set by the user to filter out certen foods, and saved to the db the other is a second set of values created when someone enters a recipe. These 9 vars can be set to either "yes" or "no". In this code the users filters are $Eggs22 and the recipe var are $Eggs without the 22. I have put together a small pice of code to do this but when I use the word "continue" to stop the filter and go back to the top of the while loop to get the next set of records to filter. If the $Eggs22 and $Eggs do not match I need to drop that record and get the new one and if they do match then it needs to just move to the next case: Can anyone see what I have done wrong I get the records weather the vars match or not. or is there an easier way. Still new to this . $n="no"; $k="yes"; switch ($n) { case $Eggs22: if($Eggs22!==$Eggs){continue;} case $Fruitose22: if($Fruitose22!==$Fruitose){continue;} case $Gluten22: if($Gluten22!==$Gluten){continue;} case $Lactose22: if($Lactose22!==$Lactose){continue;} case $Nuts22: if($Nuts22!==$Nuts){continue;} case $Soy22: if($Soy22!==$Soy){continue;} } switch ($k) { case $LowFat22: if($LowFat22!==$LowFat){continue;} case $Diabetice22: if($Diabetice22!==$Diabetice){continue;} case $Vegan22: if($Vegan22!==$Vegan){continue;} }
  2. I decided to go with the SELECT with a UNION ALL. I have used the first statements many time and it works when, but when I ad the "UNION ALL" or just the "UNION" statement it stops working. There is no error messages the script runs to the last else "No Records" All the variables are preset and working. I have tested everything up to the SELECT statements. $result=mysql_query($sql); print_r($result); prints out "Rescorce#3" The script runs all the way through to the ending else "No Records". The problem is when it gets to the SELECT its like the SELECT statements never ran? $sql="SELECT * FROM recipes WHERE Cat='$cat'and Eggs='$Eggs' and Fruitose='$Fruitose' and Gluten='$Gluten' and Lactose='$Lactose' and Nuts='$Nuts' and Soy='$Soy' and LowFat='$LowFat' and Diabetice='$Diabetice' and Vegan='$Vegan' UNION ALL SELECT * FROM recipes WHERE Cat='$cat'and Eggs='$Eggs2' and Fruitose='$Fruitose2' and Gluten='$Gluten2' and Lactose='$Lactose2' and Nuts='$Nuts2' and Soy='$Soy2' and LowFat='$LowFat2' and Diabetice='$Diabetice2' and Vegan='$Vegan2'";
  3. I run a SELECT query on my mysql database. The results are to be stored in an array $ar. I then change the SELECT statement and run it again. This time the results need to be stored in an array $ar2. These two arrays then need to be mearged into 1 for further processing. Not new to programing but new to this. Any help you can give would be greatly appreciated. <?PHP // First query run here. $result=mysql_query($sql); $num=mysql_num_rows($result); $ar=array(); $i=0; while($i < $num) { $ar[]=mysql_result($result,$i,"pic"); $ar[]=mysql_result($result,$i,"Title"); $ar[]=mysql_result($result,$i,"Directions"); $ar[]=mysql_result($result,$i,"Notes"); } // Second query run here $result=mysql_query($sql); $num=mysql_num_rows($result); $ar2=array(); $i=0; while($i < $num) { $ar2[]=mysql_result($result,$i,"pic"); $ar2[]=mysql_result($result,$i,"Title"); $ar2[]=mysql_result($result,$i,"Directions"); $ar2[]=mysql_result($result,$i,"Notes"); } //merge arrays into 1 $ar3=array(); $ar3=array_merge($ar,$ar2); //array_merge($array1, $array2); ?>
×
×
  • Create New...