如果可能的话,给予一点帮助。我有一个来自两个数据表(MySQL)的页面,一个函数提供空结果。
function ShowClient() {
global $agent;
$sql = 'SELECT * FROM nuke_bulletins WHERE user=\'' . $agent . '\' AND isActive="Y" ORDER BY id';
$client = mysql_query($sql) or die('ERROR: OOPS Something went wrong' . mysql_error());
echo '<center><p><b>Current Campaigns</b></p>';
// Pull the loop and display the data
while($row = mysql_fetch_array($client)) {
$agent = stripslashes($row['user']);
$campaign = stripslashes($row['id']);
$title = stripslashes($row['title']);
echo '<p><a href="bullies2.php?op=ShowCampaign&id=' . $campaign . '"><b>' . $title . '</b></a></p>';
}
echo '<p>Click the Campaign Title to get the Bulletin Code</p><p> </p>';
echo '<p align="center"><a href="bullies2.php"><b>Return to All Client\'s</a></p>';
}
$ agent变量是从主函数中提取的,该函数根据用户($ agent)创建一个url。
我在这里做错了什么?
答案 0 :(得分:0)
$ agent是一个全局变量。使用全局变量通常被认为是不好的做法,因为在调用此函数之前,可能会在某处设置或取消设置。
您是否检查过PHP错误日志以查看是否收到任何错误?
如果日志中没有错误,我会查看$ agent是否通过回显到屏幕(如果是dev环境)或者将值转储到错误日志文件中来查看它是否实际包含任何内容。 http://www.php.net/manual/en/function.error-log.php
然后我会看看SQL本身;您的表nuke_bulletins中的列标题是否与$ row数组键完全匹配,例如它们是否相同?
$row['title']
或
$row['Title']
答案 1 :(得分:0)
我们走了......
$agent
)。可怕的想法。or die
必须死〜http://www.phpfreaks.com/blog/or-die-must-die echo
。制作意大利面条代码我的建议是使用 mysqli 扩展程序
function getCampaigns(mysqli $con, $agent) {
if (!$stmt = $con->prepare("SELECT id, title FROM nuke_bulletins WHERE user = ? AND isActive = 'Y' ORDER BY id")) {
throw new Exception($con->error, $con->errno);
}
$stmt->bind_param('s', $agent); // if the user column is a integer, use 'i' instead
if (!$stmt->execute()) {
throw new Exception($stmt->error, $stmt->errno);
}
$stmt->bind_result($id, $title);
$campaigns = []; // or array() if you're on PHP < 5.4
while ($stmt->fetch()) {
$campaigns[$id] = $title;
}
return $campaigns;
}
现在你可以像这样调用这个函数......
<?php
// assuming you have a mysqli instance in a $con variable, eg $con = new mysqli(...)
// and an $agent variable
$campaigns = getCampaigns($con, $agent);
?>
<p><strong>Current Campaigns</strong></p>
<?php foreach ($campaigns as $id => $title) : ?>
<p>
<a href="bullies2.php?op=ShowCampaign&id=<?= $id ?>">
<strong><?= htmlspecialchars($title) ?></strong>
</a>
</p>
<?php endforeach ?>
<p>Click the Campaign Title to get the Bulletin Code</p>
<p> </p>
<p align="center"><a href="bullies2.php"><strong>Return to All Client's</strong></a></p>
而且,与往常一样,您的开发环境应在php.ini
文件
display_errors = On
error_reporting = E_ALL