gpt4 book ai didi

php - 如何从与数组值相关的其他数据库表中获取值?

转载 作者:行者123 更新时间:2023-11-29 22:00:27 26 4
gpt4 key购买 nike

在下面的代码中,我将一个数组存储在客户表中。现在我想要来自代理表的数据,但与数组值相关。

 <?php
$query = "SELECT * FROM customer";
$no1=1;
$result = mysql_query($query);

while($values = mysql_fetch_array($result))
{
$values= unserialize($values['part_no']);


foreach($values as $value)
{

echo $value."<br>";
$query2 = "SELECT * FROM agent WHERE number=$value";
$result2 = mysql_query($query2);

while($values2 = mysql_fetch_array($result2))
{

echo '' . $row['name'] . ''; // get value from agent table.
$no1++;
// echo $no1."<br>";
}
}

}
?>

最佳答案

试试这个

<?php
$query = "SELECT * FROM customer";
$no1=1;
$result = mysql_query($query);

while($values = mysql_fetch_array($result))
{
$values= unserialize($values['part_no']);


foreach($values as $value)
{
$search_value = "'".implode("','", $value)."'";
echo $value."<br>";
$query2 = "SELECT * FROM agent WHERE number IN ($search_value)";
$result2 = mysql_query($query2);

while($values2 = mysql_fetch_array($result2))
{

echo '' . $values2['name'] . ''; // get value from agent table.
$no1++;
// echo $no1."<br>";
}
}

}
?>

关于php - 如何从与数组值相关的其他数据库表中获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32710588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com