I have recently started using PHP to implement a basic ranking system. Here is my code:
review.php
<?php
require 'connect.inc.php';
mysql_select_db("conference");
$query = mysql_query("SELECT * FROM event");
$event = [];
while($row = mysql_fetch_array($query)){
$event [] = $row;
}
?>
<?php foreach($event as $events): ?>
<div class="event">
<h3><a href="event.php?id=<?php echo $events['eventID'];?>"><?php echo $events['eventName'];?></a><h3>
<div class="event-rating"> Rating: x/5</div>
</div>
<?php endforeach;?>
event.php
<?php
require 'connect.inc.php';
$event= null;
if(isset($_GET['eventID'])){
$id=(int)$_GET['eventID'];
$event = mysql_query("SELECT * FROM event WHERE eventID = {$id}")->fetch_object();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<?php if($event):?>
<div class="event">
This is Event "<?php echo $event['eventName'];?>"
<div class="event-rating"> Rating: x/5</div>
<div class="event-rate"> Rating: x/5</div> Rate this Event:
<?php foreach(range(1,5)as $rating):?>
<a href=""><?php echo $rating; ?></a>
<?php endforeach ?>
</div>
<?php endif;?>
</body>
</html>
The problem I have is that nothing is outputting onto the webpage, whereas it should display a rating page from 1 to 5. I believe the problem lies within the ->fetch_object(); line because this had been causing me problems before so I used alternatives such as mysql_fetch_array.
I also tried starting again using PDO and mysqli connections but still not having any luck.
If anyone could provide any advice it would be greatly appreciated.
Also, if anyone can explain ->fetch_object(); that would be very useful as there isn't much explanation online.