PHP - Use Results From Mysql Search To Search Another Mysql Database Can It Be Done?
Need 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! Similar TutorialsSay 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 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> 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> Hello, so i made table with Tags row which is Text(126).. and idea is to put text like "PHP, MySQL, Forum, Blog" etc etc...
I have problem searching tags my search code:
$requestedtag = $con->real_escape_string($_GET['tag']); $sql = "SELECT * FROM images WHERE tags = '$requestedtag' ORDER BY ID DESC LIMIT 12"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $image_id = $row["ID"]; $image_title = $row["Title"]; $image_url = $row["ImgURL"]; $image_tags = $row["Tags"]; echo '<div class="col-3"><div class="thumb"><a href="/image.php?id='.$image_id.'" title="'.$image_title.'"><img src="'.$image_url.'"></img></a></div></div>'; } } But it doesnt return anything. I think the problem is that row["Tags"]; is divided by "," from tags and i should split it somehow but i dont really know what to do... I'm using some code to create a select menu of a fieldname of data I have in a mysql database : Code: [Select] <?php mysql_connect('localhost' , 'dbname', 'password'); mysql_select_db('dbname'); $result=mysql_query("SELECT * FROM Persons"); if(mysql_num_rows($result)>0) { ?> <select name="Persons"> <?php while($rows=mysql_fetch_array($result)){ ?> <option value="<?php echo $rows['id']; ?>"> <?php echo $rows['FirstName']; ?></option> <?php } ?> </select> What I would like to do is to elevate this into a jump menu form so that if the user selects an item from my form they are taken to a results page showing the full row of data from the database. Basically a search form containing items from the database they can choose to see more details on. eg. In my example you select a persons name and then you are taken to a results page which displays the details of that person from the database. Problem is I don't know how to do this and have been trawling around for a couple of days to find a solution (sorry I'm new to php). I would appreciate some help or a working example would be great of : 1/ A working dynamic jump menu 2/ The page that would process the form 3/ The results page displaying the data I have selected. Thank you for your time... Hi, I'm am trying to use a search engine that search's for a username in the database and displays the information back. I have searched for a script but none of them has helped me. I have tried to use this without any luck: mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("dbsystem") or die(mysql_error()); $todo=$_POST['todo']; if(isset($todo) and $todo=="search"){ $search_text=$_POST['search_text']; $type=$_POST['type']; $search_text=ltrim($search_text); $search_text=rtrim($search_text); if($type<>"any"){ $query="select * from users where name = '$search_text'"; }else{ $kt=split(" ",$search_text);//Breaking the string to array of words // Now let us generate the sql while(list($key,$val)=each($kt)){ if($val<>" " and strlen($val) > 0){$q .= " name like '%$val%' or ";} }// end of while $q=substr($q,0,(strlen($q)-3)); // this will remove the last or from the string. $query="select * from users where $q "; } // end of if else based on type value echo $query; echo "<br><br>"; $nt=mysql_query($query); echo mysql_error(); while($row=mysql_fetch_array($nt)){ echo "$row[name]<br>"; } // End if form submitted }else{ echo "<form method='post' action=''><input type='hidden' name='todo' value='search' /> <input type='text' name='search_text' /><input type='submit' value='Search' /><br> <input type='radio' name='type' value='any' checked />Match any where <input type='radio' name='type' value='exact' />Exact Match </form> "; } I will be grateful if you can help with this. Hi. I have a database named 'Forums' with a table named 'forumlist'. The fields in the table are 'id', 'name', 'link', and 'keys'. I am trying to search the database in either the 'name' or 'keys' field and display the matches. I am getting this error: Parse error: syntax error, unexpected T_STRING, expecting ']' in C:\xampp\htdocs\search3.php on line 51 (The define fields) <html> <head> <title>My Forum Search</title> <style type="text/css"> table { background-color: #CCC } th { width: 150px; text-align: left; } </style> </head> <body> <h1>Forum Search</h1> <form method="post" action="search3.php"> <input type="hidden" name="submitted" value="true" /> <label>Search Category: <select name="category"> <option value="keys">Keyword</option> <option value="name">Name</option> </select> </label> <label><input type="text" name="criteria" /></label> <input type="submit" /> </form> <?php if (isset($_POST['submitted])) { DEFINE ('DB_USER', 'root'); DEFINE ('DB_PSWD', '******'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'Forums'); $dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME); $category = $_POST['category']; $criteria = $_POST['criteria']; $query = "SELECT * FROM forumlist WHERE $category LIKE '$criteria'"; $result = mysqli_query($dbcon, $query) or die ('Error retrieving data') echo "<table>"; echo "<tr> <th>Name</th><th>Link</th> </tr>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['link']; echo "</td></tr>"; } echo "</table>"; } // end of main if state ?> </body> </html> Thanks in advance 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". The result pages is supposed to have pagination like google help me please
This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=326703.0 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, 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 developing a intranet forum in Php and MySQL and I am using ajax to display searched results on the same page but right now I am using query LIKE text% to search in database which is slower. but I want to make it fast search engin which can parse *,+ and show result. Since I am using ajax i am not able to use free search engin,so if possible pls provide a complete solution I have code to search a database of members, I can search by lastname but having a little problem. I want to be able to search by lastname starting with the first letter. (ie: a or b or c or d and so on). As it is right now I can only search by first letter of last name if I add % to the search (ie: a% b% c%) will give me all members with the last names starting with the approiate letter designation. I'm not sure how to handle this, any help would be appreciated. Thanks. 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></title> </head> <body> <center><table cellspacing="10" cellpadding="10" width="750" border="0"> <h4>Search</h4> <form name="search" method="post" action="<?php $PHP_SELF?>"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="lname">Last Name</option> <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 "<h4>Results</h4><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", "1910") or die(mysql_error()); mysql_select_db("cmc_member") 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 $results = mysql_query("SELECT * FROM members WHERE upper($field) LIKE'$find'"); // And we display the results if($results && mysql_num_rows($results) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($results)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product ALIGN='CENTER' if($fname != "" && $fname != null) echo "<td ALIGN='CENTER'><FONT COLOR='red'><b>$fname $lname</b></FONT><br> $address <br> $city $state $zip <br>$phone<br><a href=\"mailto: $email\">$email</a><br></td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches = mysql_num_rows($results); 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></center> </body> </html> I found an article on how to implement a mysql search (http://www.iamcal.com/publish/articles/php/search/) and it seemed like a good way to go, but I can't get it up and running. Here is my code: Code: [Select] <?php $db_host = 'localhost'; $db_user = 'username'; $db_pwd = 'password'; $database = 'dbname'; $table = 'Principals'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $searchterms = 'dorr oliver'; function search_split_terms($terms){ $terms = preg_replace("/\"(.*?)\"/e", "search_transform_term('\$1')", $terms); $terms = preg_split("/\s+|,/", $terms); $out = array(); foreach($terms as $term){ $term = preg_replace("/\{WHITESPACE-([0-9]+)\}/e", "chr(\$1)", $term); $term = preg_replace("/\{COMMA\}/", ",", $term); $out[] = $term; } return $out; } function search_transform_term($term){ $term = preg_replace("/(\s)/e", "'{WHITESPACE-'.ord('\$1').'}'", $term); $term = preg_replace("/,/", "{COMMA}", $term); return $term; } function search_escape_rlike($string){ return preg_replace("/([.\[\]*^\$])/", '\\\$1', $string); } function search_db_escape_terms($terms){ $out = array(); foreach($terms as $term){ $out[] = '[[:<:]]'.AddSlashes(search_escape_rlike($term)).'[[:>:]]'; } return $out; } function search_perform($terms){ $terms = search_split_terms($terms); $terms_db = search_db_escape_terms($terms); $terms_rx = search_rx_escape_terms($terms); $parts = array(); foreach($terms_db as $term_db){ $parts[] = "Principals RLIKE '$term_db'"; } $parts = implode(' OR ', $parts); $sql = "SELECT * FROM Principal WHERE $parts"; $rows = array(); $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $row[score] = 0; foreach($terms_rx as $term_rx){ $row[score] += preg_match_all("/$term_rx/i", $row[Principals], $null); } $rows[] = $row; } uasort($rows, 'search_sort_results'); return $rows; } function search_rx_escape_terms($terms){ $out = array(); foreach($terms as $term){ $out[] = '\b'.preg_quote($term, '/').'\b'; } return $out; } function search_sort_results($a, $b){ $ax = $a[score]; $bx = $b[score]; if ($ax == $bx){ return 0; } return ($ax > $bx) ? -1 : 1; } function search_html_escape_terms($terms){ $out = array(); foreach($terms as $term){ if (preg_match("/\s|,/", $term)){ $out[] = '"'.HtmlSpecialChars($term).'"'; }else{ $out[] = HtmlSpecialChars($term); } } return $out; } function search_pretty_terms($terms_html){ if (count($terms_html) == 1){ return array_pop($terms_html); } $last = array_pop($terms_html); return implode(', ', $terms_html)." and $last"; } # # do the search here... # $results = search_perform($searchterms); $term_list = search_pretty_terms(search_html_escape_terms(search_split_terms($searchterms))); The table name is 'Principals' and the field name I am trying to search is 'Principal'. I am getting an error on the line: while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ The error is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Can anyone shed some light on this for me? Hello friends,
I am a novice in php. Though I create 2 scripts:
1. students registration form
2. search students by Registration Number
Our students' Registration Numbers are as follows: nifeA001, nifeA002 & so on...
But when someone enter just "nife" or "n" or "A" etc all the students's data is showing.
I want that students can search data by entering only Full Registration Number not a Part.
I am placing the search.php code below. Please help me out....
----------------- Search.php ------------------
<?php
mysql_connect("localhost", "root", "") or die("could not connect");
mysql_select_db("student") or die("could not connect");
//collect
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
//here
$query = mysql_query("SELECT * FROM user WHERE registration LIKE '%$searchq%'") or die("could not search!");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'There was no search results!';
}else{
while($row = mysql_fetch_array($query)) {
$fname = $row['firstname'];
$lname = $row['surname'];
$id = $row['registration'];
$output .= '<div> '.$id.' '.$fname.' '.$lname.'</div>';
}
}
}
?>
<html>
<head>
</head>
<body>
<form action="form.php" method="post">
<input type="text" name="search" placeholder="search for students.."
<input type="submit" value=">>" />
</form>
<?php print("$output");?>
</body>
</html>
Edited by NasimUddinAhmmad, 13 January 2015 - 05:43 AM. Hello, I'm working on a site search which I've never done from scratch before and I've run into a couple road blocks along the way. The first problem is that in my search form it seems that there is no minimum amount of characters that can be searched. For example I enter no value into the text box and hit enter or click submit and all my database items are displayed. My second issue is simply with the criteria of the search. say I were to search for something like 48 x 12 I would get nothing when in fact there is an item in my database with those characters in the description however they are seperated in this fashion 48 in X 12 in. Lastly is the problem where when I search for results that should produce a message stating that my search returned no results instead I get my blank results table. I'm sure that there are some easy solution and minor tweaks that can be made to my code to rectify some or all of these issues and would appreciate those willing to help to share their knowledge with me. Here is my code: <?php require_once('Connections/price_db.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_Recordset1 = "-1"; if (isset($_GET['title'])) { $colname_Recordset1 = $_GET['title']; } mysql_select_db($database_price_db, $price_db); $query_Recordset1 = sprintf("SELECT * FROM price_db WHERE tb_name LIKE %s OR tb_desc LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"),GetSQLValueString("%" . $colname_Recordset1 . "%", "text")); $Recordset1 = mysql_query($query_Recordset1, $price_db) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> and the html is as follows: <div id="search_results"> <?php do { ?> <table width="208" border="0" align="left" style="margin-right:20px;"> <tr> <td width="220"><img width="175px" height="175px" src="<?php echo $row_Recordset1['tb_img']; ?>" /></td> </tr> <tr> <td height="45"><h2><?php echo $row_Recordset1['tb_name']; ?></h2> <div id="search_desc"><?php echo $row_Recordset1['tb_desc']; ?></div></td> </tr> <tr> <td height="37"><div id="search_price">$ <?php echo $row_Recordset1['tb_price']; ?> <form action="/save_to_cart.php" method="get" style="padding-top:15px;"> <input type="text" name="quantity" size="10" value="Quantity" style="margin-right:12px; color:#666" onfocus="this.value=''"/> <input type="button" name="Add" value="Select" onclick="this.form.submit()"/> </form> </div></td> </tr> </table> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </body> </html> <?php mysql_free_result($Recordset1); ?> Thanksagain for all help Hello I wonder if it is possible to make a search form with different fields where all conditions should be met if the field is set. I have this code: $sel = "SELECT * FROM database "; $sel .= "WHERE ((test1 = '$test1' "; $sel .= "AND test2 = '$test2' "; $sel .= "AND test3 = '$test3' "; $sel .= "ORDER BY id "; $query = mysql_query($sel) or die(mysql_error()); if (mysql_num_rows($query) == 0){ echo ("No result"); exit; When I use this and leave for example 1 field empty I get the error: No result. Is it possible to make smothing so the condition only should be met if the field is set? So If test1 and test3 are set these condition should be met.. I hope you can help! Thanks in advance! - Frederik I wonder whether someone may be able to help me please. I'm trying to put together php code and an html form that allows an administrator to search for a user via the email address, retrieving the 'first' and 'surname' from the pertinent record in a mySQL database. What I would like to happen is for the retrieved 'first' and surname' values to be automatically populated into the 'first' and 'surname' text boxes on the same search form. I can perform the search and retrieval of the correct record without any problem, but I can't work out how to populate the 'first' and 'surname' values into my search form. I am quote a novice with PHP so apologies if this is a really daft question, but I just windered whether somone could take a look at my code below and let me know where I've gone wrong? Many thanks PHP CODE Code: [Select] <?php require("phpfile.php"); // Opens a connection to a MySQL server $connection=mysql_connect ("hostname", $username, $password); if (!$connection) { die('Not connected : ' . mysql_error());} // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } $email = $_POST['email']; $result = mysql_query("SELECT * FROM userdetails WHERE emailaddress like '%$email%'"); while($row = mysql_fetch_array($result)) { echo $row['forename']; echo $row['surname']; echo "<br />"; } ?> HTML FORM Code: [Select] !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Maptitle> <script src="js/gen_validatorv4.js" type="text/javascript"></script> </head> <h1><span class="blue">Sign Up</span> For Map My Finds</h1> <form name="userpasswordreset" id="userpasswordreset" method="post" action="search.php"> <h2>Your Details </h2> </div> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="26%" height="25"><strong>Email Address</strong></td> <td width="4%"> </td> <td width="70%"><input name="email" type="email" id="email" size="50" /></td> </tr> <tr> <td height="25"><strong>Confirm Email</strong></td> <td> </td> <td><input name="conf_email" type="email" id="conf_email" size="50" /></td> </tr> <tr> <td height="25"><label> <input type="submit" name="Submit" value="Search" /> </label></td> <td> </td> <td> </td> </tr> <tr> <td height="25"><strong> First Name </strong></td> <td> </td> <td><input name="fname" type="text" id="fname" size="30" value="<?php echo $forename; ?>" /></td> </tr> <tr> <td height="25"><strong> Address Last Name </strong></td> <td> </td> <td><input name="lname" type="text" id="lname" size="30" value="<?php echo $surname; ?>" /></td> </tr> <tr> <td height="25"> </td> <td> </td> <td> </td> </tr> <tr> <td height="25"> </td> <td> </td> <td> </td> </tr> <tr> <td height="25"><strong>Password</strong></td> <td> </td> <td><input name="pass" type="password" id="pass" size="30" /></td> </tr> <tr> <td height="25"><strong>Confirm Password </strong></td> <td> </td> <td><input name="conf_pass" type="password" id="conf_pass" size="30" /></td> </tr> <tr> <td height="25"> </td> <td> </td> <td> </td> </tr> <tr> <td height="25"><strong>Password Hint </strong></td> <td> </td> <td><input name="hint" type="text" id="hint" size="30" /></td> </tr> <tr> <td height="25"> </td> <td> </td> <td> </td> </tr> <tr> <td height="25"> </td> <td> </td> <td> </td> </tr> </table> </form> <script language="JavaScript" type="text/javascript"> // Code for validating the form // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml // for details var frmvalidator = new Validator("userpasswordreset"); frmvalidator.addValidation("email","req","Please provide your email address"); frmvalidator.addValidation("email","email","Please enter a valid email address"); frmvalidator.addValidation("conf_email","eqelmnt=email", "The confirmed email address is not the same as the email address"); </body> </html> |