I need to run a query and have the results post back to a table on my webpage, however, it is messing up my webpage. Basically, it is timing my web page out. I know the query works because I tested it in mySQL and got back the results I wanted. Can anyone see where I went wront at? I’ve used this exact same query on the project before and it worked GREAT, but now adding some pagination it isnt. If i run a simple query (IE: select * from Customers) I get results, but obvisouly these results are not what I need. Thanks!!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body >
<?php
// This script retrieves all the records from the users table.
echo '<h1>Registered Users:</h1>';
require_once ('mysqli_connect.php'); // Connect to the data base.
include('ps_pagination.php'); //Include the PS_Pagination class
/*
Write the query...
Note: CONCAT_WS is a function that concatenates items together with a given separator.
In this case, the last name and first name are added together , and separated by a comma and a space.
*/
$q = "SELECT Customers.CustomerID, Customers.OldCustomerID, CONCAT(Customers.LastName,', ', Customers.FirstName,', ', Customers.MiddleName) AS 'Customer Name',
CONCAT(LEFT(Customers.FirstName ,1), LEFT(Customers.MiddleName,1), LEFT(Customers.LastName,1)) AS Username,
zlu_Cars.Description AS Car, zlu_CarColor.Description AS 'Car Color', zlu_Computers.Description AS Computer,
CASE Customers.IsLaptop WHEN 1 THEN 'Yes' WHEN 0 THEN 'No'END AS Laptop,
zlu_Race.Description AS Race, zlu_Residence.Description AS Residence, zlu_BirthMonth.Description AS 'Birth Month'
FROM (((((Customers INNER JOIN zlu_Cars ON Customers.CarID = zlu_Cars.CarID) INNER JOIN zlu_CarColor ON Customers.CarColorID = zlu_CarColor.CarColorID) INNER JOIN zlu_Computers ON Customers.ComputerID = zlu_Computers.ComputerID) INNER JOIN zlu_Race ON Customers.RaceID = zlu_Race.RaceID) INNER JOIN zlu_Residence ON Customers.ResidenceID = zlu_Residence.ResidenceID) INNER JOIN zlu_BirthMonth ON Customers.BirthMonthID = zlu_BirthMonth.BirthMonthID
ORDER BY Customers.LastName, Customers.FirstName";
//Create a PS_Pagination object
$countperpage = 18;
$pager = new PS_Pagination($dbc,$q,$countperpage,10);
//The paginate() function returns a mysql result set
$rs = $pager->paginate();
// Count the number of returned rows:
$num = $pager->total_rows;
// If it ran OK, display the records.
if ($num > 0) {
// Print the number of users:
echo "<p>There are currently $num registered users.</p>";
// Table header.
echo '<table margin-left="auto" margin-right="auto" cellspacing="2" cellpadding="5" border="1" width="75%">
<tr>
<td><b>CustomerID</b></td>
<td><b>OldCustomerID</b></td>
<td><b>Customer Name</b></td>
<td><b>Username</b></td>
<td><b>Car</b></td>
<td><b>Car Color</b></td>
<td><b>Computer</b></td>
<td><b>Laptop</b></td>
<td><b>Race</b></td>
<td><b>Residence</b></td>
<td><b>Birth Month</b></td>
</tr>';
/* Fetch and print all the records:
fetch_array
Fetch a result row as an associative, a numeric array, or both.
Parameters:
type - one of MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH (default).
By using the MYSQLI_ASSOC constant this function will behave identically to the mysqli_fetch_assoc(),
while MYSQLI_NUM will behave identically to the mysqli_fetch_row() function. The final option MYSQLI_BOTH
will create a single array with the attributes of both.
Returns:
a result row as an associative, a numeric array, or both or null if there are no more rows in the result set
*/
while ($row = mysqli_fetch_array($rs, MYSQLI_ASSOC)) {
echo '<tr>
<td>' . $row['CustomerID'] . '</td><td>' . $row['OldCustomerID'] . '</td><td>' . $row['Customer Name'] . '</td>
<td>' . $row['Username'] . '</td><td>' . $row['Car'] . '</td><td>' . $row['Car Color'] . '</td>
<td>' . $row['Computer'] . '</td><td>' . $row['Laptop'] . '</td><td>' . $row['Race'] . '</td>
<td>' . $row['Residence'] . '</td><td>' . $row['Birth Month'] . '</td>
</tr>';
}
echo '</table>'; // Close the table.
mysqli_free_result ($rs); // Free up the resources.
} else { // If no records were returned.
echo '<p class="error">There are currently no registered users.</p>';
}
mysqli_close($dbc); // Close the database connection.
?>
</body>
</html>