gpt4 book ai didi

PHP - 代码几乎达到了我想要的效果

转载 作者:行者123 更新时间:2023-11-29 15:09:59 24 4
gpt4 key购买 nike

下面的代码呼应了以下内容:

Table Name 1

Table Name 2

Table Name 3

Table Name 4 "$entry": "votes_up for $entry in Table Name 4"

我希望它能回应这个:

Table Name 1: "votes_up for $entry in Table Name 1"

Table Name 2: "votes_up for $entry in Table Name 2"

Table Name 3: "votes_up for $entry in Table Name 3"

Table Name 4: "votes_up for $entry in Table Name 4"

如何更改代码以使其符合我的要求?

表名称的数量根据 $entry 的不同而变化。

谢谢

约翰

$result = mysql_query("SHOW TABLES FROM feather") 
or die(mysql_error());

while(list($table)= mysql_fetch_row($result))
{
$sqlA = "SELECT `site`,votes_up FROM `$table` WHERE `site` LIKE '$entry'";
$resA = mysql_query($sqlA) or die("$sqlA:".mysql_error());
if(mysql_num_rows($resA) > 0)
{
$table_list[] = $table;
while($rowA = mysql_fetch_assoc($resA))
{
$votes_up[$rowA["site"]] = $rowA["votes_up"];
}
}
}

foreach( $table_list as $key => $value){
echo "$value <br />";
}

foreach($votes_up as $site => $vote_up)
{
echo "$site: $vote_up";
}

最佳答案

没关系。

这给了我我想要的:

$result = mysql_query("SHOW TABLES FROM feather") 
or die(mysql_error());

while(list($table)= mysql_fetch_row($result))
{
$sqlA = "SELECT COUNT(*) FROM `$table` WHERE `site` LIKE '$entry'";
$resA = mysql_query($sqlA) or die("$sqlA:".mysql_error());
list($isThere) = mysql_fetch_row($resA);
if ($isThere)
{
$table_list[] = $table;
}
}


foreach ($table_list as $table) {
$sql = "SELECT votes_up FROM `$table` WHERE `site` LIKE '$entry'";
$sql1 = mysql_query($sql) or die("$sql:".mysql_error());
while ($row = mysql_fetch_assoc($sql1)) {
echo $table . ': "' . $row['votes_up'] . " for $entry from $table\"<br />";
}
}

关于PHP - 代码几乎达到了我想要的效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1004519/

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