开发者

Query not showing results

I am doing this开发者_如何学Go query. It doesn't show me the result which in $products.

code:

$sql = "SELECT s*
     FROM Client_agent_approvals caa
     INNER JOIN Subscriptions s ON s.client_id = caa.client_id
     WHERE caa.agent_id = '$id'
     AND s.agent_id <> '$id'";
$result = mysql_query($sql);

$query = mysql_query($sql) or die("Error: " . mysql_error());

if ($result == "") {
    echo "";
}
echo "";


$rows = mysql_num_rows($result);

if ($rows == 0) {
    print("");
} elseif ($rows > 0) {
    while ($row = mysql_fetch_array($query)) {

        $product = $row['product'];

        print("Products they have are: $product");
    }
}


if you have edited your code after the comment that was just posted, that was not what was meant by "indentation". you can indent the statements inside loop's and if's to make it more readable.

try using print_r on $rows and $row before doing anything with them. it may help you see what is going on with those variables. http://php.net/manual/en/function.print-r.php


You have s*. I think you mean s.*. You should also use do... while for query iteration:

 $row = mysql_fetch_array($query);

 if(!$row) 
 {
     print('no rows');// a more useful message
 }
 else
 {
    do {

        $product = $row['product'];

         print("Products they have are: $product");
     }
     while($row = mysql_fetch_array($query));

 }

mysql_num_rows actually counts all of the values returned, this does not. You can almost say that it is doing twice the work for the same result.

Of course, all of this assumes that there were one or more rows returned to begin with. Can you confirm that you should be getting something by running this in MySQL directly?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜