gpt4 book ai didi

PHP - MYSQL 从数组中查询多个值

转载 作者:太空宇宙 更新时间:2023-11-03 12:24:55 25 4
gpt4 key购买 nike

我想在循环中运行插入查询,直到数组中的所有元素都通过。

例如:

$signs = array("aries", "taurus", "gemini", "cancer", "leo", "virgo", "libra", "scorpio", "sagittarius", "capricorn", "aquarius", "pisces");


$config = array('sign' => 'aries',
'type' => 'daily',
'date' => date('Y-m-d'),);


$content = $horoscope->get_daily_horoscope($config);
$update = $db->prepare("INSERT INTO `horoscope` (`zodiacal_sign`, `last_updated`, `content`) values (%s,%s,%s)", $config['sign'], $config['date'], $content);
$db->query($update);

在所有 $signs 替换 $config['sign'] 之前,我不知道如何运行此查询,并且查询运行了所有 12 次循环。

有人可以帮帮我吗?

最佳答案

你可以这样做......

$signs = array("aries", "taurus", "gemini", "cancer", "leo", "virgo", "libra", "scorpio",     "sagittarius", "capricorn", "aquarius", "pisces");

foreach($signs as $s){


$config = array('sign' => $s,
'type' => 'daily',
'date' => date('Y-m-d'),);


$content = $horoscope->get_daily_horoscope($config);
$update = $db->prepare("INSERT INTO `horoscope` (`zodiacal_sign`, `last_updated`, `content`) values (%s,%s,%s)", $config['sign'], $config['date'], $content);
$db->query($update);
}

关于PHP - MYSQL 从数组中查询多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18093070/

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