Page 1 of 1

"Bad Field Offset"

Posted: Tue Nov 30, 2004 11:31 am
by patch2112
Hello, I've used $i as a mysql_fetch_field offset before and it worked fine, but now I"m getting a "Bad Field Offset" (OR err213- my error code) error, for which there is no information (at least that I can find). Does anyone see anything wrong here?

Code: Select all

//////////product pricing info 
$sql2 = mysql_query("select E1B1, E25B1, E100B1, P1B1, P25B1, P100B1, E1B2, E25B2, E100B2, P1B2, P25B2, P100B2, E1B3, E25B3, E100B3, P1B3, P25B3, P100B3, E1B4, E25B4, E100B4, P1B4, P25B4, P100B4, E1B5, E25B5, E100B5, P1B5, P25B5, P100B5, E1B6, E25B6, E100B6, P1B6, P25B6, P100B6 from products where item_name="$product"") 
or die("Didnt select price details"); 

$row2=mysql_fetch_array($sql2) 
or die("Didn't fetch array 234"); 

for ($i=0; $i<40; $i++) 
&#123; 
$name = mysql_fetch_field($sql2, $i) 
or die("err213"); 
$msg2 .= "<tr><td width="150">$name->name </td><td width="5"><input name="$row2&#1111;$i]" type="text" value="$row2&#1111;$i]" size="5" maxlength="5"</td>"; 

&#125;
Thanks!

Posted: Tue Nov 30, 2004 11:39 am
by protokol
mysql_fetch_field($sql2, $i) is most likely failing because you don't have 40 fields that you are returning. Also it doesn't make sense to use mysql_fetch_array() and mysql_fetch_field this way.

Thanks!

Posted: Tue Nov 30, 2004 11:45 am
by patch2112
You were exactly right. I was going to get the size set right after I got the offset working. Forgive me, I'm still new.

You mentioned that it's not a good use of fetch_array and fetch_field. What would be a better way? I'm trying to capture the value and column name from the query.

Thanks again!