我通过php脚本一次将50条记录插入到数据库中。 但它在插入时会跳过2-3条记录。有什么问题?
请帮忙!
我想LIMIT
中存在一些问题。请检查任何人,并告诉我们!
以下是代码:
<?php
include_once 'db.php';
$selTable = "select * from dump_hotelbasicinfo LIMIT 50";
$resultTable = mysql_query($selTable, $conn);
while($rowTable = mysql_fetch_array($resultTable))
{
echo "<br> <strong> Hotel ID </strong> : " .$rowTable['id'];
echo "<br> <strong> Hotel Name </strong>: " .$rowTable['HotelName'];
echo "<br> <strong> Hotel Code </strong>: " .$rowTable['HotelCode'];
echo "<br> <strong> Chain Code </strong>: " .$rowTable['ChainCode'];
echo "<br> <strong> Hotel Type </strong>: " .$rowTable['HotelType'];
echo "<br> <strong> Hotel Category </strong>: " .$rowTable['HotelCategory'];
echo "<br> <strong> Hotel Style </strong>: " .$rowTable['HotelStyle'];
echo "<br> <strong> Hotel Theme </strong>: " .$rowTable['HotelTheme'];
echo "<br> <strong> Rating </strong>: " .$rowTable['StarRating'];
echo "<br> <strong> Destination Name </strong>: " .$rowTable['DestinationName'];
echo "<br> <strong> Country Name </strong>: " .$rowTable['CountryName'];
echo "<br> <strong> Hotel Info </strong>: " .$rowTable['HotelInfo'];
echo "<br> <strong> Number of Floors </strong>: " .$rowTable['NumFloors'];
echo "<br> <strong> Number of Rooms </strong>: " .$rowTable['NoOfRooms'];
echo "<br> <strong> DateTime </strong>: " .$rowTable['datetimespan'];
echo "<hr>";
$sqlInsert="INSERT INTO `hotel_info`
(`property_name` ,
`property_town` ,
`property_country` ,
`property_description`,
`published` ,
`stars` ,
`ptype_id` ,
`last_changed`
)
VALUES
('$rowTable[HotelName]' , '$rowTable[DestinationName]' , '$rowTable[CountryName]', ' $rowTable[HotelInfo]','1' ,
'$rowTable[StarRating]' , '1','$rowTable[datetimespan]')";
//echo $sqlInsert;
//exit();
$resultInsert = mysql_query($sqlInsert);
}
?>
答案 0 :(得分:0)
可能你在插入查询中有错误打印sql代码并检查查询是否正确。
//...
echo $sqlInsert;
//exit();
答案 1 :(得分:0)
由于您没有转义任何输入字符串,因此极有可能在某些表(可能是属性名称)中包含撇号(&#39;)或任何其他受限制的字符,从而阻止您插入该特定查询。 例如,如果城市坎贝尔湾,它将不会在没有首先逃避撇号的情况下插入。
不要使用mysql _ 函数,因为它们已被弃用,请改用mysqli_ * *