mysql_fetch没有显示

mysql_connect('localhost:3036', 'x', 'x');
mysql_select_db('extractor');
$baseSKUraw = mysql_query("SELECT * FROM product_category where tier_one='".$result1."' and tier_two ='".$result2."' ");
$baseSKU = mysql_fetch_array($baseSKUraw);
echo json_encode(array("error"=>0, "result1"=>$baseSKU['sku_base']));

The Json is returning {"error":0,"result1":null} but when I do a "result1"=>"texthere" it will return accordingly to my textbox.

  • What went wrong here, I can't seem to display the sku_base?
  • When should I use mysql_fetch_array? because I'm returning only 1 result now?

var_dump(baseSKUraw);

resource(3) of type (mysql result)
{"error":0,"result1":null}

print_r($baseSKU);

resource(3) of type (mysql result)
Array
(
    [0] => 1
    [id] => 1
    [1] => Tops
    [tier_one] => Tops
    [2] => Shortsleeve
    [tier_two] => Shortsleeve
    [3] => WTSS
    [sku_base] => WTSS
)

Your problem is here,

$baseSKU = mysql_fetch_array($baseSKUraw);
echo json_encode(array("error"=>0, "result1"=>$baseSKU['sku_base']));

your using mysql_fetch_array and trying to use the results as if it was returned using mysql_fetch_assoc. When you use mysql_fetch_array you need to use the numerical index.