Jump to content

Jimi_l

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Jimi_l's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi All, I found a script online to search my DB and display the results- http://teamtutorials.com/web-development-tutorials/php-tutorials/creating-a-form-that-will-search-a-mysql-database While it works perfectly, I would like to make the results auto fill a form that could be re-submitted as an update to the record if needed. In other words, search for an entry and then update the fields in the DB if required. Any ideas where to look or what to search for? I have not had much luck so far. Thanks in advance, Jim
  2. No, I have a DB called "parts" and in it one table called "all. In that table is five fields labeled F0 to F5. I was under the assumption that the query was coded to search all fields in that one table. The make. model and part are the user entered variables from the search script. Is this incorrect? Jim
  3. Hi All, I changed the line and now get the following with any query- SELECT * FROM all WHERE make LIKE '%%' or model LIKE '%%' or part LIKE 'brakes%' 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 'all WHERE make LIKE '%%' or model LIKE '%%' or part LIKE 'brakes%'' at line 1 The phrase "brakes" was searched for thin this instance but with other phrases I get identical results. I noticed the double "%" which seems like an issue for the fields left blank. Thanks again, Jim
  4. Hello Again, This is indeed more promising however I get no results regardless of what I search for. I simply get the "failed" message which I assume is from this line- if ($result === FALSE) die("failed\n"); I added this line to the top to see what was happening- error_reporting(E_ALL); ini_set('display_errors', '1'); And get no errors which I assume would mean the search found nothing however I know the data is there and I get results on similar searches in phpmyadmin. You mentioned using all kinds of column names but I was under the impression I was not. In the search string- $query = "SELECT * FROM $table WHERE make LIKE '$make%' or model LIKE '$model%' or part LIKE '$part%'"; I assumed it was looking at EVERY field in the table called "all" of the DB called "parts" as defined previously as opposed to specific fields. Is this incorrect? Anyway thanks again for helping out a dumb(you know what). I have actually installed a good deal PHP apps, edited files therein, set up mail and Web servers, do a ton of system builds, ect but never hacked away at raw code from scratch. I appreciate your patience. Jim
  5. Me Again, I have a few questions. If you would rather just point me to a link to read that would be fine to as I have looked but rarely find the exact issue I am looking for. Perhaps you could give me a hint or example? 1) if(isset($_GET['Submit'])) {... I assume the "if" statement is waiting for input from the button but the {... (braces?) seems to indicate there should be something else there inside of them. What would this be? 2) How would I submit three different variables? 3) How would I define the three variables? 4) I knew this was wrong (or I suspected anyway). This is a bunch of cobbled together codes I found online. 5) Braces after it? Like all alone braces after it?
  6. Hi Orio, Yes I know there are many mistakes. I turned onn error displaying and found many undefined variables (which I suspected). I do appreciate you taking the time to help. I have to go to work now but will return tonight. make the changes and return the results. Thanks again, Jim
  7. Hi All, Below is a search form I am trying to build. My DB (parts) has 1 table (all) and 5 fields (f0 to f5). The script errors out with the following- failed Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Abyss Web Server\htdocs\search.php on line 56 failed 2 The entire code is as follows- <html> <head><title>Database Search</title></head> <form name="form" action="search.php" method="get"> <p> make (ex.Acura) <input type="text" name="x" /> <br> model (ex.Inegra) <input type="text" name="y" /> <br> part (ex.brakes) <input type="text" name="z" /> <input type="submit" name="Submit" value="Search" /> </p> </form> <?php // get variables $var = @$_GET['x'] ; $var = @$_GET['y'] ; $var = @$_GET['z'] ; /* connection information */ $hostname = "localhost"; $username = "root"; $password = "admin"; $dbName = "parts"; $table = "all"; /* make connection to database */ MYSQL_CONNECT($hostname, $username, $password) OR DIE( "Unable to connect to database"); @mysql_select_db("$dbName") or die( "Unable to select database"); if ($make == "x") {$make = '%';} if ($model == "y") {$model = '%';} if ($part == "z") {$part == '%';} $query = ("SELECT * FROM $table WHERE make LIKE '$make%' or model LIKE '$model%' or part LIKE '$part%'"); $result = MYSQL_QUERY($query); if (!$result) print ("failed\n"); /* Determine the number of records returned */ WHILE ($row=MYSQL_FETCH_ROW($result)) $number = mysql_numrows($result); if (!$number) print("failed 2 \n"); /* Print the relevant information */ $i = 0; PRINT "<font face=\"Verdana, Arial, Helvetica, sans-serif\"> <b>There are $number records in the inventory:</b></font><p>"; PRINT "<table cellpadding=5>"; PRINT " <TR bgcolor=black> <td><font face=\"Verdana, Arial,Helvetica, sans-serif\" size=\"-1\" color=white><b>make </b></font></td> <td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" color=white><b>model </b></font></td> <td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" color=white><b>part</b></font></td></tr>"; WHILE ($i < $number): $make = mysql_result($result, $i,"make"); $model = mysql_result($result, $i,"model"); $part = mysql_result($result,$i,"part"); if ($i%2 == 0) { PRINT "<tr bgcolor=lightgrey> <td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\">$make</font></td> <td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\"> $model</font></td> <td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\"> $part</font></td></tr>"; } else { PRINT "<tr bgcolor=lightgreen> <td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\">$LastName</font></td> <td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\"> $FirstName</font></td> <td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\"> $Address</font></td></tr>"; } $i++; ENDWHILE; PRINT "</table>"; /* Close the database connection */ MYSQL_CLOSE(); ?> </body> </html> It seems as if the form is submitted before any data is entered. Any ideas would be greatly appreciated. I have really struggling with this whole project for a while now and it is learn as I go. I have tried breaking this into two, the form and the .php with identical results. Thanks, Jim
  8. Hi, The DB itself is not that large but phpmyadmin does shot out a butload of code for even a simple search. It has the feature to "show php" in regards to what it is doing for the query and even a single table is about a page long so all of them must be 23 times that at least. I think my issue (at least one of them anyway) is a crappy DB to begin with. I was handed this as is so I may start from scratch but even then it would just be a zillion fields as opposed to tables. I appreciate the input, Jim
  9. Hi Fenway, I did mean entire database. I can select all 23 tables and it will search every field of every table in that one databse almost instantly. Jim
  10. Me Again, I noticed that the phpmyadmin interface allows you to search all tables and fields but does not show the code on how it is being accomplished. If you search one table, all fields it displays the search code in a little window but not for an all/all query. Any ideas on this? Thanks again, Jim
  11. Really? That seems a little counter intuitive for a database. Do you have any pointers as to a third party indexing application? Actually I am greatly amazed how difficult this project has turned out. You would think that searching an entire DB would be easily accomplished with any number of editable pre-existing open source script, but it's not. Even a single variable for a single table and field is a chore. Heck I can't even find commercial software that does it. Crazy stuff. Jim
  12. Hi All, I have two questions in regards to PHP and MySQL that I hope someone will help me with with. I understand if this seems to "write it for me" but I have looked all over the place for a few days with no luck. Anyway, any help or direction is appreciated. If this single data entry form- <form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> Calls to this function to search- $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable How would a form with three user supplied entires change to include all three variables? In other words search for "q" and "r" and "s"? Second question. If this code calls to search a given table and field for that single search field- $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; How could it be rewritten to search ALL tables and fields of a single DB using all three user supplied fields? The DB has about 30 tables and many fields in each which I would assume would require a zillion "and's" but I suspect there is a better way. Thanks in advance for any help, Jim
  13. Hi All, Still on the hunt for a three option, all tables and rows in a single MySQL DB search and came across this code (attached). I was hoping someone could clear a few things up for me. This line for example- // EDIT HERE and specify your table and field names for the SQL query $query = "SELECT * FROM tablename WHERE field1 LIKE \"%$trimm%\" OR field2 LIKE \"%$trimm%\" OR field3 LIKE \"%$trimm%\" ORDER BY field1 DESC" ; When he refers to editing the table I assumed it means change the section "FROM tablename" to read "FROM one table in my db" but what does he mean by field? Perhaps a better question is how would this be re-written to include ALL tables and rows in a single DB? Also of note is there seems to be no HTML for search options. Most of the code samples I have found so far start with an HTML form to input the search parameters. I can write my own easy enough but how to connect it to this script? Thanks, Jim [attachment deleted by admin]
  14. You are correct, That is exactly the issue and what I had in mind. If I could see such an application I am sure I could modify it for my use but I have been unable to find any multi option search in any script. Odd but there was another reply and my response to it but they seem to have disappeared ??? It regarded the DB structure itself which may be a problem. All the years are in two digit hyphenated form (88-05). I don't think there is any language that is going to "know" that means ALL the years 1988 thru 2005 but would only hit on 88 and 05 instead. Thanks again, Jim
×
×
  • 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.