我正在創建一個存儲諸如地址,城市等家庭信息的網站。我獲得了上傳到數據庫部分的工作,並且我搜索了數據庫並顯示了完成的信息。帶有PHP動作的HTML鏈接
但現在我的計劃是你得到的搜索結果,並從那裏你可以選擇通過鏈接查看該家的完整檔案。使用從數據庫收集的信息顯示完整的配置文件已通過單獨的php文件完成。現在,當我鏈接php文件時,它只會顯示數據庫中的最後一列。我如何鏈接它,所以當我點擊「查看完整個人資料」時,它將連接到與不同地址或價格對應的正確數據/個人資料。或者,如果我不能使用HTML鏈接我可以使用什麼?這是不可能的嗎?
這裏是一個顯示搜索結果的代碼,我已經成功地能夠搜索數據庫並顯示它
<?php
if($sql->num_rows){
while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
echo '<div id="listing">
<div id="propertyImage">
<img src="images/'.$row['imageName1'].'" width="200" height="150" alt=""/>
</div>
<div id="basicInfo">
<h2>$'.$row['Price'].'</h2>
<p style="font-size: 18px;"># '.$row['StreetAddress'].', '.$row['City'].', BC</p>
<p>'.$row['NumBed'].' Bedrooms | '.$row['NumBath'].' Bathrooms | '.$row['Property'].'</p>
<br>
<p><a href="outputtest.php" class="link2">View Full Details</a> | <a href="services/services.html" class="link2">Get Directions</a>
</div>
</div>';
height="150" alt=""/>';
}
}
else
{
echo '<h2>0 Search Results</h2>';
}
?>
這裏是顯示outputtest.php信息的PHP
<?php
mysql_connect("localhost","root","31588patrick");
@mysql_select_db("test") or die("Unable to select database");
$query="SELECT * FROM propertyinfo";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$varStreetAddress=mysql_result($result,$i,"StreetAddress");
$varCity=mysql_result($result,$i,"City");
$varProperty=mysql_result($result,$i,"Property");
$varNumBed=mysql_result($result,$i,"NumBed");
$varNumBath=mysql_result($result,$i,"NumBath");
$varPrice=mysql_result($result,$i,"Price");
$varEmail=mysql_result($result,$i,"Email");
$varPhone=mysql_result($result,$i,"Phone");
$varUtilities=mysql_result($result,$i,"utilities");
$varTermLease=mysql_result($result,$i,"TermLease");
$varNotes=mysql_result($result,$i,"Notes");
$image1=mysql_result($result,$i,"imageName1");
$image2=mysql_result($result,$i,"imageName2");
$image3=mysql_result($result,$i,"imageName3");
$image4=mysql_result($result,$i,"imageName4");
$i++;
}
?> html code will go after this
謝謝
編輯其工作
<?php
////////////using mysqli to connect with database
$mysqli = new mysqli("localhost","root","31588patrick", "test");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
///////////set variables
$record_id = $_GET['record_id'];
$sql = $mysqli->query("select * from propertyinfo where StreetAddress like '%$record_id%'");
if($sql === FALSE) {
die(mysql_error()); // TODO: better error handling
}
if($sql->num_rows){
while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
$varStreetAddress=$row['StreetAddress'];
$varCity=$row['City'];
$varProperty=$row['Property'];
$varNumBed=$row['NumBed'];
$varNumBath=$row['NumBath'];
$varPrice=$row['Price'];
$varEmail=$row['Email'];
$varPhone=$row['Phone'];
$varUtilities=$row['utilities'];
$varTermLease=$row['TermLease'];
$varNotes=$row['Notes'];
$image1=$row['imageName1'];
$image2=$row['imageName2'];
$image3=$row['imageName3'];
$image4=$row['imageName4'];
}
}
是的,那是可能的。 – Heavy
代碼價值1000字。 – vikingben
試着簡化你的問題,你會得到更快的答案 – thwildfire