Jump to content

RobertFullmen

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Everything posted by RobertFullmen

  1. Hey All! I have a text file that I use to update my database. It always the same filename and always sits in the same file. Is there a way I can import that file automatically into my database via php? Thanks. Robert
  2. Thanks for the quick response. I didn't know that desc was a reserved word so I changed it. I modified the code as per your instruction and now I get the following message "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'title LIKE '%chair%') OR (content LIKE '%chair%')' at line 1" chair happens to be the search term. $search = $_POST["search"]; $arraySearch = explode(" ", $search); $arrayFields = array(0 => "title", 1 => "content"); $countSearch = count($arraySearch); $a = 0; $b = 0; $query = "SELECT * FROM table1 WHERE Description LIKE '$search'"; $countFields = count($arrayFields); while ($a < $countFields) { while ($b < $countSearch) { $query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'"; $b++; if ($b < $countSearch) { $query = $query." AND "; } } $b = 0; $a++; if ($a < $countFields) { $query = $query.") OR ("; } } $query = $query.")"; echo $query; $query_result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($query_result) < 1) { echo '<p>No matches found for "'.$search.'"</p>'; } else { Print "<table border cellpadding=3>"; while($row = mysql_fetch_assoc($query_result)) echo $query; { Print "<th>Description:</th> <td>".$row['Description']. "</td> "; } Print "</table> "; }
  3. Hey All, I'm trying to add multiple word search to my site and I'm getting the following error: "mysql_num_rows(): supplied argument is not a valid MySQL result resource " I know, my search is posting because I'm getting my search terms back with the "nothing found" message I have set up. Here's what I have: $search = $_POST["search"]; $arraySearch = explode(" ", $search); $arrayFields = array(0 => "title", 1 => "content"); $countSearch = count($arraySearch); $a = 0; $b = 0; $query = "SELECT * FROM table1 WHERE desc LIKE '$arraySearch'"; $countFields = count($arrayFields); while ($a < $countFields) { while ($b < $countSearch) { $query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'"; $b++; if ($b < $countSearch) { $query = $query." AND "; } } $b = 0; $a++; if ($a < $countFields) { $query = $query.") OR ("; } } $query = $query.")"; $query_result = mysql_query($query); if(mysql_num_rows($query_result) < 1) { echo '<p>No matches found for "'.$search.'"</p>'; } else { Print "<table border cellpadding=3>"; while($row = mysql_fetch_assoc($query_result)) { Print "<th>Description:</th> <td>".$row['desc']. "</td> "; } Print "</table> "; } You guys are the best, thanks so much.
  4. Hey All. I'm trying to modify a search I have setup. What I want to do is take out the text field and replace it with a dropdown menu. It starts with an html form Old working code: <form action="result.php" method="post"> <div align="center">Search: <input type="text" name="search" /> <input type="submit" /> </div> </form> New non working code: <form action="result.php" method="POST"> <select name="dropdown"> <option value="option1">option1</option> <option value="option2">option2</option> <option value="option3">option3</option> </select><input type="submit" name="search" /> </form> That should open up result.php which searches two fields in a mysql database and prints of the results. result.php $var = $_POST["search"]; $data = mysql_query("select * FROM database1 WHERE field1 LIKE '$var' || field2 LIKE '$var'") or die(mysql_error()); echo $data; ?> If result.php not receiving the info in the dropdown or am I handling it wrong in the php? Thanks so much.
  5. Yes they're all in the same database. As demonstrated in the code I posted above, I have one search that looks at three fields in the database. One of field (item number) is the thing that needs the keyword.
  6. Here's what I have: $s_input = $_POST["search"]; $data = mysql_query("select * FROM inv_DB WHERE itm_num LIKE '$s_input' || Description LIKE '$s_input' || Price LIKE '$s_input'") or die(mysql_error()); Print "<table border cellpadding=3>"; while($info = mysql_fetch_array( $data )) { Print "<tr>"; Print "<th>" ; echo '<img src="uploads/'.$info['img1'].'" width="153" "height="271" />'; "</td> " ; Print "<th>Item Number:</th> <td>".$info['itm_num'] . "</td> "; Print "<th>Description:</th> <td>".$info['Description'] . "</td> "; Print "<th>Price:</th> <td>$".$info['Price'] . "</td> "; } Print "</table> "; ?> Thanks akeane, that does the trick aside from one thing. My search needs to check other fields besides the item number.
  7. Yes, thanks. Thank you for the response. This isn't exactly what I'm looking for because the there isn't anything like a keyword_field. I basically have, item number and description in the database so I need the to match up '555%' with the word 'Chair' (and other numbers for other words). I've been using an if statement saying that is 'search' = chair then search for 555%. But I have close to 200 such statements to write.
  8. Hi Everyone, I'm trying to set up a system for my PHP MYSQL search that allows the user to type keywords. I've been doing this with one very long if statement, is there a better way? For example, I want to user to search for "chair" and have the thing return everything with a item number stating with 555. The length of the item number can vary between 10 and 12 numbers and that has slowed me down a bit. Cheers, Rob
  9. I got it! Thanks so much for the help everyone. I was over thinking it a bit, here's what worked: $data = mysql_query("select * FROM Inventory WHERE img1 LIKE 'Searchterm'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo '<img src="images/'.$info['img1'].'"><br />'; }
  10. I'm getting nothing <img src="images/" alt="" /><br /> somewhere I'm loosing the data.
  11. Thanks Keith, I was trying something very similar to what you posted. In both cases however the image doesn't show up. So I echoed $result and got "Resource id #2" which is what I got the first time... What could be the problem?
  12. Hey all, I've written a php search feature for a mysql database. The search returns a file name like sample.gif, how would I go about displaying the actual image instead? Since the images all have the same location could I have the search return the string into a variable then make the whole thing a link? Thanks.
×
×
  • 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.