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

WBOY
Release: 2016-06-06 20:46:13
Original
930 people have browsed it

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>
Copy after login
Copy after login

回复内容:

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>
Copy after login
Copy after login

<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>
Copy after login

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!