a6april Posted May 16, 2012 Share Posted May 16, 2012 Hello all, I am new here so thank you in advance for all of your help. I am writing a pretty simple search script to display data from a table however have run into a snag. Things seem to get complicated all by themselves. I have a drop down to select the predetermined search criteria, because the data has either a 'Y'es or 'N'o. For example there are 50 or so products/brands with ingredients/categories in them. i.e. Brand X contains Sugar=Y, Salt=Y, Vinegar=N Brand Y contains Sugar=N, Salt=N, Vinegar=N Brand Z contains Sugar=Y, Salt=Y, Vinegar=Y Brand A contains Sugar=N, Salt=N, Vinegar=Y I want to display the brands that contain only the selected ingredients. I have added check boxes for the user to select. This runs ok however the return is more of a broader result and requires too much interpretation from the user. i.e. If I want to know which brands contain only salt and vinegar ??BRAND??= Sugar=N, Salt=Y, Vinegar=Y or ??BRAND??= Salt=Y, Vinegar=Y The return comes back: Brand X contains Sugar=Y, Salt=Y, Vinegar=N Brand Z contains Sugar=Y, Salt=Y, Vinegar=Y Brand A contains Sugar=N, Salt=N, Vinegar=Y Ideally the return Should only be: Brand Z contains Sugar=Y, Salt=Y, Vinegar=Y I believe the else if statement would work, I just have no knowledge of where to put it or how it would work. Any suggestions would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 16, 2012 Share Posted May 16, 2012 Post your code, including SQL. What you said doesn't make sense. "If I want to know which brands contain only salt and vinegar" "Ideally the return Should only be: Brand Z contains Sugar=Y, Salt=Y, Vinegar=Y" That is not true. If you want to know which brands only contain salt and vinegar, your result should not have sugar=Y. Quote Link to comment Share on other sites More sharing options...
a6april Posted May 16, 2012 Author Share Posted May 16, 2012 What you said doesn't make sense. "If I want to know which brands contain only salt and vinegar" "Ideally the return Should only be: Brand Z contains Sugar=Y, Salt=Y, Vinegar=Y" That is not true. If you want to know which brands only contain salt and vinegar, your result should not have sugar=Y. You are correct, thanks for pointing that out because that will cause me huge problems later, It is not that strict and it can't be, I would be better off not using the word 'Only'. If a user wants to look at all of the brands that contain both Salt and Vinegar than my statement is correct. The problem though is the same, The return is products that contain either salt or vinegar, the Sugar is a non issue because it wasn't checked as a parameter. But if it was checked, then the return is more of a combination of products that contain either Sugar, and / or Salt and /or Vinegar and any variation of that. I need to isolate the return to say....Ok The user is allergic to these 5 ingredients, I check those 5 ingredients and (check does or does not contain) and the results show the brands that are left. I really appreciate you taking a look at this for me...Thanks in advance The temp link is: http://foradomain.com/00000/search2.php This is the SQL: CREATE TABLE brands (brand VARCHAR(30), Dry VARCHAR(30), Canned VARCHAR(30), Raw VARCHAR(30), FreezeDried VARCHAR(30), Dehydrated VARCHAR(30), Puppy VARCHAR(30), Adult VARCHAR(30), Senior VARCHAR(30), AllLifeStages VARCHAR(30), GrainFree VARCHAR(30), LimitedIngredient VARCHAR(30), WeightManagement VARCHAR(30), SensitiveStomach VARCHAR(30), Organic VARCHAR(30), SmallBreed VARCHAR(30), LargeBreed VARCHAR(30), BreedSpecific VARCHAR(30), SingleProtein VARCHAR(30), UniqueProtein VARCHAR(30), Carbohydrate VARCHAR(30), SourcedinUSA VARCHAR(30), MadeinUSA VARCHAR(30), MakesTreats VARCHAR(30)); INSERT INTO brands VALUES ( "Acana", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Potato", "N", "N", "N" ), ( "Annamaet", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Rice", "Y", "Y", "N" ), ( "Annamaet Grain Free", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Potato", "Y", "Y", "N" ), ( "Before Grain", "Y", "Y", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "Y", "Potato", "Y", "Y", "N" ), ( "Blue Buffalo", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "Y", "N", "Y", "N", "N", "Y", "Y", "N", "N", "N", "Rice", "Y", "Y", "Y" ), ( "Blue Buffalo Wilderness", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "Y", "N", "Y", "N", "N", "Y", "Y", "N", "Y", "N", "Potato", "Y", "Y", "Y" ), ( "California Natural", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "Y", "Y", "Y", "N", "N", "N", "N", "Y", "N", "Rice", "Y", "Y", "Y" ), ( "California Natural Grain Free", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "Pea", "Y", "Y", "N" ), ( "Canidae", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "N", "N", "Y", "N", "N", "N", "N", "N", "N", "N", "Rice", "Y", "Y", "Y" ), ( "Canidae Pure", "Y", "Y", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Potato", "Y", "Y", "N" ), ( "Chicken Soup", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "N", "N", "N", "Y", "N", "N", "N", "Barley/Rice", "N/A", "Y", "N" ), ( "Darford", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "Y", "N", "N", "N", "N", "N", "N", "Legumes", "Y", "Y", "Y" ), ( "Daves ", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "Y", "N", "Y", "Y", "N", "N", "N", "N", "Y", "N", "Rice", "N/A", "Y", "N" ), ( "Eukanuba", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "Y", "N", "Y", "Y", "Y", "N", "N", "Corn", "N", "N/A", "Y" ), ( "Eukanuba Pure", "Y", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "Y", "N", "N", "N", "Rice", "N", "N/A", "N" ), ( "Evangers-Canned Products", "N", "Y", "N", "N", "N", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "Y", "N", "Varies", "N/A", "Y", "Y" ), ( "Evo", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "Y", "Y", "Y", "N", "N", "Y", "N", "N", "Y", "Y", "Potato/Peas", "N/A", "Y", "Y" ), ( "Fromm", "Y", "Y", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "Y", "N", "N", "N", "N", "N", "Y", "N", "Varies ", "Y", "Y", "Y" ), ( "Holistic Select", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "N", "N", "Y", "Y", "N", "Y", "N", "Rice", "N/A", "Y", "Y" ), ( "Iams", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "Y", "N", "Y", "N", "N", "Y", "Y", "N", "Y", "N", "Corn", "N", "N/A", "Y" ), ( "Iams Naturals", "Y", "N", "N", "N", "N", "N", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Y", "N", "Rice", "N", "N/A", "N" ), ( "Innova", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "N", "N", "Y", "Y", "N", "N", "N", "Barley", "N/A", "Y", "Y" ), ( "Innova Prime", "Y", "N", "N", "N", "N", "N", "Y", "N", "N", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Legumes", "N/A", "Y", "Y" ), ( "Instinct", "Y", "Y", "Y", "Y", "N", "Y", "Y", "N", "Y", "Y", "Y", "N", "Y", "N", "N", "N", "N", "Y", "Y", "Grain Free", "N", "Y", "Y" ), ( "Merrick", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Rice", "N/A", "Y", "Y" ), ( "Natural Balance-LID", "Y", "Y", "N", "N", "N", "N", "N", "N", "Y", "Y", "Y", "N", "Y", "N", "Y", "N", "N", "Y", "Y", "Swt Potato", "N/A", "Y", "Y" ), ( "Natural Balance", "Y", "Y", "N", "N", "N", "N", "Y", "N", "Y", "N", "N", "Y", "N", "Y", "N", "N", "N", "N", "N", "Varies", "N/A", "Y", "Y" ), ( "Natural Balance Alpha", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Legumes", "N/A", "Y", "N" ), ( "Nemans Own", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "Y", "N", "N", "N", "Y", "N", "Rice", "N/A", "N/A", "Y" ), ( "Nutrisca", "Y", "N", "N", "Y", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Legumes", "N/A", "Y", "Y" ), ( "Nutri-Source", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "N", "N", "Y", "Y", "N", "N", "N", "Rice", "N/A", "Y", "N" ), ( "Nutro Natural Choice", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "Y", "N", "Y", "Y", "N", "Y", "Y", "Rice", "N/A", "Y", "Y" ), ( "Nutro Ultra", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "N", "N", "Y", "Y", "N", "N", "N", "Rice", "N/A", "Y", "Y" ), ( "Nutro Natural Choice Grain Free", "Y", "Y", "N", "N", "N", "N", "Y", "N", "N", "Y", "N", "N", "N", "N", "N", "Y", "N", "Y", "Y", "Potatoes", "N/A", "Y", "N" ), ( "Nutro Max", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "N", "N", "Y", "Y", "N", "Y", "N", "Rice", "N/A", "Y", "Y" ), ( "Orijen", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "N", "Y", "N", "N", "N", "Potato", "N", "N", "N" ), ( "Pinnacle", "Y", "Y", "N", "N", "N", "N", "N", "N", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "Varies", "Y", "Y", "N" ), ( "Pinnacle Grain Free", "Y", "Y", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "Potatoes", "Y", "Y", "N" ), ( "Prairie", "Y", "Y", "N", "N", "N", "Y", "N", "N", "Y", "N", "N", "N", "N", "N", "N", "Y", "N", "Y", "Y", "Varies", "N", "Y", "N" ), ( "Precise Holistic", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "N", "Y", "N", "Varies", "N/A", "Y", "N" ), ( "ProPlan", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "Y", "N", "N", "Y", "Y", "N", "Y", "Y", "N", "N", "N", "Brewers Rice", "N/A", "N/A", "Y" ), ( "Royal Canin", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "Y", "N", "Y", "Y", "Y", "Y", "N", "Rice", "N", "N", "N" ), ( "Sammy Snacks", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "N", "N", "N", "Y", "N", "Y", "Y", "Rice", "N/A", "N/A", "Y" ), ( "Science Diet", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "Y", "N", "Y", "Y", "N", "Y", "N", "Corn", "N/A", "N/A", "Y" ), ( "Solid Gold", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "Y", "N", "Y", "N", "N", "Y", "Y", "N", "Y", "Y", "Varies", "N/A", "Y", "Y" ), ( "Spots Stew", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "N", "Y", "N", "N", "N", "N", "oats/barley", "N", "Y", "Y" ), ( "Taste of the Wild", "Y", "Y", "N", "N", "N", "Y", "Y", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "potatoes", "N/A", "Y", "N" ), ( "Verus", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "N", "N", "Y", "N", "Y", "N", "Varies", "Y", "Y", "N" ), ( "Wellness", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "N", "Y", "Y", "N", "Y", "Y", "N", "Y", "N", "Oatmeal", "N/A", "N/A", "Y" ), ( "Wellness Core", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "N", "Y", "N", "Y", "N", "N", "N", "N", "N", "N", "Y", "Peas/potatoes", "N/A", "N/A", "N" ), ( "Wellness Simple", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "N", "N", "Y", "N", "Y", "N", "N", "N", "N", "Y", "Y", "Rice", "N/A", "N/A", "N" ), ( "Whole Earth Farms", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Oatmeal", "Y", "Y", "Y" ), ( "Wysong", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "Y", "N", "None", "Y", "Y", "N" ) The Script is: <h2>Search</h2> <form name="search" method="post" action="<?=$PHP_SELF?>"> Seach for: <Select NAME="find"> <Option VALUE="">Select</option> <Option VALUE="Y">Yes - My Results Should Contain A Positive Yes</option> <Option VALUE="N">No- My Results Should Contain A Positive NO</option> </Select> <!--Commented out Not needed...I don't think-- in <Select NAME="field"> <Option VALUE="">Select</option> <Option VALUE="Dry">Dry</option> <Option VALUE="Canned">Canned</option> <Option VALUE="Raw">Raw</option> <Option VALUE="FreezeDried">Freeze Dried</option> <Option VALUE="Dehydrated">Dehydrated</option> <Option VALUE="Puppy">Puppy</option> <Option VALUE="Adult">Adult</option> <Option VALUE="Senior">Senior</option> <Option VALUE="AllLifeStages">All Life Stages</option> <Option VALUE="GrainFree">Grain Free</option> <Option VALUE="LimitedIngredient">Limited Ingredient</option> <Option VALUE="WeightManagement">Weight Management</option> <Option VALUE="SensitiveStomach">Sensitive Stomach</option> <Option VALUE="Organic">Organic</option> <Option VALUE="SmallBreed">Small/Toy Breed</option> <Option VALUE="LargeBreed">Large Breed</option> <Option VALUE="BreedSpecific">Breed Specific</option> <Option VALUE="SingleProtein">Single Protein</option> <Option VALUE="UniqueProtein">Unique Protein</option> <Option VALUE="Carbohydrate">Carbohydrate</option> <Option VALUE="SourcedinUSA">Sourced in USA</option> <Option VALUE="MadeinUSA">Made in USA</option> <Option VALUE="MakesTreats">Makes Treats</option> </Select> --> <p> </p> Dry <input type="checkbox" name="field" value="Dry"> <br> Canned <input type="checkbox" name="field" value="Canned"> <br> Raw <input type="checkbox" name="field" value="Raw"> <br> Freeze Dried <input type="checkbox" name="field" value="FreezeDried"> <br> Dehydrated <input type="checkbox" name="field" value="Dehydrated"> <br> Puppy <input type="checkbox" name="field" value="Puppy"> <br> Adult <input type="checkbox" name="field" value="Adult"> <br> Senior <input type="checkbox" name="field" value="Senior"> <br> AllLifeStages <input type="checkbox" name="field" value="AllLifeStages"> <br> GrainFree <input type="checkbox" name="field" value="GrainFree"> <br> LimitedIngredient <input type="checkbox" name="field" value="LimitedIngredient"> <br> WeightManagement <input type="checkbox" name="field" value="WeightManagement"> <br> SensitiveStomach <input type="checkbox" name="field" value="SensitiveStomach"> <br> Organic <input type="checkbox" name="field" value="Organic"> <br> SmallBreed <input type="checkbox" name="field" value="SmallBreed"> <br> LargeBreed <input type="checkbox" name="field" value="LargeBreed"> <br> BreedSpecific <input type="checkbox" name="field" value="BreedSpecific"> <br> SingleProtein <input type="checkbox" name="field" value="SingleProtein"> <br> UniqueProtein <input type="checkbox" name="field" value="UniqueProtein"> <br> Carbohydrate <input type="checkbox" name="field" value="Carbohydrate"> <br> SourcedinUSA <input type="checkbox" name="field" value="SourcedinUSA"> <br> MadeinUSA <input type="checkbox" name="field" value="MadeinUSA"> <br> MakesTreats <input type="checkbox" name="field" value="MakesTreats"> <br> <p> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <BR><BR> ---------------------- <BR><BR> <table CELLPADDING=3 border =1> <tr> <td><center><B>BRAND</B></center></td> <td><img src="images/dry.png"></td> <td><img src="images/canned.png"></td> <td><img src="images/raw.png"></td> <td><img src="images/freezedried.png"></td> <td><img src="images/dehydrated.png"></td> <td><img src="images/puppy.png"></td> <td><img src="images/adult.png"></td> <td><img src="images/senior.png"></td> <td><img src="images/alllifestages.png"></td> <td><img src="images/grainfree.png"></td> <td><img src="images/limiteding.png"></td> <td><img src="images/weightmanage.png"></td> <td><img src="images/senstomach.png"></td> <td><img src="images/organic.png"></td> <td><img src="images/smallbreed.png"></td> <td><img src="images/largebreed.png"></td> <td><img src="images/breedspecif.png"></td> <td><img src="images/singprotein.png"></td> <td><img src="images/uniquepro.png"></td> <td><center><img src="images/carbs.png"></center></td> <td><img src="images/soundedusa.png"></td> <td><img src="images/madeinusa.png"></td> <td><img src="images/makestreats.png"></td> </tr> <tr> <? //This is only displayed if they have submitted the form if ($searching =="yes") { echo "<h2>Results</h2><p>"; //If they did not enter a search term we give them an error if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "****************", "*************") or die(mysql_error()); mysql_select_db("foradoma_search") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM brands WHERE upper($field) LIKE'%$find%'"); //And we display the results while($result = mysql_fetch_array( $data )) { echo "<td>".$result['brand']; echo "<td>".$result['Dry']."</td>"; echo "<td>".$result['Canned']."</td>"; echo "<td>".$result['Raw']."</td>"; echo "<td>".$result['FreezeDried']."</td>"; echo "<td>".$result['Dehydrated']."</td>"; echo "<td>".$result['Puppy']."</td>"; echo "<td>".$result['Adult']."</td>"; echo "<td>".$result['Senior']."</td>"; echo "<td>".$result['AllLifeStages']."</td>"; echo "<td>".$result['GrainFree']."</td>"; echo "<td>".$result['LimitedIngredient']."</td>"; echo "<td>".$result['WeightManagement']."</td>"; echo "<td>".$result['SensitiveStomach']."</td>"; echo "<td>".$result['Organic']."</td>"; echo "<td>".$result['SmallBreed']."</td>"; echo "<td>".$result['LargeBreed']."</td>"; echo "<td>".$result['BreedSpecific']."</td>"; echo "<td>".$result['SingleProtein']."</td>"; echo "<td>".$result['UniqueProtein']."</td>"; echo "<td>".$result['Carbohydrate']."</td>"; echo "<td>".$result['SourcedinUSA']."</td>"; echo "<td>".$result['MadeinUSA']."</td>"; echo "<td>".$result['MakesTreats']."</td>"; echo "</tr>"; echo "<tr>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 16, 2012 Share Posted May 16, 2012 Good god use code tags. There's nothing in there relating to your question. And there's a ton of other errors, like every single one of your checkboxes has the same name. I recomend looking at some basic HTML/PHP tutorials then coming back to the project. You clearly don't even know what part of the code is doing what. Quote Link to comment Share on other sites More sharing options...
a6april Posted May 16, 2012 Author Share Posted May 16, 2012 That's because they are all in the same field. The values are different as they relate to the query as it stated in the various tutorials I read, Thanks anyway... I have read the PHP tutorials which lead me to my current problem. Anyone else??? If I am not clear please let me have an opportunity to clarify. Thanks in advance Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 16, 2012 Share Posted May 16, 2012 If you have a set of checkboxes with the same name, you will only ever get one of the values, unless you make the name an array, which you have not done. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 16, 2012 Share Posted May 16, 2012 I stopped looking at the code when I saw all the "Boolean" fields were set as 30 character VARCHARs. Do NOT use Y/N for fields that should be logical TRUE / FALSE values. Instead use a tinyint type field and use 1/0 for the value. Additionally, since you need to create several sets of HTML output using the same list of values, they should be in an array so you can create that output dynamically. Quote Link to comment Share on other sites More sharing options...
a6april Posted May 16, 2012 Author Share Posted May 16, 2012 ok, thanks I looked up arrays at php.net and found quite a bit, I'll have to narrow it down, by doing so I have to read each and every one to see how it specifically applies here. I will also take a look at the boolean search criteria. I am not sure what exactly, but I will get to it perhaps in a month or so when I finish up with array. I may have started this all with the wrong starter script. The original was pretty basic, I thought a great way to get involved with php, but this got a little out of my scope of experience pretty quick. I thought by posting here I could get a jump start into the correct direction and build from there, the criticism is great because it keeps me sharp and thinking about other ways that perhaps I didn't consider, however but not too helpful in moving forward. I'll finish this up in java which should only take a day or two and then I'll go back to the php books. php.net is a great resource. Thanks for all of your support and consideration. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 17, 2012 Share Posted May 17, 2012 Here is an example of how you could replace a large portion of the hard-coded content and make it dynamically created. This ensures that all the elements are being generate3d consistently. If you are hard-coding a lot of content like you have above it is common to have copy/paste errors. And, with so many variables, such an error could go undetected for a long time. <?php $fieldList = array ('Dry', 'Canned', 'Raw', 'FreezeDried', 'Dehydrated', 'Puppy') //Use the aarray to create dynamic HTML $options = ''; $checkboxes = ''; $images = ''; foreach($fieldList as $field) { $options .= "<option value='{$field}'>{$field}</option>"; $checkboxes .= "{$field} <input type='checkbox' name='fields[]' value='{$field}'><br>\n"; $images ,= "<td><img src='images/{$field}.png'></td>\n"; } ?> <h2>Search</h2> <form name="search" method="post" action=""> Seach for: <Select name="find"> <option VALUE="">Select</option> <option VALUE="Y">Yes - My Results Should Contain A Positive Yes</option> <option VALUE="N">No- My Results Should Contain A Positive NO</option> </select> <select name="field"> <option value="">Select</option> <?php echo $options; ?> </select> <p> </p> <?php echo $checkboxes; ?> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <BR><BR> ---------------------- <BR><BR> <table cellpadding=3 border =1> <tr> <td><center><B>BRAND</B></center></td> <?php echo $images; ?> </tr> Quote Link to comment Share on other sites More sharing options...
a6april Posted May 17, 2012 Author Share Posted May 17, 2012 Awesome, Thanks Huge Psycho this is a great start....I appreciate it. This is actually starting to make sense.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.