基于在StackOverflow上给我的建议,我尝试了下面的查询,但它没有工作。我正试图获取数据库中的"site“最近增加的25个值的列表,而不管它们在哪个表中。下面的代码给出了以下错误:
警告: mysql_fetch_array():提供的参数不是第82行domain.php中的有效MySQL结果资源
第82行有while ($rowa = mysql_fetch_array($indexa))
知道为什么不行吗?
echo "<table class=\"samples\">";
$index = mysql_query("select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='sitefeather'");
while ($row = mysql_fetch_array($index))
{
$indexa = mysql_query("select site FROM index order by createdatetime desc limit 25");
while ($rowa = mysql_fetch_array($indexa))
{
echo '<tr><td><a href="sitelookup3.php?entry='.urlencode($rowa['site']).'&searching=yes&search=search">'.$rowa['site'].'</a></td></tr>';
}
}
echo "</table>";
发布于 2009-10-31 06:14:04
您可能需要一个变量来代替index
。也许这个?
$indexa = mysql_query("select site FROM {$row['TABLE_NAME']} order by createdatetime desc limit 25");
但是,嗯..。你干吗呢?我不知道你到底想达到什么目的,但我脑子里响起了非常响亮的警钟。在查询中使用动态表名是一个主要的危险标志,是数据库设计不善的标志。
My数据库有可变数量的表,它们都具有相同的结构。
那可不好。
这些桌子里有什么?让我们帮助您将所有这些数据放到一个表中。
最简单的方法是创建一个包含当前存储每一行表名称的额外列的单个表。不要让表"foo“、"bar”和"baz",而是创建一个包含"foo“、"bar”或"baz“作为字符串值的列。
发布于 2009-10-31 06:17:19
查询
select site FROM index order by createdatetime desc limit 25
不应该起作用。"index“是一个保留词。
您想在那里使用$row‘’TABLE_NAME‘吗?
$indexa = mysql_query("select site FROM " + $row['TABLE_NAME'] + " order by createdatetime desc limit 25");
发布于 2009-10-31 06:17:02
您的内部查询与外部查询无关,您可能会尝试以下操作
<?php
echo "<table class=\"samples\">";
$index = mysql_query("select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='jammulinks'");
while ($row = mysql_fetch_row($index))
{
$indexa = mysql_query("select site FROM $row[0] order by createdatetime desc limit 25");//assuming you have site and createddatetime column there.
while ($rowa = mysql_fetch_array($indexa))
{
echo '<tr><td><a href="sitelookup3.php?entry='.urlencode($rowa['site']).'&searching=yes&search=search">'.$rowa['site'].'</a></td></tr>';
}
}
echo "</table>";
?>
https://stackoverflow.com/questions/1653566
复制相似问题