kayp sanchez kayp sanchez - 1 year ago 50
Javascript Question

I want to display 1 record instead of displaying the whole Database, PHP


<form method="post" action="a.php">
<select name="taskOption" id="cust-id" onchange="showUser(this.value)">
include 'orderSelect.php';
echo '<option>View Order</option>';
while($row = mysqli_fetch_array($result)):;?>
<option value='<?php echo $row[0]; ?>'><?php echo $row[1]; echo " ";
echo $row[2]; ?></option>
<?php endwhile; ?>



include 'connect.php';
$q = intval($_GET['q']);

$sql = "SELECT id, firstname, lastname,productOne, quantity, price
FROM orderlist";
$result = mysqli_query($conn, $sql);

echo "<table >

while($row = mysqli_fetch_array($result)) {
$tquan = $row['quantity'];
$tprice = $row['price'];
$total = $tquan * $tprice;

echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['productOne'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $total . "</td>";
echo "</tr>";
echo "</table>";

I got it working. IT display the record/ users that I want to see when something is selected from the drop down list, but the problem is it's displaying the entire database data. I only want to get that specific that of the selected person. Any Ideas how to solve this problem? I would appreciate it.

Image Example

I only wanted the first row to be selected when I select from the dropdown list

Answer Source

Your SELECT is of the whole database you need to select something exact.

For example:

$sql = "SELECT 'id' FROM Users WHERE username='$name'";

That is an example of using the WHERE clause.