I have three tables i want to search for customer data depending on the equipment type.

$test = "SELECT custid, equipment FROM customer WHERE custid='$id'";
$data = @mysqli_query ($dbcon, $test);
$equip = mysqli_fetch_array($data, MYSQLI_ASSOC);








         if($equip['equipment'] = "cellphone" ){
                        // Make the query:
                        $q = "SELECT custid, cdate, custName, customer.equipment, customer.manufacturer, customer.model, customer.imei, notes, workdesc, hardware, status, cost, pickup_date
                              FROM customer 
                              INNER JOIN cellrepair 
                              ON customer.custid=cellrepair.cust_id
                              WHERE custid='$id'";      
                        $result = @mysqli_query ($dbcon, $q); // Run the query.
                        $members = mysqli_num_rows($result);
                        if ($result) { // If it ran OK, display the records.
                        // Table header.
                        echo '<table id="result">
                        <tr>
                        <th><b>ID</b></th>
                        <th><b>Date</b></th>
                        <th><b>Name</b></th>
                        <th><b>Equipment</b></th>
                        <th><b>Manufacturer</b></th>
                        <th><b>Model</b></th>
                        <th><b>IMEI</b></th>
                        <th><b>Notes</b></th>
                        <th><b>Work Done</b></th>
                        <th><b>Hardware</b></th>
                        <th><b>Status</b></th>
                        <th><b>Cost</b></th>
                        <th><b>Pickup Date</b></th>

                        </tr>';
                        // Fetch and print all the records:
                        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                            echo '<tr>
                            <td>' . $row['custid'] . '</td>
                            <td>' . $row['cdate'] . '</td>
                            <td>' . $row['custName'] . '</td>
                            <td>' . $row['equipment'] . '</td>
                            <td>' . $row['manufacturer'] . '</td>
                            <td>' . $row['model'] . '</td>
                            <td>' . $row['imei'] . '</td>
                            <td>' . $row['notes'] . '</td>
                            <td>' . $row['workdesc'] . '</td>
                            <td>' . $row['hardware'] . '</td>
                            <td>' . $row['status'] . '</td>
                            <td>' . $row['cost'] . '</td>
                            <td>' . $row['pickup_date'] . '</td>
                            </tr>';
                            }
                            echo '</table>'; // Close the table.

                            mysqli_free_result ($result); // Free up the resources. 
                        }

                        } elseif($equip['equipment'] = "tablet" ){
                        // Make the query:
                        $q = "SELECT custid, cdate, custName, customer.equipment, customer.manufacturer, customer.model, customer.imei, notes, workdesc, hardware, status, cost, pickup_date
                              FROM customer 
                              INNER JOIN cellrepair 
                              ON customer.custid=cellrepair.cust_id
                              WHERE custid='$id'";      
                        $result = @mysqli_query ($dbcon, $q); // Run the query.
                        $members = mysqli_num_rows($result);
                        if ($result) { // If it ran OK, display the records.
                        // Table header.
                        echo '<table id="result">
                        <tr>
                        <th><b>ID</b></th>
                        <th><b>Date</b></th>
                        <th><b>Name</b></th>
                        <th><b>Equipment</b></th>
                        <th><b>Manufacturer</b></th>
                        <th><b>Model</b></th>
                        <th><b>IMEI</b></th>
                        <th><b>Notes</b></th>
                        <th><b>Work Done</b></th>
                        <th><b>Hardware</b></th>
                        <th><b>Status</b></th>
                        <th><b>Cost</b></th>
                        <th><b>Pickup Date</b></th>

                        </tr>';
                        // Fetch and print all the records:
                        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                            echo '<tr>
                            <td>' . $row['custid'] . '</td>
                            <td>' . $row['cdate'] . '</td>
                            <td>' . $row['custName'] . '</td>
                            <td>' . $row['equipment'] . '</td>
                            <td>' . $row['manufacturer'] . '</td>
                            <td>' . $row['model'] . '</td>
                            <td>' . $row['imei'] . '</td>
                            <td>' . $row['notes'] . '</td>
                            <td>' . $row['workdesc'] . '</td>
                            <td>' . $row['hardware'] . '</td>
                            <td>' . $row['status'] . '</td>
                            <td>' . $row['cost'] . '</td>
                            <td>' . $row['pickup_date'] . '</td>
                            </tr>';
                            }
                            echo '</table>'; // Close the table.

                            mysqli_free_result ($result); // Free up the resources. 
                        }

                        } elseif ($equip['equipment'] != "cellphone" || "tablet") {
                        // Make the query:
                        $q = "SELECT custid, cdate, custName, customer.equipment, customer.manufacturer, customer.model, customer.serial, notes, pcrepair.workdesc, hardware, software, status, cost, pickup_date
                              FROM customer 
                              INNER JOIN pcrepair 
                              ON customer.custid=pcrepair.cust_id
                              WHERE custid='$id'";      
                        $result = @mysqli_query ($dbcon, $q); // Run the query.
                        $members = mysqli_num_rows($result);
                        if ($result) { // If it ran OK, display the records.
                        // Table header.
                        echo '<table id="result">
                        <tr>
                        <th><b>ID</b></th>
                        <th><b>Date</b></th>
                        <th><b>Name</b></th>
                        <th><b>Equipment</b></th>
                        <th><b>Manufacturer</b></th>
                        <th><b>Model</b></th>
                        <th><b>Serial</b></th>
                        <th><b>Notes</b></th>
                        <th><b>Work Done</b></th>
                        <th><b>Hardware</b></th>
                        <th><b>Software</b></th>
                        <th><b>Status</b></th>
                        <th><b>Cost</b></th>
                        <th><b>Pickup Date</b></th>

                        </tr>';
                        // Fetch and print all the records:
                        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                            echo '<tr>
                            <td>' . $row['custid'] . '</td>
                            <td>' . $row['cdate'] . '</td>
                            <td>' . $row['custName'] . '</td>
                            <td>' . $row['equipment'] . '</td>
                            <td>' . $row['manufacturer'] . '</td>
                            <td>' . $row['model'] . '</td>
                            <td>' . $row['serial'] . '</td>
                            <td>' . $row['notes'] . '</td>
                            <td>' . $row['workdesc'] . '</td>
                            <td>' . $row['hardware'] . '</td>
                            <td>' . $row['software'] . '</td>
                            <td>' . $row['status'] . '</td>
                            <td>' . $row['cost'] . '</td>
                            <td>' . $row['pickup_date'] . '</td>
                            </tr>';
                            }
                            echo '</table>'; // Close the table.

                            mysqli_free_result ($result); // Free up the resources. 
                        }

                        } 
                        else { // If it did not run OK.
                        // Public message:
                        echo 'no shit';
                            echo '<p class="error">The current record could not be retrieved. We apologize for any inconvenience.</p>';
                            // Debugging message:
                            //echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>';
                        }


                    //  }

?>

<p><a href="customer_search.html.php">Search Database</a></p>        


        </div>

I keep getting only data for cellphone and nothing else. I have tried everything but still not working. Any assistance as to how to simplified this repetitive task or correct the error.

Looks to me like the IF statement only runs once, there is no looping through the returned records. So the first result = 'cellphone' and thats all you see.

I have done this code . It result is very well.
thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.