dongzhang7961 2015-03-22 13:32 采纳率: 0%
浏览 406
已采纳

WHERE子句中的多个查询

Struggling with this one.. my sql query works in PHP myAdmin but not on the page..

The url: http://www.copleycaravanservices.co.uk/Caravans.php?room_id=1&foreign_id=1 There is also another query which works for the room_id section of the url

The code that isnt working:

<?php
require_once('db_config.php');
mysql_select_db($dbname, $db);
$sql1 = "SELECT * FROM  `SS_hotel_booking_multi_lang` 
WHERE  `foreign_id` = " . $_GET['foreign_id'] . "
AND  `locale` = '1'
AND  `field` =  'description'
AND  `source` =  'data'";
$result1 = mysql_query($sql1, $db) or die(mysql_error());
$CaravanDesc = mysql_fetch_assoc($result1);
?>

The database: (Hope this displays correctly!)

id  foreign_id  model   locale  field   content              source
7365    1       pjRoom    1     name    Promenade 654          data
7366    1       pjRoom    1  description This caravan sleeps 6 data
7371    2       pjRoom    1     name    Butlins Sandhills 14   data
7372    2       pjRoom    1  description 4 Day Passes included data
  • 写回答

1条回答 默认 最新

  • duankui6150 2015-03-22 15:26
    关注

    I think this should be done like this try by removing quotes of column name

     <?php
        require_once('db_config.php');
        mysql_select_db($dbname, $db);
        $sql1 = "SELECT * FROM  `SS_hotel_booking_multi_lang` 
        WHERE  foreign_id = " . $_GET['foreign_id'] . "
        AND  locale = '1'
        AND  field =  'description'
        AND  source =  'data'";
        $result1 = mysql_query($sql1, $db) or die(mysql_error());
        $CaravanDesc = mysql_fetch_assoc($result1);
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog