PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am very desperated, I have to finish a search engine for the university for this thursday morning.
I didnt sleep last night, trying to improve the search thing but I cant get any logic implementation.
I have to do a search with php and mysql using logic such as AND, NOT, OR but i am very frustated.
I cant get any help from anyone and I cant find examples in the net. If anyone can help me I could pay him by paypal.
I would like to get a text box, where I could type the name of a person or two names, and a following drop-down menu where the options on it would be: matches exactly or include. Then a buton that when I click on it goes to o the php and shows the results. The code of both pages would be very apreciated.
This is the code that I have but it is diferent from what I want to do. It is a drop down menu that get user details from a database. when selecting a user and then clicking on search it goes to another php that list the products that the user has in a table. But this is not what I want to do, I want a text box, where the user can type words, and then a drop-down menu, that asks the user to select if want to get results of any word or the exact word for example. when user click on search a list of results appears
?php
// script to display all the films in drop down menu
// connection information
$hostName = "localhost";
$userName = "root";
$password = "password";
$dbName = "dvdswap";
// make connection to database
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
mysql_select_db($dbName) or die( "Unable to select database $dbName");
$query = "SELECT DISTINCT product.userid
FROM product ORDER BY userid";
$result = mysql_query($query);
// Determine the number of results
$number = mysql_numrows($result);
// Create drop-down menu
print "<tr>
<td>View films of a selected owner:<p></td>
<td><form action=\"listFilmCriteria.php\" method=\"get\">
<select name=\"userid\">
<option value=\"\">Select owner</option>";
for ($i=0; $i<$number; $i++) {
$userid = mysql_result($result,$i,"userid");
print "<option value=\"$userid\">$userid </option>";
}
print "</select><input type=\"submit\" value=\"Search\"
name=\"submit\"></form></tr>";
// Close the database connection
mysql_close();
?>
------------------------------------------------------------------------------------------------------------
<?php
// script to display all the Computers in the Computers table
// connection information
$hostName = "localhost";
$userName = "root";
$password = "password";
$dbName = "dvdswap";
$userid = $_GET['userid'];
$genre = $_GET['genre'];
$director = $_GET['director'];
$pyear = $_GET['pyear'];
$cert = $_GET['cert'];
// make connection to database
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
mysql_select_db($dbName) or die( "Unable to select database $dbName");
$query ="SELECT * FROM product where userid='$userid' or genre='$genre' or director='$director' or pyear='$pyear' or cert='$cert' ORDER BY title";
$result = mysql_query($query);
// Determine the number of results returned
$number = mysql_numrows($result);
// Print the relevant information
if ($number == 0)
{
print "<h3>Sorry, there are no records matching your criteria:</h3>
<p><b>$number</b> films found.</p>
<p>You did not select a valid input. <br>Please try again.</br></p>
<p>Alternatively you could:
<ul>
<li>Conduct a quick search at the right of the page.</li>
<li>Conduct an advanced film search by clicking <a href='advancedSearchFilm.php'>here.</a></li>
<li>Browse all films by clicking <a href='browseAllProducts.php'>here.</a></li>
</ul>";
}
else
{
print "<h3>We have $number product(s) that match your criteria:</h3>
<table cellpadding=5 width='100%'>
<tr bgcolor=#6D6867>
<td align='center'><font color=white><b>Title</b></font></td>
<td align='center'><font color=white><b>Year</b></font></td>
<td align='center'><font color=white><b>Format</b></font></td>
<td align='center'><font color=white><b>Certificate</b></font></td>
<td align='center'><font color=white><b>Owner</b></font></td></tr>";
for($i=0; $i<$number; $i++) {
$prodid = mysql_result($result, $i, "prodid");
$title = mysql_result($result, $i, "title");
$pyear = mysql_result($result, $i, "pyear");
$format = mysql_result($result,$i,"format");
$cert = mysql_result($result,$i,"cert");
$userid = mysql_result($result,$i,"userid");
/* print even-numbered rows with a grey background,
odd-numbered with a white background */
if ($i%2 == 0) {
print "<tr bgcolor=lightgrey>";
} else {
print "<tr>";
}
print "<td><a href=\"prodinfo.php?prodid=$prodid\">$title</a></td>
<td align='center'>$pyear</td>
<td align='center'>$format</td>
<td align='center'>$cert</td>
<td><a href=\"userinfo.php?userid=$userid\">$userid</a></td></tr>";
// <td><input type='submit' value='Contact' size=5></td>
// <td><input type='submit' value='Swap' size=5></td>
}
print "</table>";
}
// Close the database connection
mysql_close();
?>
It firstly queries the DB for any entries that are similar to what was entered in a text box. It then generates a drop menu and puts all the results from the DB query into it. What else did you want it to do?
This is a university project? Can your professor give you some insight. I think when it comes to helping out students doing school work, I am a little reserved about giving out code (this is just my opinion).
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, this is the code that im working with, the php problems are when i use if in the queries, i dont know how to fix it, anyone can help me???
Thank you for your help, it is very appreciated
[syntax="html"]
</form>
<form name="searchProduct" method="post" action="try2.php">
Title:
<input type="text" name="title" size="18"> <br />
Format:
<select name="option">
<option value="exactly"> exactly </option>
<option value="starts"> starts </option>
<option value="includes"> includes </option>
</select> <br />
<input type="submit" value="Search" class="rightColButton"><br />
</p>
</form>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I use this:
$query = "SELECT product.prodid, product.title, product.pyear, product.format, product.cert, product.userid, product.director, product.starring
FROM product where ";
switch($_POST['optionfilm']) {
case 'exactlyfilm' :
$query .=" title = '$title' ";
break;
case 'startsfilm' :
$query .=" title like '$title%'";
break;
case 'includesfilm' :
$query .= " title like '%$title%'";
break;
}
I got working the code that you posted bofore as well but didnt save it sorry.
Thanks.
Now im trying to allow the users to type AND, OR, NOT in the search text box, if anyone can help me it would be great.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]