Page 1 of 1

How to apply this search result code in Dreamweaver PHP

Posted: Tue Aug 08, 2006 8:16 am
by prasitc2005
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]

Posted: Tue Aug 08, 2006 8:34 am
by neophyte
Welcome to Devnetwork.

Please remember to use PHP tags or something appropriate when posting code.

Second DW is a great tool but it doesn't replace learning html tags or php code.

I know because once upon a not to long ago day I made the same mistake.

It's a great tool

Posted: Tue Aug 08, 2006 9:19 am
by prasitc2005
DW PHP is a great tool especially when I have such tight deadline!

Also, I love to be able to manipulate table layout. By spending hours on adjusting script for table is very frustating. Don't you think by combining such 2 powerful tool to work together is amazing? I would love to know more how to integrate everything php with DW8.

DHTML + PHP + Mysql + DW8 will make you get any job in the world as web developer!

Posted: Tue Aug 08, 2006 9:31 am
by feyd
This isn't the place to evangelize an editor. Please stick to your original topic.

Posted: Tue Aug 08, 2006 9:47 am
by prasitc2005
Sorry. Your messege makes me laugh. Perhaps, I should start learning how to preach in PHP... I think my question costs and there's nothing such easy freebie.