无法从数据库中获取信息

时间:2013-03-06 08:49:32

标签: php mysql

我最近开始学习PHP,我通过dreamweaver创建了以下查询。

enter code here
<?php

if (!function_exists("GetSQLValueString")) {

    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
        if (PHP_VERSION < 6) {
            $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
        }

        $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

        switch ($theType) {
            case "text":
                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                break;
            case "long":
            case "int":
                $theValue = ($theValue != "") ? intval($theValue) : "NULL";
                break;
            case "double":
                $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
                break;
            case "date":
                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                break;
            case "defined":
                $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
                break;
        }
        return $theValue;
    }

}

mysql_select_db($database_PMS, $PMS);
$query_rs_home = "SELECT * FROM hotelinfo, hotelslider WHERE hotelinfo.hotelid=hotelslider.id";
$rs_home = mysql_query($query_rs_home, $PMS) or die(mysql_error());
$row_rs_home = mysql_fetch_assoc($rs_home);
$totalRows_rs_home = mysql_num_rows($rs_home);
?>

如果我使用此代码,我只获得数据库的第一条记录。我没有得到进一步的记录。

请帮助我。

2 个答案:

答案 0 :(得分:1)

使用:

while($row_rs_home = mysql_fetch_assoc($rs_home)){
 //do something
}

答案 1 :(得分:0)

mysql_select_db($database_PMS, $PMS);
 $query_rs_home = "SELECT * FROM hotelinfo, hotelslider WHERE hotelinfo.hotelid=hotelslider.id";
 $rs_home = mysql_query($query_rs_home, $PMS) or die(mysql_error());

while($rows= mysql_fetch_array($rs_home)){
 echo $rows['field_name'];//this will print your db record
}