ช่วยดู code ให้หน่อยครับ

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderators: mindphp, ผู้ดูแลกระดาน

User avatar
ICrazyBoy
PHP Jr. Member
PHP Jr. Member
Posts: 10
Joined: 01/01/1970 7:00 am

ช่วยดู code ให้หน่อยครับ

Post by ICrazyBoy » 25/02/2008 10:59 pm

ช่วยดู code ให้หน่อยครับ ว่ามันผิดตรงไหน มันไม่แสดงผลครับ ช่วยหน่อยครับ
มันบอกว่า

Please select list for search
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\-----------\search_result.php on line 192


//search_from.php

<form method="post" action="search_result.php" name="searchresult" id="searchresult">
<div id="userPw">
<fieldset><legend><b>Search Form</b></legend>
<br />

<b>Step 1 </b><br />

<!-- Type of Properties....-->

Type &nbsp;&nbsp;:<br />
<select name="type" id="type" onchange="location.href='search_form.php?class_id='+this.value;">
<option value="">---- Select Type of Properties ----</option>
<?

$sql_type = "select * from bkkapart_en_class order by class_rank";
$dbquery_type = mysql_db_query($dbname,$sql_type);
while ($result_type = mysql_fetch_array($dbquery_type))
{
if($class_id == $result_type[class_id])
{
?>
<option value="<?=$result_type[class_id];?>" selected="selected"><?=$result_type[class_name];?></option>
<?
}else{ ?>
<option value="<?=$result_type[class_id];?>"><?=$result_type[class_name];?></option>

<?
}
}


?>
</select><br />

<!-- End Type of Properties.... -->

<b>Step 2</b><br />

<!-- City.... -->

City &nbsp;&nbsp;:<br />
<select name="$select_city" id="select_city">
<option value="">---- Select City ----</option>
<?


if($class_id != "")
{

$sql_city = "SELECT distinct lde.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements lde, bkkapart_classlistingsdb cld
WHERE lde.listingsdbelements_field_name = 'city' and lde.listingsdb_id = cld.listingsdb_id and cld.class_id = '$class_id'
ORDER BY listingsdbelements_field_value";
$dbquery_city = mysql_db_query($dbname,$sql_city);
while($result_city = mysql_fetch_array($dbquery_city))
{

?>
<option value="<?=$result_city[listingsdbelements_field_value];?>"><?=$result_city[listingsdbelements_field_value];?></option>
<?
}
}

?>

</select><br />



<!-- End City.... -->


<!-- Area.... -->

Area &nbsp;:<br />
<select name="select_Area" id="select_Area">
<option value="">------ Select Area -----</option>
<?



if($class_id != "")
{

$sql_Area = "SELECT distinct lde.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements lde, bkkapart_classlistingsdb cld
WHERE lde.listingsdbelements_field_name = 'Area' and lde.listingsdb_id = cld.listingsdb_id and cld.class_id = '$class_id'
ORDER BY listingsdbelements_field_value";
$dbquery_Area = mysql_db_query($dbname,$sql_Area);
while($result_Area = mysql_fetch_array($dbquery_Area))
{

?>

<option value="<?=$result_Area[listingsdbelements_field_value];?>"><?=$result_Area[listingsdbelements_field_value];?></option>

<?
}
}

?>

</select><br />

<!-- End Area.... -->



<!-- Beds.... -->

Beds &nbsp;:<br />
<select name="select_beds" id="select_beds">
<option value="">--- Select Bed ---</option>
<?



if($class_id != "")
{

$sql_beds = "SELECT distinct lde.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements lde, bkkapart_classlistingsdb cld
WHERE lde.listingsdbelements_field_name = 'beds' and lde.listingsdb_id = cld.listingsdb_id and cld.class_id = '$class_id'
ORDER BY listingsdbelements_field_value";
$dbquery_beds = mysql_db_query($dbname,$sql_beds);
while($result_beds = mysql_fetch_array($dbquery_beds))
{
?>

<option value="<?=$result_beds[listingsdbelements_field_value];?>"><?=$result_beds[listingsdbelements_field_value];?></option>

<?
}

}

?>

</select> <br />

<!-- End Beds.... -->


<!-- Price.... -->
Prices :<br />
<select name="select_minPrice" id="select_minPrice">
<option value="">---- Min Prices ----</option>
<?



if($class_id != "")
{

$sql_minPrice = "SELECT distinct lde.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements lde, bkkapart_classlistingsdb cld
WHERE lde.listingsdbelements_field_name = 'price' and lde.listingsdb_id = cld.listingsdb_id
and cld.class_id = '$class_id'
ORDER BY listingsdbelements_field_value";
$dbquery_minPrice = mysql_db_query($dbname,$sql_minPrice);
while($result_minPrice = mysql_fetch_array($dbquery_minPrice))
{
?>
<option value="<?=$result_minPrice[listingsdbelements_field_value];?>"><?= number_format($result_minPrice[listingsdbelements_field_value],0,',',',')." ". "Thb";?> </option>
<?
}
}


?>

</select><br />


<select name="select_maxPrice" id="select_maxPrice">
<option value="">---- Max Prices ---</option>
<?


if($class_id != "")
{

$sql_maxPrice = "SELECT distinct lde.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements lde, bkkapart_classlistingsdb cld
WHERE lde.listingsdbelements_field_name = 'price' and lde.listingsdb_id = cld.listingsdb_id
and cld.class_id = '$class_id'
ORDER BY listingsdbelements_field_value";
$dbquery_maxPrice = mysql_db_query($dbname,$sql_maxPrice);
while($result_maxPrice = mysql_fetch_array($dbquery_maxPrice))
{
?>
<option value="<?=$result_maxPrice[listingsdbelements_field_value];?>"><?= number_format($result_maxPrice[listingsdbelements_field_value],0,',',',')." ". "Thb";?> </option>
<?
}
}


?>

</select><br /><br />

<!-- End Price....-->

<input type="submit" class="button"value="Search" />
<input type="reset" class="button" value="Reset" />




</fieldset>
</div>

</form>


----------------------------------------------------------------------------------------
//Search_result.php

<?


if($result_city[listingsdbelements_field_value] !="")

{


$sql = "SELECT DISTINCT a.listingsdb_id,(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'city'
AND b.listingsdb_id = a.listingsdb_id) AS fcity,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'Area'
AND b.listingsdb_id = a.listingsdb_id) AS fArea,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'beds'
AND b.listingsdb_id = a.listingsdb_id) AS fbeds,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'price'
AND b.listingsdb_id = a.listingsdb_id) AS fprice,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'home_features'
AND b.listingsdb_id = a.listingsdb_id) AS ffeatures,
c.listingsdb_title AS ftitle,
d.listingsimages_thumb_file_name AS fpicture

FROM bkkapart_en_listingsdbelements a, bkkapart_en_listingsdb c, bkkapart_en_listingsimages d
WHERE c.listingsdb_id = a.listingsdb_id
AND a.listingsdb_id = '$result_city[listingsdbelements_field_value]'
AND c.listingsdb_id = d.listingsdb_id
AND d.listingsimages_rank = '1' ";

} elseif($result_Area[listingsdbelements_field_value] !="")
{

$sql = "SELECT DISTINCT a.listingsdb_id,(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'city'
AND b.listingsdb_id = a.listingsdb_id) AS fcity,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'Area'
AND b.listingsdb_id = a.listingsdb_id) AS fArea,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'beds'
AND b.listingsdb_id = a.listingsdb_id) AS fbeds,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'price'
AND b.listingsdb_id = a.listingsdb_id) AS fprice,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'home_features'
AND b.listingsdb_id = a.listingsdb_id) AS ffeatures,
c.listingsdb_title AS ftitle,
d.listingsimages_thumb_file_name AS fpicture

FROM bkkapart_en_listingsdbelements a, bkkapart_en_listingsdb c, bkkapart_en_listingsimages d
WHERE c.listingsdb_id = a.listingsdb_id
AND a.listingsdb_id = '$result_Area[listingsdbelements_field_value]'
AND c.listingsdb_id = d.listingsdb_id
AND d.listingsimages_rank = '1' ";

} elseif($result_beds[listingsdbelements_field_value] != "")
{

$sql = "SELECT DISTINCT a.listingsdb_id,(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'city'
AND b.listingsdb_id = a.listingsdb_id) AS fcity,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'Area'
AND b.listingsdb_id = a.listingsdb_id) AS fArea,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'beds'
AND b.listingsdb_id = a.listingsdb_id) AS fbeds,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'price'
AND b.listingsdb_id = a.listingsdb_id) AS fprice,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'home_features'
AND b.listingsdb_id = a.listingsdb_id) AS ffeatures,
c.listingsdb_title AS ftitle,
d.listingsimages_thumb_file_name AS fpicture

FROM bkkapart_en_listingsdbelements a, bkkapart_en_listingsdb c, bkkapart_en_listingsimages d
WHERE c.listingsdb_id = a.listingsdb_id
AND a.listingsdb_id = '$result_beds[listingsdbelements_field_value]'
AND c.listingsdb_id = d.listingsdb_id
AND d.listingsimages_rank = '1' ";


}elseif($result_minPrice[listingsdbelements_field_value] != "" && $result_maxPrice[listingsdbelements_field_value] != "")
{

$sql_minPrice = "SELECT DISTINCT a.listingsdb_id,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'price'
AND b.listingsdb_id = a.listingsdb_id) AS min_price
FROM bkkapart_en_listingsdbelements a
WHERE a.listingsdb_id = '$result_minPrice[listingsdbelements_field_value]' ";

$sql_maxPrice = "SELECT DISTINCT a.listingsdb_id,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'price'
AND b.listingsdb_id = a.listingsdb_id) AS max_price
FROM bkkapart_en_listingsdbelements a
WHERE a.listingsdb_id = '$result_minPrice[listingsdbelements_field_value]'";



$sql = "SELECT DISTINCT a.listingsdb_id,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'city'
AND b.listingsdb_id = a.listingsdb_id) AS fcity,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'Area'
AND b.listingsdb_id = a.listingsdb_id) AS fArea,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'beds'
AND b.listingsdb_id = a.listingsdb_id) AS fbeds,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'price'
AND b.listingsdb_id = a.listingsdb_id and
b.listingsdbelements_field_value BETWEEN '$sql_minPrice' and '$sql_minPrice') AS fprice,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'home_features'
AND b.listingsdb_id = a.listingsdb_id) AS ffeatures,
c.listingsdb_title AS ftitle,
d.listingsimages_thumb_file_name AS fpicture

FROM bkkapart_en_listingsdbelements a, bkkapart_en_listingsdb c, bkkapart_en_listingsimages d
WHERE c.listingsdb_id = a.listingsdb_id
AND a.listingsdb_id = '$result_price[listingsdbelements_field_value]'
AND c.listingsdb_id = d.listingsdb_id
AND d.listingsimages_rank = '1' ";

} else
{

echo"Please select list for search";

}



$db_query = mysql_db_query($sql,$dbname);
$num_rows = mysql_num_rows($db_query);

$a=0;
while($a < $num_rows)
{
$result = mysql_fetch_array($db_query);
$title = $result['ftitle'];
$city = $result['fcity'];
$area = $result['fArea'];
$beds = $result['fbeds'];
$price = $result['fprice'];
$features = $result['ffeatures'];
$picture = $result['fpicture'];



echo"<br>";
echo"<div style='padding: 1px;'>
<div style='float:left; width: 255px; height:180px; border: 1px solid;'>
<div style='float:left; width: 254px; height:20px; border: 1px solid;'><font size = 2>$title</font></div>
<div style='float:left; width: 90px; height:140px; border: 0px solid;'><font size = 2><img src = $picture></font></div>
<div style='float:left; width: 163px; height:140px; border: 0px solid;'>

<div style='float:left; width: 163px; height: 20px;'><font size = 2><b>city</b> : $city</font></div>
<div style='float:left; width: 163px; height: 20px;'><font size = 2><b>area</b> : $area</font></div>
<div style='float:left; width: 163px; height: 20px;'><font size = 2><b>price</b> : $price</font></div>
<div style='float:left; width: 163px; height: 80px;'><font size = 2><b>features</b> : <br>$features</font></div>
</div>
<div style='float:left; width: 255px; height:20px; border: 0px solid;'>
<div style='float:right; width: 50px; height: 20px;'><font size = 1><a href='contact.php'>Contact</a></font></div>
<div style='float:right; width: 70px; height: 20px;'><font size = 1><a href='#'>Bookmark</a></font></div>
<div style='float:right; width: 45px; height: 20px;'><font size = 1><a href='#'>Detail</a></font></div>
</div>

</div>

</div><br><br><br><br><br><br><br><br><br><br><br>";


$a++;

}

?>


ช่วยหน่อยนะครับ ผมเพิ่งหัดเขียน ยังไม่ถึงไหนเลย โง่ก็โง่....ขอบคุณคร๊าบบบ...
Last edited by ICrazyBoy on 26/02/2008 12:38 am, edited 2 times in total.

User avatar
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
Posts: 22325
Joined: 22/09/2008 6:18 pm
Contact:

Post by mindphp » 25/02/2008 11:14 pm

ลองดูเช็ค คำสั่ง sql ก่อนหน้า line 192
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042

User avatar
ICrazyBoy
PHP Jr. Member
PHP Jr. Member
Posts: 10
Joined: 01/01/1970 7:00 am

Post by ICrazyBoy » 25/02/2008 11:53 pm

หะๆ ไม่รู้ว่าตรงไหน ช่วยดูหน่อยนะคร๊าบบบ..มืดแปดด้านแล้ว หาอยู่หลาย ชม แล้วครับ ...ขอบตุณครับ

User avatar
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
Posts: 22325
Joined: 22/09/2008 6:18 pm
Contact:

Post by mindphp » 26/02/2008 12:06 am

ลองดูเช็ค คำสั่ง sql ก่อนหน้า line 192
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042

User avatar
ICrazyBoy
PHP Jr. Member
PHP Jr. Member
Posts: 10
Joined: 01/01/1970 7:00 am

Post by ICrazyBoy » 26/02/2008 12:31 am

ผมลองไล่ sql ดู แล้วลอง test กับ phpminadmin ดู มันขึ้นว่า

Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in C:\AppServ\www\phpMyAdmin\libraries\common.lib.php on line 2146

Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in C:\AppServ\www\phpMyAdmin\libraries\common.lib.php on line 2147

แต่ผลมันก้ออกตามที่ต้องการจะครับ ผมไม่ทราบว่ามันมีผลกับที่มันบอกว่า

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\---------------\search_result.php on line 192

หรือเปล่าครับ..ขอบคุณครับ

Post Reply

Return to “Programming - PHP”

Who is online

Users browsing this forum: Bing [Bot] and 23 guests