Jump to content

a6april

Members
  • Posts

    9
  • Joined

  • Last visited

Everything posted by a6april

  1. WOW, That worked like a charm! Thank you Sooo Much!!!
  2. Hello. I am uploading a csv file and populating a data base. I have tried all kinds of things to get the header removed from the input but it either stops writing all together or breaks. Can anyone help me or does anyone have any suggestions? It works pretty good as intended now except for the one header record that gets added. Here is my script: <?php include '_inc/include.php'; if ($_FILES[csv][size] > 0) { //get the csv file $file = $_FILES[csv][tmp_name]; $handle = fopen($file,"r"); //loop through the csv file and insert into database do { if ($data[0]) { $mysql_query = mysql_query("INSERT INTO carbon_PA (closeddate, soldprice, streetnumber, streetname, streetsuffix, city, state, zip, gla, built, acres, taxid, photo, dom) VALUES ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."', '".addslashes($data[3])."', '".addslashes($data[4])."', '".addslashes($data[5])."', '".addslashes($data[6])."', '".addslashes($data[7])."', '".addslashes($data[8])."', '".addslashes($data[9])."', '".addslashes($data[10])."', '".addslashes($data[11])."', '".addslashes($data[12])."', '".addslashes($data[13])."' ) "); } } while ($data = fgetcsv($handle,10000,",","'")); // //redirect } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Import a CSV File with PHP & MySQL</title> </head> <body> <?php if (!empty($_GET[success])) { echo "<b>Your file has been imported by import 55.</b><br><br>"; } //generic success notice ?> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> Choose your file: <br /> <input name="csv" type="file" id="csv" /> <input type="submit" name="Submit" value="Submit" /> </form> <P> Display Data Contents <a href ='Data-Display.php'>here</a></P> </body> </html>
  3. Hello All, I was hoping to get an understanding of displaying data from a specific column in a MySQL database using php. for example lets say the column field is called features and the input contains many features of the record seperated by pipes | and semi colons. (This is imported by a csv file by the way) Lot Description|Flat|Yes;Lot Description|Adjoins Greenbelt|Yes;Lot Description|Wooded Lot|Yes;Lot Description|Irregular|Yes;Outside Features|Deck|Yes;Outside Features|Other - See Remarks|Yes;Outside Features|Utility Shed|Yes; etc etc and so on <td><?php echo $row_vvcarbonall['Features']; ?></td> Would I create an array for this, or is this an if else scenario or is there a way to replace the output of ';' with perhaps a break or is there some other approach I should be considering. Thanks
  4. Hi All! Have a couple of questions I hope you can help me with. I am creating an upload by browse button. Select the csv file and upload. Then run Queries on the data later. A couple of problems is that this only works when I re edit the csv file renaming the headers or columns. Some of the column headers contain spaces, #,$,/, etc and of course MySQL doesn't like these characters. Another issue I have is I can not figure out, how to populate the table using the first row of the csv file as the column header. Right now I was able to try and test it renaming the header file and adding the MySQL values in the php and worked ok, however ultimately I want the user to be able to browse for the csv file upload it and then be able to run the queries, but my script is set up for "here is the csv file, these are the headers, they already match up so lets go ahead and populate the rows" Ultimately it should be "here is the csv file, lets take the first row and use that to create our column headers, renaming the column headers for user friendly while removing duplicates, slashes etc etc and then lets go ahead and populate the rows" Here is my code, I am assuming I will have to start from scratch? <?php include '_inc/include.php'; if ($_FILES[csv][size] > 0) { //get the csv file $file = $_FILES[csv][tmp_name]; $handle = fopen($file,"r"); //loop through the csv file and insert into database do { if ($data[0]) { $mysql_query = mysql_query("INSERT INTO carbon_PA (closeddate, soldprice, streetnumber, streetname, streetsuffix, city, state, zip, gla, built, acres, taxid, photo, dom) VALUES ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."', '".addslashes($data[3])."', '".addslashes($data[4])."', '".addslashes($data[5])."', '".addslashes($data[6])."', '".addslashes($data[7])."', '".addslashes($data[8])."', '".addslashes($data[9])."', '".addslashes($data[10])."', '".addslashes($data[11])."', '".addslashes($data[12])."', '".addslashes($data[13])."' ) "); } } while ($data = fgetcsv($handle,10000,",","'")); // //redirect } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Import a CSV File with PHP & MySQL</title> </head> <body> <?php if (!empty($_GET[success])) { echo "<b>Your file has been imported by import 55.php</b><br><br>"; } //generic success notice ?> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> Choose your file: <br /> <input name="csv" type="file" id="csv" /> <input type="submit" name="Submit" value="Submit" /> </form> <P> Display Data Contents <a href ='display55.php'>here</a></P> </body> </html> I would really appreciate any advice or help or direction on this. Thank You!
  5. Awesome, Thanks Huge Psycho this is a great start....I appreciate it. This is actually starting to make sense....
  6. 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.
  7. 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
  8. 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>
  9. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.