Reputation: 1834
i fetch MySql result using PHP array using this Code:
$sql = 'SELECT * FROM ' . LOCATION . ' ORDER BY category ';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );
while ($ROW = $db->fetcharray($r))
{
if ($ROW[1] == '') //line 15
$ROW[1] = $ROW['subcategory'];
}
fetcharray function:
function fetcharray ($query_id)
{
if(!$query_id)
{
$query_id = $this->query_res;
}
if($query_id)
{
$id = (int) $query_id;
$this->q_array[$id] = @mysql_fetch_array($query_id,MYSQL_ASSOC); // LINE 124
return $this->q_array[$id];
}
else
{
return false;
}
}
I see this error:
Notice: Undefined offset: 1 in C:\xampp\htdocs\script\state.php on line 15
I change if ($ROW[1] == '') to if (isset($ROW[1]))
but I see again error.
NOTE: i remove **MYSQL_ASSOC** from fetcharray function and fix error. i think my problem with fetcharray function how to fix this?
How I can Fix this error?
Upvotes: 0
Views: 9383
Reputation: 876
This is not directly answer to your question BUT you implemented some kind of wrapper for old and deprecated functions.
In addition, you have inconsistent coding style. Once you use small letters for variables, another time you use capital letters.
Instead of this:
if ($ROW[1] == '') //line 15
$ROW[1] = $ROW['subcategory'];
you should use:
if (!isset($ROW[1])) //line 15
$ROW[1] = $ROW['subcategory'];
or this:
if (empty($ROW[1])) //line 15
$ROW[1] = $ROW['subcategory'];
Upvotes: 2
Reputation: 3128
In your code:
if ($ROW[1] == '') //line 15
$ROW[1] = $ROW['subcategory'];
You are directly accessing $ROW[1]
( and $ROW[0]
as mentioned in comments) without even setting it. That is the reason it fails. If the name of the column in your database is "1" or "0" after all, try using $ROW["1"] or $ROW["0"]
Upvotes: 0