PHP - Multiple Search Boxes Help W/php Script To Get Mysql Results
I have a simple (1 table, 14 fields) database. I'm using 9 separate search boxes from my search page :
http://www.cinemaposter.com/database.html There are currently 162 entries. Hitting "submit" throws them all out, same with valid input into any box, with the exception of "country" - example : entering "F" gives 20results; "PL" gives 34 results. Here's my code (to simplify, I only went down to the 4th box ('country' - the last and only one giving correct results). I'm one sorry newbie.... please help ! Here's the code : ------------------ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd"> <html> <head> <title>Search Results</title> <meta name="generator" content="BBEdit 6.5"> <style type="text/css"> td { color: #000000; font-family: arial; font-size: 10px; } </style> </head> <body> <?php $link = mysql_connect("xxxx", "xxxx", "xxxx") or die("Could not connect"); ///print "Connected successfully<BR>"; mysql_select_db("xxxx") or die("Could not select database"); { $Author = $_POST['Author']; $sql = "SELECT * FROM posters WHERE Author LIKE '%$Author%'"; } { $Title = $_POST['Title']; $sql = "SELECT * FROM posters WHERE Title LIKE '%$Title%'"; } { $Originaltitle =$_POST['Originalitle']; $sql="SELECT * FROM posters WHERE Originaltitle LIKE '%$Originaltitle%'"; } { $Country =$_POST['Country']; $sql="SELECT * FROM posters WHERE Country LIKE '%$Country%'"; } $result = mysql_query ($sql) or die("Query failed : " . mysql_error()); $numrs = mysql_num_rows($result); if ($numrs > 0){ if ($numrs==1){ print ("<p><font face=\"Arial\"><b>There is $numrs record in our database.</B> <BR><BR>"); }elseif($numrs>1){ print ("<p><font face=\"Arial\"><b>There are $numrs records in our database. </B><BR><BR>");//Apparently, he wan't to be able to search again...</b><form method \"POST\" action=\"$PHP_SELF\">Search Again:"); } echo("<a href='javascript:history.go(-1)'>Go Back</a></p>"); print("<P align=center>Click on the column heading links to sort the results.<br><br />"); print ("<TABLE CELLPADDING=\"1\" CELLSPACING=\"2\" BORDER=\"0\">\n"); PRINT ("<TR BGCOLOR=\"#FFFF77\"> <TD COLSPAN=2><P align=center>Author</td> <TD><P align=center>Title</TD> <TD><P align=center>Original Title</TD> <TD><P align=center>Country</TD> <TD><P align=center>Director</TD> <TD><P align=center>Cast</TD> <TD><P align=center>Year</TD> <TD><P align=center>Original Year</TD> <TD><P align=center>Photo</TD> <TD><P align=center>Producer</TD> <TD><P align=center>Circulation</TD> <TD><P align=center>Size</TD> <TD><P align=center>Print type</TD> <TD><P align=center>Remarks</TD></TR>"); $z=1; while ($line = mysql_fetch_array($result)) { $num=$z++; //Note here that I'm assigning the found objects new names (indicated by lowercase) to that php wont get confused..... $auth=$line['Author']; $title=$line['Title']; $originaltitle=$line['Originaltitle']; $country=$line['Country']; $director=$line['Director']; $cast=$line['Cast']; $year=$line['Year']; $originalyear=$line['Originalyear']; $producer=$line['Producer']; $circ=$line['Circulation']; $size=$line['Size']; $print=$line['Print']; $remarks=$line['Remarks']; $pict=$line['Picture']; //Set the formatting $bgcolor = ($i++ & 1) ? '#d3d3d3' : '#c0c0c0'; PRINT("<TR BGCOLOR=$bgcolor> <TD>$num.</TD> <TD>$auth</td> <TD>$title</TD> <TD>$originaltitle</TD> <TD><P align=center>$country</TD> <TD>$director</TD> <TD>$cast</TD> <TD><P align=center>$year</TD> <TD><P align=center>$originalyear</TD><TD>"); // This is the test to find do we have a picture if ($pict) { // If there is a picture, display it: print ("<P align=center><a href='zdjecie.php?zdj= $pict&autor=$auth&opis=$title&orig=$originaltitle&rok=$year' target='_blank'> <img src=$pict height=\"150\"></a>"); } else { // We don't have a picture, so we print some text instead: print ("<P align=center>no picture available"); } print ("</TD><TD>$producer</TD> <TD><P align=center>$circ</TD> <TD>$size</TD> <TD>$print</TD> <TD>$remarks</TD></TR>"); } PRINT("</TABLE><BR><font face=\"Arial\"><a href=\"javascript:history.go(-1);\">Search Again</a></font>"); }else { print ("<font face=\"Arial\">Sorry, there were no results for your search. <a href=\"javascript:history.go(-1);\">Please try again</a></font>"); } //mysql_close($link); ?> </body> </html> Similar TutorialsNeed some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! Hello, I had 8 select boxes(dropdowns) in a form. Its like a search kind of implementation in the website. I don't know what the user selects, he may choose different select boxes, any number of select boxes. So, based upon the user selection, I need to generate the data. The data fields to be generated would be almost same. So, How would I know what the user selection is and how many select boxes has been selected and how could I generate different data based upon selected boxes. I had to make a small note abt this, that the data generation fields may change for some of the user select combinations, but most of the result fields would be same. so, can you please help me out, how to do, how to make different combination data generations, because, i had 8 fields, i had to make 8! combinations, that would result in a big code. Hello everyone, Very new to coding - enjoying it but struggling! I think I'm trying to do something pretty common but I seem to have come up against a complete wall now and after hours/days searching the internet and reading books I'm completely stuck! I'm trying to write some code to search a MySQL database of products, then display the results. For some search results there will be lots of products so I want to display 10 products on the first page then allow visitors to go to the next page to see another 10, and so on - a type of pagination, as they should then be able to click back to see the last page etc. I've got to the point of being able to display the first 10 search results, but I can't figure out at all how to create some kind of page scrolling/pagination system. Please, does anybody have any ideas?? I've attached my code, I hope this is the correct way of doing things here. Many thanks for your time! The PHP search code... Code: [Select] <?php //opens connection to mysql server $dbc = mysql_connect('localhost'); if (!$dbc) { die('Not connected :' . mysql_error()); } echo "Connected to mysql database<br />"; //select database $db_selected = mysql_select_db("NAME_OF_DATABASE", $dbc); if (!$db_selected) { die ("Cannot connect :" . mysql_error()); } echo "Connected to database<br /><hr />"; echo "Here are your results"; $term = $_POST['term']; $category = $_POST['category']; $brand = $_POST['brand_name']; $sql = mysql_query("SELECT * FROM products where product_name like '%$term%' AND category_name like '%$category%' AND brand_name like '%$brand%' LIMIT 0, 10"); { while ($row = mysql_fetch_array($sql)){ echo "<table border='1' width='100%'> "; echo "<tr>"; echo "<td style='vertical-align:top' width='25%'>" . '<img src="', $row['image_url'], '" alt="', $row['product_name'], '" width="100" height="100" />' . "</td>"; echo "<td style='vertical-align:top' width='50%'>" . $row['product_name']; echo "<br />"; echo "<span style='font-size: 10px'>" . $row['description'] . "</span>" . "</td>"; echo "<td style='vertical-align:top' width='25%'>" . $row['price']; echo "<br />"; echo "<br />"; echo "<hr />"; echo "$row['merchant_name'] </td>"; echo "</tr>"; } echo "</table>"; } ?> Hi all How do I modify the below code to search multiple tables in mySQL database? $query = "select * from store_items where description like \"%$trimmed%\" or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); It is for a search function and I need it to search another table called 'about_text' and 'faq_text' Thanks Pete Hello folks, I've got a problem with a search script. It's searching a db containing various properties (as in buildings) and it's not quite returning the correct results. The search form asks that you select a house type (4 options, all of which are tick boxes) and then the last part of the form is select how many bedrooms you'd like (which is a drop-down list featuring numbers 2-5) What should happen is someone selects one or more of the tick boxes and then the number of bedrooms and it returns all the house types that were ticked but only those with the number of bedrooms that were specified in the original search. Currently the results are correct in that they're showing the correct house types, but the number of bedrooms isn't right. e.g. if you chose 2 bedrooms in the search it shows those, as well as 3, 4 and 5 bedrooms in the results. Can't figure it out but it will be something to do with && and OR in my search script. Can anyone suggest a tweak to this that might work? (I'm using the $_GET function because the search form is in a Flash movie) $Result = mysql_query("select * from property_names where TownHouse = '$_GET[TownHouse]' OR Apartment = '$_GET[Apartment]' OR Detached = '$_GET[Detached]' OR SemiDetached = '$_GET[SemiDetached]' && visible= 'Yes' && bedrooms = '$_GET[Bedrooms]' && bedrooms = '$_GET[Bedrooms]'") Hello. I hope someone out there can help me with this as I have been trying all different ways to make this work but to no avail. I have a report.php page that allows a user to search 3 particular fields in a database to retrieve search results that displays itself on the same page. What I am looking to do is have both an EDIT and DELETE button/link for each queried result that is retrieved allowing the user to edit or delete the search result of their choice. Or, how to implement some inline editing on the results that are retrieved by the search query. Here is the code I have so far with the EDIT or DELETE options feature that I am wanting to utilize. Code: [Select] <!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=utf-8" /> <title>Budgets Report</title> </head> <body class="oneColFixCtr"> <div id="container"> <h2>Budget Report</h2> <form name="search" method="post" style="background-color:#FFF" action="<?php $PHP_SELF?>"> <span id="search">Search for</span>: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="rundate">rundate</option> <Option VALUE="section">section</option> <Option VALUE="reporter">reporter</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <?php // check to see if anything is posted if (isset($_POST['find'])) {$find = $_POST['find'];} if (isset($_POST['searching'])) {$searching = $_POST['searching'];} if (isset($_POST['field'])) {$field = $_POST['field'];} //This is only displayed if they have submitted the form if (isset($searching) && $searching=="yes") { echo "<h2>Results</h2><p>"; // If they did not enter a search term we give them an error if (empty($find)) { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("budgets") 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 daily_budget WHERE upper($field) LIKE'%$find%' ORDER BY section ASC"); // And we display the results while($result = mysql_fetch_array( $data )) { echo "<strong>Section:$nbsp</strong>"; echo " ";echo $result['section']; echo "<br>"; echo $result['slug']; echo " "; echo ":"; echo " "; echo $result['budgetInfo']; echo " "; echo "/"; echo " "; echo $result['reporter']; echo " "; echo $result['notes']; echo " "; echo $result['art_photos']; echo " "; echo $result['artDesc']; echo " "; echo $result['multimedia']; echo " "; echo $result['multimediaDesc']; echo "<br>"; echo "Pickup"; echo " "; echo ":"; echo " "; echo $result['pickup']; echo "<br>"; echo "Sidebar"; echo " "; echo ":"; echo " "; echo $result['sidebar']; echo "<br> "; echo $result['sSlug']; echo " "; echo $result['sBudget']; echo " "; echo $result['sArt']; echo " "; echo "EDIT"; echo " "; echo "| "; echo " ";echo "DELETE"; echo " "; echo "<br>"; echo "<hr>"; } //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; } ?> </div> </div> </body> </html> Say a user puts in a support request, and for every request it generates a unqiue string, and enters it into the database. Ok, now say there is a text field, when the user enters their unique string and it finds a match, it displays the data along with it. How can I accomplish this? Im kind of new to mysql, but I know basic SQL. Would be great if somebody could point me in the right direction! Thanks Ok, so I have a bit of code but it's not working as it should, would one of you guys have a look at it and let me know where I'm going wrong? Basically I need to be able to input several words or terms into the text area, each on a separate line and have the results displayed something like: hello: 23,000.000 hello world: 19,000,000 world: 278,000,000 I also see that the script is not searching the words / terms inside quotes (EG. "hello world") TIA Code: [Select] <html> <body> <?php function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)') { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); $result = curl_exec ($ch); curl_close ($ch); return $result; } $s = $_GET['s']; if (isset($s)) { echo "<p><i>Search for $s</i></p>"; $s = urlencode($s); $data = my_fetch("http://www.google.com/search?hl=en&q=" . $s . "&btnG=Google+Search"); $data = strip_tags($data); $find = 'Results 1 - 10 of about '; $find2 = ' for'; $data = strstr($data, $find); $pos = strpos($data, $find2); $search_number=substr($data,strlen($find), $pos-strlen($find)); echo "Total Results: $search_number"; } else { ?> <form name="form1" id="form1" method="get" action=""> <div align="left"> <p> <textarea name="s" type="text" id="s" rows="8" style="width:60%" /></textarea><br /> <input type="submit" name="Submit" value="Results" /></p> Put "" around the string: <input type="checkbox" checked name="apos" value="true" /><br /> </div> </form> <p> <?php } ?> </p> </body> </html> Hi Everyone, Well I have a bit of a problem... I have created a search page that I would like to return results from my MySQL database. However for some reason I can not get my page to display the results. Instead I am getting an error page. Below is the code I am using: In addition to this, should I wish for a user to be able to edit the returned results by clicking a link, how would I do that? <?php session_start(); ?> <link rel="stylesheet" type="text/css" href="css/layout.css"/> <html> <?php $record = $_POST['record']; echo "<p>Search results for: $record<br><BR>"; $host = "localhost"; $login_name = "root"; $password = "P@ssword"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("schedules_2010") or die("Could not find database"); $result = mysql_query("SELECT * FROM schedule_september_2010 WHERE champ LIKE '%$record%' ") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row echo "<br><p>Your Schedule<BR></p><br>"; echo "<table border=1>\n"; echo "<tr> <td bgcolor=#444444 align=center><p><b>Champ</p></td> <td bgcolor=#444444 align=center><p><b>Date</p></td> <td bgcolor=#444444 align=center><p><b>Start Time</p></td> <td bgcolor=#444444 align=center><p><b>End Time</p></td> <td bgcolor=#444444 align=center><p><b>Department</p></td> <td bgcolor=#444444 align=center><p><b>First Break</p></td> <td bgcolor=#444444 align=center><p><b>Second Break</p></td> <td bgcolor=#444444 align=center><p><b>Login ID</p></td> </tr>\n"; do { printf("<tr> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> </tr>\n" , $row["champ"] , $row["date_time"] , $row["start_time"] , $row["end_time"] , $row["department"] , $row["first_break"] , $row["second_break"] , $row["login_id"] ); } while ($row = mysql_fetch_array($result)); echo "</table>\n"; } else { echo "$champ No Records Found"; } mysql_free_result($result); mysql_close($con); ?> </html> Hi guys,
What I'm trying to accomplish sounds like fairly easy task but due to my poor knowledge of php this turned to be quite a challenge.
What I'm trying to do is to make a php script that will search the keywords on the multiple websites.
Websites that I will search are all web shops, selling spare part for home appliances and keywords used are usually original spare part codes.
When searching, script is searching these websites using their own search functions and not Google or other search engines.
Input for this script should be a CSV file containing list of keywords and URLs of the web shops that needs to be search for all these keywords. Here is the example: http://prntscr.com/4ebhxh Script should perform like this: It picks up the 1st keyword, browse to the URL1, uses its search, searches for the product, if it finds it, copy its price and write it back to original input CSV. If it doesn't find match (search results appear empty) it should write "no match found" and continue to URL2, URL3 and so on... When all URLs from the list are checked for the 1st keyword, scripts picks up 2nd keyword and continues on through all these keywords are not checked. This would be a resulting CSV file after the 1st keyword is checked: http://prntscr.com/4ebj52 After all data from the input CSV file are processed, script should prompt a msg and create a download link for that CSV file to be downloaded. If there are multiple matches, in other words if for one keyword some of the website searches find 2 or more products, something like "More then one match" should be written in the file. Example: http://prntscr.com/4ebkcx Please note that non of the website is using SSL and non of them requires login in order to display the prizes. This fact should make this script easier to build. Its not important for this script to run fast (its better I think to run it with some timeouts because of the server glitches and bottlenecks). What is more important is to make it automatic so one can start it over the night, over the weekends. Number of the URLs would be around 10, and list of keywords from few tens, to a few hundred. If I can provide some additional clarification and info I'm available. Of course I would be willing to pay someone to help me accomplish this task. Cheers Dean Edited by dolke022, 19 August 2014 - 07:54 AM. Hi, So I'm trying to make a car rental project, and I need to show cars of a specific type, available in a specific period. I'm currently using this query: SELECT * FROM car, reservations WHERE car.car_id = reservations.car AND car.type = 1 AND reservations.reserved_from >= "2011-12-22" AND reservations.reserved_to <= "2012-12-20"; So this returns all the cars of the type 1 reserved in 2011-12-22 - 2012-12-20 period. So know that I know which cars are unavailable, how would you go ahead and pick out what's left? Im having problems with this code in my search button script. I get the following error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource Here's the code I use on my search form. Code: [Select] <form method="post" action="srch_all.php"><input type=text name='search' size=15 maxlength=255><br><input type=submit></form> and here's the code I'm using to perform the search query: Code: [Select] if ($search) // perform search only if a string was entered. { mysql_connect($host, $user, $pass) or die ("Problem connecting to Database"); $srch="%".mysql_real_escape_string($search)."%"; $query = "select * from database WHERE column1 LIKE '$srch' or column2 LIKE '$srch' or column3 LIKE '$srch' or column4 LIKE '$srch' ORDER BY column1, column2 DESC, column3 ASC"; $result = mysql_db_query("database_name", $query); if(mysql_num_rows($result)==0) { print "<h2>Your search returned 0 Results</h2>"; } else if ($result) { <restult data stuff here>.. Cheers I have a search set up to search a table for the text entered in a textbox, I have two columns in the table, one with the first name of people, and the second with their last names, I am wondering how I can search both, so for instance: I type in the search field: Roger Smith in the database it would look like: First_name-----|-----Last_name -------------------|------------------- Roger------------|-------Smith my current query is: Code: [Select] $query = mysql_query("SELECT * FROM users WHERE fname LIKE '%$find%' OR lname LIKE '%$find%'"); But if I type both parts of the name it doesn't return anything. works fine if I just search for "Roger" OR "Smith". Not sure if this topic goes in here, it is related to PHP but also MySql, so if i'm on the wrong board sorry! What i'm trying to do is search for a keyword in 5 different tables and return the keyword ID from the table that its in The tables i'm trying to search are as follow location state county region continent The "location" table has all the locations i.e cities and each row has the following columns: id | continent_id | country_id | state_id | region_id | city_name The "state" table is set the the following: id | name "county" table : id | name "region" table: id | region and "continent" table id | name The way it works is the can search for any city or state or county or region or continent and ideally it should look into the five different tables and return the id of that table. So if the use searches for United States it will look for United States in all five tables, obviously it would find it in the "country" table so it should return that "id". The results are returned in "json format" Below is the code i have: Code: [Select] <? $input = $_GET['keyword']; $data = array(); /* In this query i'm attempting to search in all databases, but i'm not sure if i'm doing this right. I'm not getting any results so i know something is wrong just don't know how to write it. */ $query = mysql_query("SELECT * FROM locations JOIN states ON states.id = locations.state_id JOIN countries ON countries.id=locations.country_id JOIN regions ON regions.region_id = locations.region_id JOIN continents ON continents.id=locations.continent_id WHERE name LIKE '$input%' OR state LIKE '$input%' OR region LIKE '$input%' OR country LIKE '$input%' OR continent LIKE '$input%'") or die(mysql_error()); /* Here the values are added to to the $json array. The "value" should be the "id" from the table that the keyword matched. The 'name' Should be the name of the actual keyword. Again if they search for United States the "id" will come from the "countries" table and the "value" would come from the "countries" table as the name */ while ($row = mysql_fetch_assoc($query)) { $json = array(); $json['value'] = $row['id']; $json['name'] = $row['name']; $data[] = $json; } header("Content-type: application/json"); echo json_encode($data); ?> Any help would he be appreciated, i don't want people to do it for me, but rather just guide me a little bit. I have a multiple choice search page which asks visitors to select one or more choices before rendering the search results. It only works in items 1+2 are selected, or 1+2+3, or 1+2+3+4, or 1+2+3+4, etc... I want to make it so that any combination of choices work. Example: Items 1+6 or 2+3+5 or 1+4+6 etc... I have four hours to fix it before my client shows up and need help BADLY. Anyone out there who can help? Whoever can help me... you are the best and I will have a special prayer for you tonight. Here is the coding: <?php } else{ if(!empty($_GET['latt']) && !empty($_GET['long'])) { $condition="SELECT ( 3959 * acos( cos( radians( '".$_GET['latt']."' ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( '".$_GET['long']."' ) ) + sin( radians( '".$_GET['latt']."' ) ) * sin( radians( latitude ) ) ) ) as distance,id,membership FROM notary_members "; if(!empty($_GET['s'])) { $a=" where and"; } else { $a=" where"; } if($_GET['edoc']!='') { $condition.=$a." edoc= 'yes'"; } if($_GET['esign']!='') { if($_GET['edoc']!='') $condition.=" and esign= 'yes'"; else $condition.=$a." esign= 'yes'"; } if($_GET['laserprinter']!='') { if($_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and laserprinter= 'yes'"; else $condition.=" laserprinter= 'yes'"; } if($_GET['dualtray']!='') { if( $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and dualtray= 'yes'"; else $condition.=" dualtray= 'yes'"; } if($_GET['error_in']!='') { if($_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and error_in= 'yes'"; else $condition.=" error_in= 'yes'"; } if($_GET['bg_checked']!='') { if($_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and bg_checked= 'yes'"; else $condition.=" bg_checked= 'yes'"; } if($_GET['home_insp']!='') { if($_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and home_insp= 'yes'"; else $condition.=" home_insp= 'yes'"; } if($_GET['fingerprint']!='') { if($_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and fingerprint= 'yes'"; else $condition.=" fingerprint= 'yes'"; } if($_GET['hosp_signing']!='') { if($_GET['fingerprint']!='' || $_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and hosp_signing= 'yes'"; else $condition.=" hosp_signing= 'yes'"; } if($_GET['jail_signing']!='') { if($_GET['hosp_signing']!='' || $_GET['fingerprint']!='' || $_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and jail_signing= 'yes'"; else $condition.=" jail_signing= 'yes'"; } if($_GET['im_docs']!='') { if($_GET['jail_signing']!='' || $_GET['hosp_signing']!='' || $_GET['fingerprint']!='' || $_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and im_docs= 'yes'"; else $condition.=" im_docs= 'yes'"; } if($_GET['jail_signing']!='' || $_GET['hosp_signing']!='' || $_GET['fingerprint']!='' || $_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='' || $_GET['im_docs']!='') { $condition.=" and status=1 order by distance asc"; } else { $condition.=$a." status=1 order by distance asc"; } $sql=mysql_query($condition); $num=mysql_num_rows($sql); $getmile=explode(' ',$_GET['miles']); $c=0; while($getidres=mysql_fetch_array($sql)) { if($getidres['distance']<=$getmile[0]) { if($getidres['membership']=='premium') { $prefirst[$getidres['id']]=$getidres['distance']; $c++; } else { $basicfirst[$getidres['id']]=$getidres['distance']; $c++; } } } if(!empty($sql)) { if($c!=0) { if(!empty($prefirst) || !empty($basicfirst)) { ?> I want to have a search product feature, but I would like members to be able to search multiple fields in one go i.e. product_code, Product_name in one MySQL query. The thing is, members have to be logged on, so the query must also only show results relating to that specific member, via the session[member_ID], my current query for listing products for that specific member is : Code: [Select] $sql = "SELECT productId, productCode, image, name, price, stock_level FROM product_inventory WHERE memberr_ID = '" . $_SESSION['SESS_mem_ID'] . "; How would I change the above into a search query to search for productcode, productname and still only show results beloging to this member using the session data ? all help appreciated I need some advice on how to implement, if possible, the following scenario: I would like start a MySQL transaction to process database changes through Ajax requests and commit the changes on request of the user. The web application needs to allow multiple users, but can be limited. If persistent connections must be used, any persistent connections must be terminated after a length of time, or on session time to avoid hogging the limited number of persistent users available. Is there any good way of doing this? And were should I begin my research. Much thanks! Hello, I'm developing a website that asks the user to submit a keyword for a search. The results should display matches for this keyword, but also show matches for related keywords (in order of relevenace!). I'm planning on building up a library of which search terms users use in the same sessions (e.g. if someone searches for "it jobs" and "php jobs", I'll know the terms are correlated), and I'll also measure the click-through rates of the items on the results list. I've been spending all weekend trying to map out the design for this but it's proving incredibly complicated and I think the solution is likely to be on the internet somewhere already?! Please could someone point me in the right direction if you've come accross this problem before? Thanks a million, Stu I am pretty new to using php and mysql and am struggling to understand how to go about processing a multiple choice quiz script to check if the answer given by the user is right or wrong and give the user the final result . I understand how to write and process register pages and login scripts and the like but for some reason I just can't understand what i need to do for this type of script So far my thinking has been 1) When the page is submitted have a query that compares the answer selected to the answer in the database. 2) Have php variables for correct and and incorrect both initialised to 0 and which will change depending on the answers given. 3) Use an if else statement similar to the code below to add up the score : - if($result['answer']==$_POST[$result['id']]){ $correct_answer++; }else{ $incorrect_answer++; } 4) Have a query that enters the person taking the quiz's grade in to the database. I would really appreciate it someone could give me some guidance for the best way to do this. I have included below my code for selecting the questions form the database. <?php // Starts the session session_start(); /* */ if (!isset($_SESSION['user_level']) or ($_SESSION['user_level'] != 0)) { header("Location: error_page.php"); exit(); } ?> <?php require_once ('mysqli_connect.php'); $email_address = ['email_address']; $quizGradeBegan=("INSERT INTO learner_grade_db( email_address, score, )VALUES ('$email_address',0) "); $result=@mysqli_query($dbcon, $submittedAnswerQuery); if(isset($_SESSION['email_address'])){ ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Q-Quiz: Learner Homepage</title> <link rel="stylesheet" href="sdnt.css" /> </head> <body> <div class="wrapper"> <!-- Start of wrapper div --> <div class="header"> <!-- Start of header div --> <h1>e-Quiz: <br> Learner Homepage</h1> <?php //Makes a call to includes/leaner_nav.php in order to show The Learner Navigation Bar require_once("includes/learner_nav.php"); //Makes a call to includes/welcome_name.php in order to show the Learners name. require_once("includes/welcome_name.php"); /*Makes a call to includes/current_date in order to shows the current date. Will appear in the Day Month Year Format.*/ require_once("includes/current_date.php"); ?> <!-- Shows the Change text size images --> <div id="textSizer"><!-- Start of the textSizer div --> <img id="smallStyler" class="textSize" src="imgs/fontSmall.jpg" height="18" width="18" alt="Smallest" /> <img id="mediumStyler" class="textSize" src="imgs/fontMedium.jpg" height="18" width="18" alt="Default" /> <img id="largeStyler" class="textSize" src="imgs/fontLarge.jpg" height="18" width="18" alt="Biggest" /> </div> <!-- End of textsizer div --> </div><!-- End of Header div --> <div class="article"> <!-- Start of the article div --> <?php $query=("SELECT question_id, question, distractor_1, distractor_2, distractor_3, distractor_4 FROM multiplechoice_db ORDER BY RAND() LIMIT 3 " ); $result = @mysqli_query ($dbcon, $query); // Run the query. while($row = mysqli_fetch_array($result, MYSQL_BOTH)):?> <br> <form action="gradepage.php" method="post"> <?php echo $row['question_id'];?> <br> <?php echo $row['question'];?> <br> <input type="radio" value="1" id=' distractor <?php echo $row['question_id'];?>' name ='<?php echo $row['question_id'];?>'/><?php echo $row['distractor_1'];?> <br> <input type="radio" value="2" id=' distractor <?php echo $row['question_id'];?>' name ='<?php echo $row['question_id'];?>'/><?php echo $row['distractor_2'];?> <br> <input type="radio" value="3" id=' distractor <?php echo $row['question_id'];?>' name ='<?php echo $row['question_id'];?>'/><?php echo $row['distractor_3'];?> <br> <input type="radio" value="4" id=' distractor <?php echo $row['question_id'];?>' name ='<?php echo $row['question_id'];?>'/><?php echo $row['distractor_4'];?> <br> <?php endwhile;?> <p> <input id="submit" type="submit" name="submit" value="Click To Submit Completed Quiz "></> </div> <!-- End of the article div --> <div class="aside"> <!-- Start of the aside div --> <ul class="nav2"> <?php //Makes a call to includes/leanersidebar1.php in order to show The Learner Sidebar require_once("includes/learnersidebar1.php"); ?> </ul> <br><br><br><br><br> </div> <!-- End of the aside div --> <div class="footer "><!-- Start of the footer div --> <?php //Makes a call to includes/footer.php in order to show the Footer require_once("includes/footer.php"); ?> </div><!-- End of the footer div --> </div><!-- End of the wrapper div --> </body> <html> |