phpstuff Posted September 23, 2013 Share Posted September 23, 2013 Been over this multiple times, found some errors and fixed them and went through 2 more times but still can't see what is wrong here: <?php # Script 10.4 - view_users.php #4 // This script runs a query on the username database, and retrieves all the records from the users table $page_title = 'View the current users'; include ('includes/header.html'); echo '<h1>Registered Users</h1>'; require ('mysqli_connect.php'); // Connect to the database // Number of records to show per page $display = 10; // Determine how many pages there are... if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined $pages = $_GET['p']; } else { // Need to determine // Count the number of records $q = "SELECT COUNT(user_id) FROM users"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages if ($records > $display) { // More than 1 page $pages = ceil ($records/$display); } else { $pages = 1; } } // End of p IF. // Determine where in the database to start returning results... if (isset($_GET['s'])) && is_numeric($_GET['s'])) { $start = $GET['s'] } else { $start = 0; } // Define the query (dr = date registered) $q = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr, user_id FROM users ORDER BY registration_date ASC LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // Table header echo '<table align="center" cellspacing="0" cellpadding="5" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b>Last Name</b></td> <td align="left"><b>First Name</b></td> <td align="left"><b>Date Registered</b></td> </tr> '; // Fetch and print all the records $bg = '#eeeeee'; // Set the initial background color while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg =='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color (It's set above to #eeeeee, this test with Ternary Operator will be true right now only if the color is #eeeeee, and since its currently set to #eeeeee above, it will be true (#eeeeee == #eeeeee) so the color returned will be #ffffff. Next time through the loop, the color will be what it was just set to #ffffff, so when it does a test, it will be false, which will return the second color (#eeeeee). This process will repeat itself which will create candy striping in the table rows. echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user.php?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> '; } // End of while loop echo '</table>'; // Close the table mysqli_free_result ($r); // Free up the memory resources (an optional step that is considered good form) mysqli_close($dbc); // Close the database connection // Make the links to other pages if necessary if ($pages > 1) { // Add some spacing and start a paragraph echo '<br /><p>'; // Determine what page the script is $current_page = ($start/$display) + 1; // If its not the first page, make a Previous link if ($current_page != 1) { echo '<a href="view_users.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> '; } // Make all the numbered pages for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_users.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If its not the last page, make a Next button if ($current_page != $pages) { echo '<a href="view_users.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; } echo '</p>'; // Close the paragraph } // End of links section include ('includes/footer.html'); ?> Link to comment Share on other sites More sharing options...
Larry Posted September 23, 2013 Share Posted September 23, 2013 If you're getting a blank screen, you should start by confirming that display_errors is enabled so you can see what the error is. Link to comment Share on other sites More sharing options...
phpstuff Posted September 24, 2013 Author Share Posted September 24, 2013 Thanks Larry, historically I've always worked through the error but I can see as code gets longer this will become a requirement... I added: ini_set ('display_errors', 1); // TURN ON DISPLAY ERRORS And I also went into the php.ini file and changed it to: display_errors = On I am still getting a blank screen... I thought maybe having both on caused the issue - so I deleted the ini_set line from the code - still get a blank page. Any ideas? Link to comment Share on other sites More sharing options...
phpstuff Posted September 24, 2013 Author Share Posted September 24, 2013 Arrgh... Once again I missed an underscore, a semicolon, and a parenthesis!! I was still getting a blank screen even though I had display_errors = On. Any idea why? Link to comment Share on other sites More sharing options...
Larry Posted September 25, 2013 Share Posted September 25, 2013 Enabling display_errors in the script won't work if your script has a parse error If you tried to enable it in your php.ini file and it still showed a blank page, then the enabling didn't work. Link to comment Share on other sites More sharing options...
Recommended Posts