Hi guys i did a search and couldnt find what i needed. Im making a DB search form for a DB which holds names of items.
I've got the DB table I want to search from with around 6 columns (name, effects, stackable etc). I made a php page which displays ALL hits in a table easy enough with :
$result = mysql_query("SELECT * FROM items);
The problem is i'm trying to make it searchable from a search form which uses text boxes. I want whatever is entered into the text box to search the NAME column from the DB and display the results in the table instead of "*". So display names LIKE instead of all the hits.
I'm unsure of how to integrate the SUBMIT button into the query.
I tried this : (button code)
Button:
td width="100%" height="190"> <form name="search" method="post" action="dbitemstable.php">
<p align="left"><strong><font size="4">Search the Database: (Fill one text field and select an option from below and click submit)</font><br>
<br>
Name:</strong>
<input type="text" name="item" value="">
<br>
<br>....etc
And in another php file have the script which displays the hits :
<html>
<head>
<title>Search Results</title>
<head>
<body>
<table border="1" cellspacing="0" cellpadding="6" align="center"><tr>
<?php
$dbcnx = @mysql_connect("localhost", "user", "pass");
if (!$dbcnx) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
// Select the items database
if (! @mysql_select_db("fantasy") ) {
echo( "<p>Unable to locate the fantasy " .
"database at this time.</p>" );
exit();
}
?>
<p> Here are all the items you have selected </p>
<blockquote>
<tr>
<?php
$result = mysql_query("SELECT * FROM items WHERE name LIKE ". $_GET['item']);
echo "<tr><th>Item Name</th><th>Item Effects</th><th>Stackable?</th><th>Approx Trader Value</th><th>Used in Tradeskill</th><th>Notes</th></tr>";
$first=1;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
// if first loop, make the headings
if($first)
{
echo " ";
// do a loop for each field in the $row, make labels
reset($row);
while(@list($fieldname, $fieldvalue) = each($row))
//echo " <td> $fieldname </td> ";
echo "
";
// not first loop anymore
$first=0;
}
echo " ";
// now go through each field and print the value
reset($row);
while(@list($fieldname, $fieldvalue) = each($row))
echo " <td>$fieldvalue </td> ";
echo "<tr></tr>
";
} // end while
?>
</blockquote>
</table>
</body>
</html>
Can anyone suggest a way of integrating the 2 together? How to get whatever is typed in the text box form and make it appear in the mySQL query is what is troubling me.
Thanks in advance and my apologies for so much text ><
Hopkins