Hi, in changeing from MYSQL to MYSQLi (that's where the blame goes) I can't get a clear understanding as to the proper code for the while loop. help please. code follows: ------------------------------------------------------ <html><body> <hr> <center><b><font size=+2> 515 Certification Expiration Report</font><br>06/22/2020 - 06/22/2021<p> <hr> <?php //Open a new connection to the MySQL server require_once "getprerentdb.php"; //MySqli Select Query $results = $mysqli->query (SELECT * FROM waitlist); ?> <table border=1> <th>unit#</th> <th>resident name</th> <th>movein date</th> <th>effect date</th> <th>expire date</th> <th>days left</th> <th colspan=3>recertification notification</th> </tr> <?php // --------------------------------------- while($row = mysqli_fetch_array($result)) { // ---------------------------------------- echo "<tr>"; echo "<td>" . $row['apt'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['moveindate'] . "</td>"; echo "<td>" . $row['effdate'] . "</td>"; echo "<td>" . $row['expdate'] . "</td>"; echo "<td>" . $row['daysleft'] . "</td>"; echo "<td>" . $row['90date'] . "</td>"; echo "<td>" . $row['60date'] . "</td>"; echo "<td>" . $row['30date'] . "</td>"; echo "</tr>"; echo "</table>"; } ?> </body></html> PHP:
Why are you using Table under while loop. <?php // --------------------------------------- while($row = mysqli_fetch_array($result)) { // ---------------------------------------- echo "<tr>"; echo "<td>" . $row['apt'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['moveindate'] . "</td>"; echo "<td>" . $row['effdate'] . "</td>"; echo "<td>" . $row['expdate'] . "</td>"; echo "<td>" . $row['daysleft'] . "</td>"; echo "<td>" . $row['90date'] . "</td>"; echo "<td>" . $row['60date'] . "</td>"; echo "<td>" . $row['30date'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> Now format will be fine.
this t 515 Certification Expiration Report 06/22/2020 - 06/22/2021 //Open a new connection to the MySQL server require_once "getprerentdb.php"; //MySqli Select Query $results = $mysqli->query (SELECT * FROM waitlist); ?> Notice: Undefined variable: result in C:\xampp\htdocs\property\certlog.php on line 25 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\property\certlog.php on line 25 unit# resident name movein date effect date expire date days left recertification notification he result:
this $results = $mysqli->query (SELECT * FROM waitlist); PHP: should be $results = $mysqli->query ('SELECT * FROM `waitlist`'); PHP: and this while($row = mysqli_fetch_array($result)) PHP: should be while($row = mysqli_fetch_array($results)) PHP:
a 515 Certification Expiration Report 06/22/2020 - 06/22/2021 //Open a new connection to the MySQL server require_once "getprerentdb.php"; //MySqli Select Query $results = $mysqli->query ('SELECT * FROM `waitlist`'); ?> Notice: Undefined variable: results in C:\xampp\htdocs\property\certlog.php on line 24 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\property\certlog.php on line 24 unit# resident name movein date effect date expire date days left recertification notification fter change:
I wasn't coping looking at that code so I tidied it up a bit. Compare your original to mine and learn a different way of doing things We'll start by adding error display, remove it when it goes live but error messages help you understand your code Put the setup code at the top and only have presentation PHP code in the markup section. You'll read stuff about MVC and separation of code from presentation. This is the best we can do with a single page script. Use H1, H2 etc for your headings and learn how to use css to style them appropriately. Add thead and tbody to your tables, it helps the browser and anyone using a screen reader. May not apply in this case but it's "best practice". Don't jump in and out of echo statements constantly. Just write a single statement that is readable. The {} tell PHP where to find variables in the string. <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); //Open a new connection to the MySQL server require_once "getprerentdb.php"; //MySqli Select Query $results = $mysqli->query ('SELECT * FROM `waitlist`'); ?><html> <head></head> <body> <hr> <h1>515 Certification Expiration Report: 06/22/2020 - 06/22/2021</h1> <hr> <table border='1' cellpadding="4"> <thead> <tr> <th>unit#</th> <th>resident name</th> <th>movein date</th> <th>effect date</th> <th>expire date</th> <th>days left</th> <th colspan=3>recertification notification</th> </tr> </thead> <tbody> <?php // --------------------------------------- while($row = mysqli_fetch_array($results)) { // ---------------------------------------- echo "<tr> <td>{$row['apt']}</td> <td>{$row['name']}</td> <td>{$row['moveindate']}</td> <td>{$row['effdate']}</td> <td>{$row['expdate']}</td> <td>{$row['daysleft']}</td> <td>{$row['90date']}</td> <td>{$row['60date']}</td> <td>{$row['30date']}</td> </tr>"; } ?> </tbody> </table> </body> </html> PHP:
whatParse error: syntax error, unexpected 'waitlist' (T_STRING), expecting ')' in C:\xampp\htdocs\property\certlog.php on line 10's wrong?
Aaah good catch. I didn't put the quotes around the SQL query. I'm surprised you didn't pick up on that. I've updated my code above.
You need to go and hunt down some mysqli tutorials and read how to do prepared statements. If the where clause has user-entered data then you have to ensure that the data is safe.
$results = $mysqli->query (SELECT * FROM waitlist); Code (markup): That's not a string. Where are your quotes? You're using fetch_array instead of fetch_assoc so your results are numerically indexed not field indexed, you're mixing object and non-object willy-nilly... Overall your code is just missing a bunch of things... and the markup is like the worst of "4 transitional" -- aka in transition from 1997 to 1998 practices. Though @sarahk, that {} nonsense is NOT going to do this poor sod any favors. Fixing the gibberish to non-existent semantics and your incomplete code, it goes something more like this: <!DOCTYPE HTML><html lang="en"><body><meta charset="utf-8"> <title>515 Certification Expiration Report</title> </head><body> <table> <caption> 515 Certification Expiration Report<br> 06/22/2020 - 06/22/2021 </caption> <thead> <tr> <th scope="col">unit#</th> <th scope="col">resident name</th> <th scope="col">movein date</th> <th scope="col">effect date</th> <th scope="col">expire date</th> <th scope="col">days left</th> <th scope="col" colspan=3>recertification notification</th> </tr> </thead><tbody> <?php //Open a new connection to the MySQL server require_once('getprerentdb.php'); $results = $mysqli->query(' SELECT * FROM waitlist '); while ($row = $result->fetch_assoc) echo ' <tr> <th scope="row">', $row['apt'], '</th> <td>', $row['name'], '</td> <td>', $row['moveindate'], '</td> <td>', $row['effdate'], '</td> <td>', $row['expdate'], '</td> <td>', $row['daysleft'], '</td> <td>', $row['90date'], '</td> <td>', $row['60date'], '</td> <td>', $row['30date'], '</td> </tr>'; ?> </tbody> </table> </body></html> Code (markup): Guessing slightly on the body row headers... And remember, H1 doesn't mean "draw a line across the screen" it means a block level change in subject or topic (negating something like H1)... and tags like FONT and CENTER haven't been valid/proper HTML since 1997... just like the outmoded border and cellpadding attributes. You want to control that sort of stuff, do it from your stylesheet!
oops, fixed. Not sure how I lost two characters there... but then I probably shouldn't be trying to touch-type with a band-aid across the end of my right hand middle finger. Sliced it open on the tear-strip for a aluminum foil package.
Dead shade long time since I've been lambasted so thoroughly. See you're still at it. I meant to tell you guys I straightened it out. It isn't as pretty as yours looks but slightly less coding and mine works - yours doesn't. Hang in there and don't hurt your friends too bad.