![]() |
|
| |||||||
| Notices |
| mySQL & PHP Discussions, information and help with mySQL and PHP. |
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| Hello everyone, I’ve created a sql based search feature and have successfully created the following DB: Create database users; And I’ve successfully created the following tables: insert into users set title="example", description="example description example description example description example description", url="www.mclexa.com", status="certified", file="none", keywords="happy sad glad mad jump high low fast slow" I then successfully modified the following sql search script to quiry the DB and return the results of the search and paginate the pages using this script: <? //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 $hostname_logon = "localhost" ; $database_logon = "data base name" ; $username_logon = "user name" ; $password_logon = "my password" ; //open database connection $connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to the database" ); //select database mysql_select_db($database_logon) or die ( "Unable to select database!" ); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //__________________________________________________ _______________________________ //This checks to see if there is a page number. If not, it will set it //to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //__________________________________________________ _______________________________ //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'"); $rows = mysql_num_rows($data); //__________________________________________________ ___________________________________ //This is the number of results displayed per page $page_rows = 10; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than //our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //__________________________________________________ ____________________ //Now we search for our search term, in the field the user specified $data_p = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'"); //This is where you display your query results while($info = mysql_fetch_array( $data_p )) { Print $info['title']; echo "<br>"; Print $info['status']; echo "<br>"; Print $info['description']; echo "<br>"; Print $info['url']; echo "<br>"; Print ""; echo "<br>"; Print ""; echo "<br>"; Print ""; echo "<br>"; } // This shows the user what page they are on, and the total //number of pages echo " --Page $pagenum of $last-- <p>"; // First we check if we are on page one. If we are then we don't //need a link to the previous page or the first //page so we do //nothing. If we aren't then we generate links to the first page, //and to the previous page. if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } //just a sp**** echo " "; //This does the same as above, only checking if we are on the //last page, and then generating the Next and Last //links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } } ?> QUESTIONS: 1. How do you alter the scripts code to provide a text format similar to that illustrated at the link below? http://www.mclexa.com/examplesearchresult.html 2. How do I connect a link to the variable entered into the “title” field to cause a url jump to the variable url entered into the "url" field? 3. How do you alter the scripts code to provide a link to 1 of 2 possible urls based entirely upon the value stored in the “status” coulumb? Example: if “status” contains the word pending - connect a link to the word “pending” that will cause a jump to http://www.mclexa.com/pending.html. if “status” contains the word certified - connect a link to the word “certified” that will cause a jump to http://www.mclexa.com/certified.html. 4. When the words "VIEW DOCUMENT" are clicked - how do I cause a pop up window to appear and display the PDF or JPEG document entered and stored in the “file” field? Forever in your dept!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! |