dimanche 5 avril 2015

How to implement and call multiple php functions?

The following is code that I have put together with some help from SO. I am trying to be able to implement the $select statement, as well as the $search statement on the same page. The $select statement works fine, but I do not know how to call the $search statement to execute when the user searches using the form within the code. Does anyone know how to do this, or can you redirect me to a good tutorial with how forms interact with php?



<?php
require 'db/connect.php';

$select = $db->query("SELECT * FROM customers ORDER BY id DESC");

$search = $db->query("SELECT * FROM customers WHERE FName LIKE '%$_REQUEST[q]%' OR LName LIKE '%$_REQUEST[q]%' ORDER BY id DESC");
?>

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="wrapper">
<h1>Customers</h1>
<p><a class="btn create" href="createcustomer.php">CREATE</a></p>
<?php
if (!$select->num_rows) {
echo '<p>', 'No records', '</p>';
}else{
?>
<table border="1" width="100%">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Alt Phone</th>
<th>Job Address</th>
<th>Billing Address</th>
<th>Email</th>
<th>Alt Email</th>
</tr>
</thead>
<tbody>
<?php
while ($row = $select->fetch_object()) {
?>
<tr>
<td><?php echo $row->FName;?></td>
<td><?php echo $row->LName;?></td>
<td><?php echo $row->Phone;?></td>
<td><?php echo $row->AltPhone;?></td>
<td><?php echo $row->JobAddress;?></td>
<td><?php echo $row->BillingAddress;?></td>
<td><?php echo $row->Email;?></td>
<td><?php echo $row->AltEmail;?></td>

<td><a class="btn read" href="viewcustomer.php?id=<?php echo $row->id; ?>">READ</a>&nbsp;<a class="btn update" href="editcustomer.php?id=<?php echo $row->id; ?>">UPDATE</a>&nbsp;<a class="btn delete" href="deletecustomer.php?id=<?php echo $row->id; ?>">DELETE</a></td>
</tr>
</tbody>
<tbody>
<?php
}
?>
</table>
<?php
}
?>
# Search form that needs tied to $search
<input type="text" name="q" /> <input type="submit" name="search" />

</div>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire