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

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

图片转代码服务由CSDN问答提供 功能建议

在这个问题上苦苦挣扎..我的SQL查询在PHP myAdmin中运行,但不在页面上..

网址: http:/ /www.copleycaravanservices.co.uk/Caravans.php?room_id=1&foreign_id=1 还有另一个查询适用于网址的room_id部分

不起作用的代码:

 &lt;?php 
require_once('db_config.php'); 
mysql_select_db($ dbname,$ db); 
 $ sql1 =  “SELECT * FROM`SS_hotel_booking_multi_lang` 
WHERE`external_id` =”。  $ _GET ['foreign_id']。  “
AND`locale` ='1'
AND`field` ='description'
AND`source` ='data'”; 
 $ result1 = mysql_query($ sql1,$ db)或die(mysql_error())  ; 
 $ CaravanDesc = mysql_fetch_assoc($ result1); 
?&gt; 
   
 
 

数据库:(希望这显示正确!)

  id foreign_id model locale field content source 
7365 1 pjRoom 1 name Promenade 654 data 
7366 1 pjRoom 1 description此大篷车可睡6个数据
7371 2 pjRoom 1 name Butlins Sandhills 14 data 
7372 2 pjRoom 1 说明4天通行证包括数据
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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);
        ?>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题