PHP/mySQL : mysql_query with SELECT, 来源和地点

标签 php mysql select where fetch

我正在尝试使用以下代码设置 $nextPageID$nextPageTitle。不幸的是,他们没有得到设置。

$pageCategoryID = 1;
$nextPageOrder = 2;

$fetchedNextPageData = mysql_query("
  SELECT pageID, pageCategoryID, 'order', title 
  FROM pages 
  WHERE pageCategoryID='$pageCategoryID' AND 'order'='$nextPageOrder'
") or die(mysql_error());

            while ($nextPageArray = mysql_fetch_array($fetchedNextPageData)) {
                $nextPageID = $nextPageArray['pageID'];
                $nextPageTitle = $nextPageArray['title'];
            }

我的表 pages 包含 pageID = 2、pageCategoryID = 1、order = 2、title = Next Page 的行,以及其他 4 个包含我不需要此查询的数据的列。

出于测试目的,此代码已被简化。它会在我开始工作后进行 sanitizer 。

关于如何让这段代码正常工作,我有什么想法吗?

最佳答案

你正在覆盖每条记录的变量,也许创建一个像这样的数组

 $data = array();
 while ($nextPageArray = mysql_fetch_assoc($fetchedNextPageData)) {
   $data[] = array('id' => $nextPageArray['pageID'], 
            'title' => $nextPageArray['title']);
 }

关于PHP/mySQL : mysql_query with SELECT, 来源和地点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8272673/

相关文章:

php - 内连接选择语句

javascript - 在 codeIgniter 中使用单个表进行动态下拉

php - 从 file_get_contents 请求获取 IP

mysql - 如何让 BreezeJS 使用 Angular + Node 与 MySQL DB 对话?

php - 我在日志中遇到错误,但是脚本可以满足我的要求

php - 选择select中的所有选项

php - 使用 Propel 强制数据库刷新

php - 同时在服务器和用户上下载

mysql - 增加多个时间戳值

sql - 使用CTE在SQL中生成测试数据