我对php比较新,我正在转移我写给OOP的搜索引擎。
相关SQL连接代码/ sqlconnect1类:
public function query($query){
$this->stmt = $this->dbh->prepare($query);
}
public function bind($param, $value, $type = null){
if (is_null($type)) {
switch (true) {
case is_int($value):
$type = PDO::PARAM_INT;
break;
case is_bool($value):
$type = PDO::PARAM_BOOL;
break;
case is_null($value):
$type = PDO::PARAM_NULL;
break;
default:
$type = PDO::PARAM_STR;
}
}
$this->stmt->bindValue($param, $value, $type);
}
public function execute(){
return $this->stmt->execute();
}
public function resultset(){
$this->execute();
return $this->stmt->fetch(PDO::FETCH_ASSOC);
}
while loop:
$search = new LoadSearch;
$sqlconnect1 = new sqlconnect1;
$sqlconnect1->query("SELECT * FROM data1 WHERE address_city LIKE 'austin' AND address_zip LIKE '78758'");
//Assign Variables and Display Record Results
while ($row1 = $sqlconnect1->resultset()){
$Name1=$row1['name'];
$Address1=$row1['address_1'];
$City1=$row1['address_city'];
$State1=$row1['address_state'];
$ZIP1=$row1['address_zip'];
$Country1=$row1['address_country'];
$Phone1=$row1['phone'];
$Website1=$row1['website'];
$Category_11=$row1['category_1'];
$Category_21=$row1['category_2'];
echo"
<!--Table 2-->
<table class='table2'>
<tr>
<td></td><td><b>$Name1</b></td>
</tr>
<tr>
<td></td><td>$Address1, $City1, $State1 $ZIP1</td>
</tr>
<tr>
<td></td><td>$Country1</td>
</tr>
<tr>
<td></td><td>$Phone1</td>
</tr>
<tr>
<td></td><td>$Category_11</td>
</tr>
</table>";
每当加载页面时,它会无限期地重复第一个查询结果,并且永远不会超出第一个结果。任何建议将不胜感激。当程序化时,类似的设置工作正常。