我有以下PHP:

<?php
$con = mysql_connect("localhost","foo","bar");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("zed", $con);
$getTagID = $_GET["id"];
//make a loop that outputs each coupon that has been tagged that

$alphaTagSQL = mysql_query("SELECT * FROM coupon_tags WHERE tagID = '$getTagID'");

$alphaTagSQLArr[] = mysql_fetch_array($alphaTagSQL);

foreach($alphaTagSQLArr as $mouse)
    {
        $nzed = $mouse["couponID"];
        $brah = mysql_query("SELECT * FROM coupons WHERE couponID = '$nzed'");
        $pen[] = mysql_fetch_row($brah);
    }

foreach($pen as $ruler)
    {
        echo $pen;
    }

?>


我想做的是从$_GET中选择tagID,然后将其与表couponID中与之匹配的所有coupon_tags匹配,然后将这些coupon_ID匹配到表retailerName中的coupons,其中couponID与字段id匹配。然后,我只想按字母顺序列出它们。我只是遇到一些问题-即,出现错误Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource

有什么帮助吗?

最佳答案

尝试改变

$brah = mysql_query("SELECT * FROM coupons WHERE couponID = '$nzed'");


进入

$brah = mysql_query("SELECT * FROM coupons WHERE couponID = '$nzed'") or die(mysql_error());


它将为您提供有关查询为什么失败的更多信息。

10-06 04:42