How to apply this search result code in Dreamweaver PHP
Posted: Tue Aug 08, 2006 8:16 am
Pimptastic | Please use
----------------------------------------------------------------------------------------------------------------------------
Result Page:
Pimptastic | Please use
Code: Select all
,Code: Select all
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]
DW8 PHP/MySQL IIS XP PRO:
Please help to define this search result in DW PHP! I'm a bit confused myself.
The problem is that I want the results to loop inside a nice and proper DW table but don't know how to do it as DW recordset. Thanks!
Search Page:Code: Select all
<?php
$dbcnx = @mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
if (!@mysql_select_db('hydrosql')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}
$subcats = @mysql_query('SELECT metertp_id, metertp_name FROM flow_metertp');
if (!$subcats) {
exit('<p>Unable to obtain subcategory list from the database.</p>');
}
$cats = @mysql_query('SELECT cat_id, cat_name FROM flow_cat');
if (!$cats) {
exit('<p>Unable to obtain category list from the database.</p>');
}
?>
</h1>
<form action="search_result.php" method="get">
<p>Specify the search criteria :</p>
<label></label>
<label>By category:<br />
<select name="cid" size="1">
<option selected value="">Any Category</option>
<?php
while ($cat = mysql_fetch_array($cats)) {
$cid = $cat['cat_id'];
$cname = htmlspecialchars($cat['cat_name']);
echo "<option value='$cid'>$cname</option>\n";
}
?>
</select></label>
<br />
<br />
<label>By subcategory: <br />
<select name="sid" size="1">
<option selected="selected" value="">Any Subcategory</option>
<?php
while ($metertp = mysql_fetch_array($subcats)) {
$sid = $metertp['metertp_id'];
$sname = htmlspecialchars($metertp['metertp_name']);
echo "<option value='$sid'>$sname</option>\n";
}
?>
</select>
</label>
<br />
<br />
<label>Containing text: <br />
<input type="text" name="searchtext" /></label>
<br />
<input type="submit" value="Search" />
</form>----------------------------------------------------------------------------------------------------------------------------
Result Page:
Code: Select all
<?php
$dbcnx = @mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
if (!@mysql_select_db('hydrosql')) {
exit('<p>Unable to locate the products ' .
'database at this time.</p>');
}
// The basic SELECT statement
$select = 'SELECT DISTINCT id, name';
$from = ' FROM flow_products';
$where = ' WHERE 1=1';
$sid = $_GET['sid'];
if ($sid != '') { // A subcat is selected
$where .= " AND metertp='$sid'";
}
$cid = $_GET['cid'];
if ($cid != '') { // A category is selected
$from .= ', flow_procat';
$where .= " AND id=prodid AND catid='$cid'";
}
$searchtext = $_GET['searchtext'];
if ($searchtext != '') { // Some search text was specified
$where .= " AND name LIKE '%$searchtext%'";
}
?>
<table>
<tr><th>Product Name: </th><th>Options</th></tr>
<?php
$products = @mysql_query($select . $from . $where);
if (!$products) {
echo '</table>';
exit('<p>Error retrieving products from database!<br />'.
'Error: ' . mysql_error() . '</p>');
}
while ($flow_products = mysql_fetch_array($products)) {
echo "<tr valign='top'>\n";
$id = $flow_products['id'];
$name = htmlspecialchars($flow_products['name']);
echo "<td>$name</td>\n";
echo "<td><a href='edit.php?id=$id'>Edit</a> | " .
"<a href='delete.php?id=$id'>Delete</a></td>\n";
echo "</tr>\n";
}
?>Pimptastic | Please use
Code: Select all
,Code: Select all
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]