首頁 > 後端開發 > php教程 > 循环 - php,while中使用mysql查询语句问题

循环 - php,while中使用mysql查询语句问题

WBOY
發布: 2016-06-06 20:46:13
原創
951 人瀏覽過

php的mysql查询语句可不可以这样用呢?

<code class="lang-php">$query = "SELECT name FROM bank WHERE area LIKE 'aaa'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
    $http = $row['http'];
    $task_query = "SELECT * FROM task WHERE link LIKE'%$http%'";
    $task_result = mysql_query($task_query) or die(mysql_error());
    while($task = mysql_fetch_array($task_result));
            echo $task['high'].'<br>';
    }
</code>
登入後複製
登入後複製

回复内容:

php的mysql查询语句可不可以这样用呢?

<code class="lang-php">$query = "SELECT name FROM bank WHERE area LIKE 'aaa'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
    $http = $row['http'];
    $task_query = "SELECT * FROM task WHERE link LIKE'%$http%'";
    $task_result = mysql_query($task_query) or die(mysql_error());
    while($task = mysql_fetch_array($task_result));
            echo $task['high'].'<br>';
    }
</code>
登入後複製
登入後複製

<code class="lang-sql">SELECT *
FROM task    
JOIN (SELECT http AS zhttp FROM bank WHERE area LIKE 'aaa') AS Z 
    ON task.link LIKE CONCAT('%', Z.zhttp, '%')
</code>
登入後複製

SELECT * FROM bank LEFT JOIN task ON task.link LIKE concat('%', bank.http, '%') WHERE bank.area = 'aaa'

我觉得你可能需要JOIN....

<code>select task.high from task left join bank on task.link like concat('%', bank.http. '%') where bank.area like 'aaa'
</code>
登入後複製

你在 $task_query = "SELECT * FROM task WHERE link='%$http%'"; 这里应该是希望得到模糊匹配的效果,怎么能用 = 呢?

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板