Page 1 of 1

[SOLVED]I give up.....help

Posted: Wed Sep 22, 2004 9:25 am
by brewmiser
Ok, I have read through the forums and still could not find my answer. I have changed my code over and over and still does not work. So I turn to the Gods for help (btw, that is you all)! :oops:

Here is my error message:
Notice: Undefined offset: 1 in /var/www/html/public/amcad/admin/admin_edit.php on line 9


Notice: Undefined offset: 2 in /var/www/html/public/amcad/admin/admin_edit.php on line 9


Notice: Undefined offset: 3 in /var/www/html/public/amcad/admin/admin_edit.php on line 9
Here is my code:

Code: Select all

<?php
if (isset($_REQUEST['group_delete'])){
  $result_cat = mysql_query("SELECT product_category FROM product_category WHERE product_group = '".$array['product_group']."'") 
    or die("<b>MySQL Error 2:</b> ".mysql_errno()." : ".mysql_error());
  $numrows    = mysql_num_rows($result_cat);
  $array_cat  = mysql_fetch_array($result_cat);

  for ($i=0; $i < $numrows; $i++){
    echo "<p class='normal'>".$array_cat[$i]."</p>";
  }
}
?>
This is a very simple piece of code and I have used this snippet before. So can someone tell me why it is not working now please?

Posted: Wed Sep 22, 2004 9:35 am
by CoderGoblin
Your SQL statement is returning one field from the Select.
mysql_fetch_array returns the row, with an array set for each field.
At the moment you are checking for the array based on the row number, not the field.

My prefered method (uses fetch_assoc)....

Code: Select all

<?php
if (isset($_REQUEST['group_delete'])){
  $result_cat = mysql_query("SELECT product_category FROM product_category WHERE product_group = '".$array['product_group']."'") 
    or die("<b>MySQL Error 2:</b> ".mysql_errno()." : ".mysql_error());
  while ($row=mysql_fetch_assoc($result_cat)) {
    echo "<p class='normal'>".$row['product_category']."</p>";
  }
}
?>

Posted: Wed Sep 22, 2004 9:42 am
by brewmiser
That did it, how simple.....thanks a bunch!