When I try to use entries from the $rules array I get the error:
Notice: Undefined index: id in C:\xampp\htdocs\topdrawerfifa\fifa-text-book.php on line 55 Notice: Undefined index: content in C:\xampp\htdocs\topdrawerfifa\fifa-text-book.php on line 56
Whilst this answer addresses what the error means, it doesn't help to identify the source.
Here is the code -
function get_rules($id = null){
$rules = array();
$query = "SELECT 'fifa_rules' . 'id' AS 'rule_id', 'content'
FROM 'fifa_rules'";
if(isset($id)){
$id = (int)$id;
$query .= "WHERE 'fifa_rules'.'id' = {$id}";
}
$query .= "ORDER BY 'fifa_rules'.'id' DESC";
$query = mysql_query($query);
while($row = mysql_fetch_assoc($query)){
$rules[] = $row;
}
return $rules;
}
$rules = (isset ($_GET['$id'])) ? get_rules($_GET['id']) : get_rules();
?>
<h2><a href="fifa-text-book.php?id=<?php echo $rules['id']; ?>"><?php echo
$rules['id']; ?></a></h2>
<div><?php echo nl2br($rules['content']); ?></div>
I managed to get the last part of that to work when I changed the while loop to this:
while($row = mysql_fetch_array($query)){
$rules['id'] = $row['id'];
$rules['content'] = $row['content'];
}
But it would only show the first entry in the database. How do I get this to work properly? Thanks.