MySQLi won't display database information

Codes here !

Moderators: egami, macek, gesf

Post Reply
BelowZero
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Feb 08, 2011 4:36 pm

Fri Nov 13, 2020 8:48 am

Trying to update an old website from MySQL to MySQLi. Connection to database is fine but the site won't display any information from the database. Probably a typo somewhere but my weary eyes aren't seeing it. Can anyone check the coding for mistakes? Thanks.

www.beat-the-spread.net

Code: Select all

<?php include("opendatabase.php"); ?>

							<?php

							for ($i = 1; $i <= 8; $i++) 
							{
								echo "<div class='gameholder'><div class ='textholder2'>";
								$result = mysqli_query($con, "
								SELECT * 
								FROM schedule
								JOIN teams ON schedule.team = teams.team_id
								WHERE week_id ='10'
								AND game_id ='$i'");
 
								echo "<table class='schedule'>\n";

								while($row = mysqli_fetch_array( $result )) 
								{
									if($row['pt_spread'] == 0)
									{
										$row['pt_spread'] = "";
									}
									if(empty($row['pt_spread'] ))
									{
									$row['pt_spread'] = "";
									}

									if (empty($row['bye']))
									{
									echo "</td><td class='schedule' width='51%'>"; echo $row['alt_name'];
									echo "</td><td class='schedule' width='25%' style='color:#ffffff;'>"; echo $row['pt_spread'];
									echo "</td><td class='schedule' width='16%'>"; echo $row['team_pts'];
									echo "</td></tr>";
									}
								}
		
								echo "</table>";
								echo "<br />";
								echo "</div> <!-- textholder2 --></div><!-- gameholder -->";
							}

							mysqli_close($con);
							?>
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1186
Joined: Mon Feb 22, 2016 5:52 pm

Sat Nov 14, 2020 7:54 am

Please don't take this the wrong way, but, you've missed the point of changing from mysql_***, not all mysql_ calls translate to mysqli_ calls.

The point was to allow time to get used to using prepared statements for security reasons. What I suggest you do is learn PDO instead of MySQLi, it offers many benefits over the old, outdated and deprecated functions that you have been using. It's not that hard to learn and removes the potential SQL injections and might offer an increase in execution speed in the looped example you have shown.
User avatar
Strider64
php-forum GURU
php-forum GURU
Posts: 396
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI
Contact:

Sat Nov 14, 2020 6:17 pm

Life is a fig newton of your imagination! https://www.miniaturephotographer.com
Post Reply