I am creating a system in which I want to fetch data from a table complaints Now i Have two variables that on behalf of which i want to fetch data from table complaints. One is the district variable and second is pin code and there are a lot of pin codes attached to one center. For example a center signs up and he wants to work on multiple pin codes lets say 110007 and 110008 so his pin code data is stored in a table named center. And his details like his district is stored in users table. Now i have made a page in which i want to show data from a table complaints where district matches his center and pin code matches his pin code. And the code is working fine if one pin code matches but if there are multiple pin codes attached to a center and the complaint is of only 1 pin code then it shows no result but i want it to show results even if it matches only 1 or any of the pin code.
i have tried some code this is my code
session_start();
if(!isset($_SESSION['username']) || (trim($_SESSION['username']) == '')) {
header("location: login.php");
exit();
}
$username = $_SESSION['username'];
if ($username=="dhruv") {
header("location: complaint.php");
}
$sql = "SELECT * FROM users where username = '$username'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while ($row = mysqli_fetch_assoc($result)) {
$district = $row['district'];
}
}
$sql = "SELECT * FROM center where username = '$username'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while ($row = mysqli_fetch_assoc($result)) {
$pin = $row['id'];
echo $pin."<br>";
}
}
$sql = "SELECT *
FROM complaints
where city_pin = '$pin'
AND status = 'pending'
And district ='$district'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$status = $row['status'];
?>
<tr>
<td><?php echo"<a href='otp.php'>".$row['center']."</a>"?></td>
<td><?php echo $row['time2']?></td>
<td><?php echo $row['product']?></td>
<td><?php echo $row['quantity']?></td>
<td><?php echo $row['warranty']?></td>
<td><?php echo $row['date_of_purchase']?></td>
<td><?php echo $row['customer_name']?></td>
<td><?php echo $row['contact']?></td>
<td><?php echo $row['customer_email']?></td>
<td><?php echo $row['customer_address']?></td>
<td><?php echo $row['city_pin']?></td>
<td><?php echo $row['issue_complaint']?></td>
<td class="red"><a href="otp.php?id=<?php echo $row['id'] ?>"><?php echo $row['status']?></a></td>
</tr>
<?php
}
} else {
echo "0 results".mysqli_error($con);
}
please feel free to ask if you didn't understand any part of my question