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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

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

Post 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?
Last edited by brewmiser on Wed Sep 22, 2004 9:41 am, edited 1 time in total.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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>";
  }
}
?>
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

That did it, how simple.....thanks a bunch!
Post Reply