0

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.

Community
  • 1
  • 1
  • 1
    What is the entire error message ? Also your query is wrong, `ORDER BY` should never come before `WHERE` and you are not appending your 2nd part off the query when id exists as u don't have a `.` before the `=` like this `$query .= "WHERE 'fifa_rules'.'id' = {$id}";` – Prix Jul 30 '13 at 22:49
  • 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 That is the error message. – user2179817 Jul 30 '13 at 22:56

0 Answers0