如何在新查询中使用分解数据?
我需要对爆炸后数组的每个部分运行查询。
现在,我只是从爆炸中回显每个单词,但我需要为爆炸中的每个单词运行这样的查询:
(select * from words where word = $split_phrase[$i])
我想知道如何处理需要运行的单独查询。那我可以结合吗 以某种方式与for循环?
我检查过其他帖子,但似乎没有什么可以直接解决这个问题。
代码示例:我有 2 个表 短语 字
<?
/* Table: phrases */
$ID = 'ID'
$TARGET = 'TLP'
/* Table: words */
$ID_Split = 'ID';
$Word_Split = 'Word';
$WBW_Split = 'WBW';
?>
<table width="800">
<tr>
<th>Display Word</th>
</tr>
<?
/* I pass in a variable from another page which is inserted into the query */
$phrase_query = mysql_query("SELECT * FROM phrases WHERE id=" . $_GET['id']);
/* Loop through the search results and explode the string on the column variable $Target */
while($rows=mysql_fetch_assoc($phrase_query)) {
$split_phrase = explode(" ", $rows[$TARGET]);
/* Loop through the string and list each word from the explode array /
the html table in the echos is started outside the PHP tags */
for($i = 0; $i < count($split_phrase); $i++) {
echo "<tr>";
echo "<td>" .$split_phrase[$i] . "</td>";
echo "</tr>";
}
?>
</table>
I need to run a query on each part of the array coming out of explode.
Right now I just echo each word out from the explode, but I need to run a query like this for each word in the explode:
(select * from words where word = $split_phrase[$i])
I am wondering how to deal with the separate queries that need to run. Can I combine then
in some way with the for loop?
I have check other posts, but nothing seems to address this directly.
Code Sample:I have 2 tables
phrases
words
<?
/* Table: phrases */
$ID = 'ID'
$TARGET = 'TLP'
/* Table: words */
$ID_Split = 'ID';
$Word_Split = 'Word';
$WBW_Split = 'WBW';
?>
<table width="800">
<tr>
<th>Display Word</th>
</tr>
<?
/* I pass in a variable from another page which is inserted into the query */
$phrase_query = mysql_query("SELECT * FROM phrases WHERE id=" . $_GET['id']);
/* Loop through the search results and explode the string on the column variable $Target */
while($rows=mysql_fetch_assoc($phrase_query)) {
$split_phrase = explode(" ", $rows[$TARGET]);
/* Loop through the string and list each word from the explode array /
the html table in the echos is started outside the PHP tags */
for($i = 0; $i < count($split_phrase); $i++) {
echo "<tr>";
echo "<td>" .$split_phrase[$i] . "</td>";
echo "</tr>";
}
?>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分解单词
转义并添加引号 (php >= 5.3)
使用
IN
条件运行查询并且您最好使用 PDO 或 mysqli 而不是 mysql - 它已被弃用。
Explode words
Escape and add quotes (php >= 5.3)
Run query with
IN
conditionAnd you better use PDO or mysqli instead of mysql - it is deprecated.