0

我最近开始学习 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);
?>

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

请帮助我的人。

4

2 回答 2

1

利用:

while($row_rs_home = mysql_fetch_assoc($rs_home)){
 //do something
}
于 2013-03-06T08:51:10.400 回答
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
}
于 2013-03-06T08:57:13.537 回答