 |
สอบถามเกี่ยวกับ BETWEEN ค้นหาตามช่วงราคาครับ ต้องเขียนfrom ยังไง |
|
 |
|
|
 |
 |
|
Code (PHP)
ตามนี้เลยครับ ท่านต้องไปศึกษาการส่งค่าระหว่างฟอร์ม ก่อนนะครับ ถึงจะเข้าใจ
txtprice1 name price1
txtprice2 name price2
แล้วก็ Action มายังฟอร์ม
searchprice.php
ถ้าไม่เข้าใจไปหาบทความ
$eid=$_GET[search];
$_GET['price1']
$_GET['price2']
ศึกษาได้จากที่นี้ครับ https://www.thaicreate.com/php/php-predefined-variables.html
|
 |
 |
 |
 |
Date :
2013-02-27 13:30:50 |
By :
prachaporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Prachaporn ขอบคุณมากเลยครับ แต่ก็ยังไปไม่เป็นอยู่อะครับ ยังไม่แน่ใจที่ผมเขียนตัว รับถูกรึยังแล้ว ผมเขียนตัวfrom ไม่ถูกอยู่ดีอะครับ ช่วยเขียวfrom ให้ดูหน่อยได้มั้ยครับจะเป็นพระคุณมากเลย
|
 |
 |
 |
 |
Date :
2013-02-27 13:47:58 |
By :
vanavat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
include'config.inc.php';
$eid=$_GET[search];
$sql = "select * from tb_newstravel where n_copy BETWEEN '".$_GET['price1']."' and '".$_GET['price2']."' "; //คำสั่ง Sql ที่ใช้
//$sql = "select * from $tblname where $field_search like '%$search%'";
$rs=mysql_query($sql);
$num_rows = mysql_num_rows($rs);
if($num_rows==''){
echo "ยังไม่มีเนื้อหาที่เกี่ยวข้อง";
}
$cols =1; //
$c = $cols;
echo "<form name=\"form1\" method=\"post\" action=\"\">";
echo"<table border=0>";
echo" <tr>";
while ($result=mysql_fetch_array($rs)){
$c --;
$r=$d[type_web_id];
#ถ้า หัวข้อกระทู้ ยาวเกินให้ตัดออก
$da1 = substr_utf8($result[n_topic],0,200) . "...";
$da2 = substr_utf8($result[n_title],0,150) . "...";
$da3=eregi_replace(" ", "-", $result[n_topic]);
echo" <td width= >";
if($result[n_image]==""){
echo"<default><img src=$siteurl/images/noimages.jpg width=125 height=150 class='reflect'></default>";
} else {
echo"<a href=Product-$result[n_id]-$da3.html alt='รองเท้าแฟชั่นเกาหลี $da3' target='_blank'><img src=$siteurl/images/news/$result[n_image] alt='รองเท้าแฟชั่นเกาหลี $da3' width=125 height=150 border=0></default></a>";
}
echo"</td><td width=100% valign=top>";
echo"<a href=Product-$result[n_id]-$da3.html alt='รองเท้าแฟชั่นเกาหลี $da3' target='_blank'><font class=head-line>$da1</font> </a> ";
echo"<br/>$da2";
?>
<br/>
<img src="images/time.gif"><font class="time_update"><?=ThaiDatesale($result[a_date]);?></font>
<?
echo" <img src=images/icon/stat.gif><font class='time_update'>$result[pageview] ผุ้เข้าชม</font><br />";
$tags_select = mysql_query("SELECT name FROM `tags` WHERE `topicid`=".$result['n_id']." ") or die(mysql_error());
while($tags_topic = mysql_fetch_array($tags_select)){
echo "<a href=\"tag.php?tag=".$tags_topic['name']."\"> ".$tags_topic['name']."</a>,</font>";
}
echo"</td>";
if($c == 0) {
$c = $cols;
echo" </tr></tr>";
} }
echo"</tr></table>";
echo "</form>";
?>
|
 |
 |
 |
 |
Date :
2013-02-27 13:55:05 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดันหน่อยครับอยากได้ form ส่งอะครับ
|
ประวัติการแก้ไข 2013-02-27 16:24:19 2013-02-27 16:24:29
 |
 |
 |
 |
Date :
2013-02-27 15:29:34 |
By :
vanavat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="get" action="searchprice.php">
<table width="424" border="1" align="center">
<tr>
<td width="212">price1
<label>
<input name="price1" type="text" id="price1" />
</label></td>
<td width="207">price2
<label>
<input name="price2" type="text" id="price2" />
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center"> <br />
<input name="btok" type="submit" id="btok" value="ตกลง" />
</div></label></td>
</tr>
</table>
</form>
</body>
</html>
Copy ไปวางใส่ในไฟล์ PHP ที่สร้างขึ้น ลบ Code ที่มีอยู่ทั้งหมดออกแล้วก็วางลงไป Save เป็น .php แล้วก็รัน ครับ
ขอบอกนะครับว่า ท่านต้องไปนั่งอ่านที่ผมบอกไปด้วย ถือซะว่าอันนี้เป็นตัวอย่างง่ายๆ นะครับ
|
ประวัติการแก้ไข 2013-02-27 16:50:13
 |
 |
 |
 |
Date :
2013-02-27 16:48:12 |
By :
prachaporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 5 เขียนโดย : prachaporn เมื่อวันที่ 2013-02-27 16:48:12
รายละเอียดของการตอบ ::
ผมลองแล้วครับ ค้นหาไม่ได้อะครับ http://www.sesonshopping.com ที่เว็บนี้ครับ ดูที่ด้านขวาครับ
Code (PHP)
<?
session_start();
include'config.inc.php';
include'function.php';
?>
<?php
include "config.inc.php";
$query = "select * from tb_seo WHERE id=1";
$result = mysql_query($query);
$dbarr = mysql_fetch_array($result) ;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo "$dbarr[t_tt]"; ?></title>
<META content="<?php echo "$dbarr[t_de]"; ?>" name=description>
<META content="<?php echo "$dbarr[t_ke]"; ?>" name=Keywords>
<link rel="stylesheet" type="text/css" href="css.css" />
<style type="text/css" media="screen">
body {font-family: Helvetica, Arial, sans-serif; color:#333;}
.Circular {
font-weight: normal;
font-style: normal;
line-height:normal;
font-family: 'CircularRegular', sans-serif;
}
body,td,th {
font-size: 12px;
}
.style1 {color: #FF0000}
.style2 {
font-size: 18px;
font-weight: bold;
color: #B31115;
}
</style>
<style type="text/css">
<!--
.style3 {font-size: 36px}
-->
</style>
</head>
<body>
<table width="999" border="0" align="center" cellpadding="0" cellspacing="0" class="body">
<tr>
<td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="760" valign="top"><div align="center"><? include'header.php';?></div></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><? include'topmenu.php';?></td>
</tr>
</table>
<table width="100%" border="0">
<tr>
<td width="725" valign="top"><?
include'config.inc.php';
$eid=$_GET[search];
$sql = "select * from tb_newstravel WHERE n_copy BETWEEN '".$_GET['price1']."' AND '".$_GET['price2']."' like '%$eid%'"; //คำสั่ง Sql ที่ใช้
//$sql = "select * from $tblname where $field_search like '%$search%'";
$rs=mysql_query($sql);
$num_rows = mysql_num_rows($rs);
if($num_rows==''){
echo "ยังไม่มีเนื้อหาที่เกี่ยวข้อง";
}
$cols =1; //
$c = $cols;
echo"<table border=0>";
echo" <tr>";
while ($result=mysql_fetch_array($rs)){
$c --;
$r=$d[type_web_id];
#ถ้า หัวข้อกระทู้ ยาวเกินให้ตัดออก
$da1 = substr_utf8($result[n_topic],0,200) . "...";
$da2 = substr_utf8($result[n_title],0,150) . "...";
$da3=eregi_replace(" ", "-", $result[n_topic]);
echo" <td width= >";
if($result[n_image]==""){
echo"<default><img src=$siteurl/images/noimages.jpg width=125 height=150 class='reflect'></default>";
} else {
echo"<a href=Product-$result[n_id]-$da3.html alt='รองเท้าแฟชั่นเกาหลี $da3' target='_blank'><img src=$siteurl/images/news/$result[n_image] alt='รองเท้าแฟชั่นเกาหลี $da3' width=125 height=150 border=0></default></a>";
}
echo"</td><td width=100% valign=top>";
echo"<a href=Product-$result[n_id]-$da3.html alt='รองเท้าแฟชั่นเกาหลี $da3' target='_blank'><font class=head-line>$da1</font> </a> ";
echo"<br/>$da2";
?>
<br/>
<img src="images/time.gif"><font class="time_update"><?=ThaiDatesale($result[a_date]);?></font>
<?
echo" <img src=images/icon/stat.gif><font class='time_update'>$result[pageview] ผุ้เข้าชม</font><br />";
$tags_select = mysql_query("SELECT name FROM `tags` WHERE `topicid`=".$result['n_id']." ") or die(mysql_error());
while($tags_topic = mysql_fetch_array($tags_select)){
echo "<a href=\"tag.php?tag=".$tags_topic['name']."\"> ".$tags_topic['name']."</a>,</font>";
}
echo"</td>";
if($c == 0) {
$c = $cols;
echo" </tr></tr>";
} }
echo"</tr></table>";
// echo"<a href=readnews.php?id=$n_id target='_blank'><font class=head-line>$n_topic</font> </a> ";
//echo "รหัส : $n_topic- ชื่อ : $n_title - เกรด : $grade <BR />"; //แสดงข้อมูล
//echo "รหัส : $n_topic- ชื่อ : $n_title - เกรด : $grade <BR>"; //แสดงข้อมูล
//$i++;
//}
//mysql_close();
?></td>
<td width="250" valign="top"><? include'sidemenu.php';?></td>
</tr>
</table>
<br />
<? include'footer.php';?>
</td>
</tr>
</table>
</body>
</html>
|
 |
 |
 |
 |
Date :
2013-02-27 16:52:52 |
By :
vanavat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
$sql = "select * from tb_newstravel WHERE n_copy BETWEEN '".$_GET['price1']."' AND '".$_GET['price2']."' like '%$eid%'"; //like '%$eid% เพื่ออะไร และอะไรคือ eid ให้ตรวจสอบคำสั่ง SQL ใหม่ครับ
|
 |
 |
 |
 |
Date :
2013-02-27 17:27:30 |
By :
prachaporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใครก็ได้ช่วยทีครับ T-T
|
 |
 |
 |
 |
Date :
2013-02-27 17:51:12 |
By :
vanavat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาอย่างนี้ดีไหมผมว่าคุณยังคงไม่เข้าใจหลักของ PHP และ SQL
PHP ให้กลับไปอ่านตามที่ผมเคยบอกไว้
SQL ให้อ่านตาม บท ความที่เขียนไว้แล้ว
และให้ศึกษาโปรแกรม Navicat เพื่อท่านจะได้ง่ายในการดึงข้อมูล SQL
คือคุณต้องพึ่งตัวเองก่อนครับ เนื่องจาก ฐานข้อมูลก็อยู่กับคุณ และ
คุณต้องการดึงข้อมูลอะไรออกมา ผมยังไม่ทราบเลย แล้วผมจะทำให้คุณได้อย่างไร
1. กลับไปคิดว่าจะเอาข้อมูลอะไรออกมาแสดง
2. กลับไปคิดคำสั่ง SQL ว่าจะแสดงได้อย่างไร โดยใช้โปรแกรม Navicat ครับ
|
 |
 |
 |
 |
Date :
2013-02-27 19:54:18 |
By :
prachaporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่าครับพอดีผมไม่ได้เรียนมาอะครับ ผมจบมาน้อย ทำเว็บงูๆปลาๆไปวันๆ ผมต้องการจะดึง สินค้าโดยเรียงตามราคา
n_copy นี่เก็บราคาสินค้าไว้อะครับ tb_newstravel เก็บสินค้าทั้งหมดไว้ ก็อย่างที่เห็นอะครับ ต้องการจะดึงสินค้าออกมาแสดงตามราคา จาก .... ถึง .... ขออภัยด้วยนะครับพอดีผมก็ศึกษาจากการบอกของคนอื่นแล้วก็ค้นหาเนี่ยแหละครับ บางครั้งค้นหาแล้วลองทำมันไปไม่รอดจริงๆเพราะ ม.3 ผมยังเรียนไม่จบเลย T-T
Code (PHP)
$sql = "select * from tb_newstravel WHERE n_copy BETWEEN '".$_GET['price1']."' AND '".$_GET['price2']
|
 |
 |
 |
 |
Date :
2013-02-27 20:01:25 |
By :
vanavat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
$sql = "select * from tb_newstravel WHERE n_copy BETWEEN '".$_GET['price1']."' AND '".$_GET['price2']
ที่คุณเขียนมาก็ใกล้เคียงแล้ว ในการจะดึงข้อมูลออกมา แต่ผิดตรงที่
PK หรือ คีย์หลัก ของตาราง tb_newstravel จะต้องเป็น สินค้า ID หรือพูดง่ายๆ คือ product_id
FK หรือ คีย์รอง หรือ Index ของตราราง n_copy จะต้องเป็น product_id
และจะต้องนำสองตารางนี้มา JOIN กันเพื่อที่จะดึง
Code (C#)
INNER JOIN tb_newstravel ON tb_newstravel.product_id = n_copy.product_id
where n_copy BETWEEN '100' and '1000' ORDER BY N_COPY
ประมาณนี้ ไม่รู้ผมเข้าใจถูกหรือไม่ จะให้ดี เอาโครงสร้างฐานข้อมูล มาแสดงครับ
|
 |
 |
 |
 |
Date :
2013-02-27 23:14:30 |
By :
prachaporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ประมาณนี้ครับ
Code (PHP)
INNER JOIN tb_newstravel ON tb_newstravel.n_id = n_copy.n_id
where n_copy BETWEEN '".$_GET['price1']."' and '".$_GET['price2']."' ORDER BY N_COPY ";
พอจะได้มั้ยครับ
|
 |
 |
 |
 |
Date :
2013-02-27 23:23:42 |
By :
vanavat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทดสอบดูหรือยังครับว่าได้ไหรือไม่ ที่เขียน SQL มาก็ประมาณนั้นหละครับ
|
 |
 |
 |
 |
Date :
2013-02-28 09:50:13 |
By :
prachaporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ ตอนนี้ใช้แล้ว มันออกมาแบบนี้อะครับ พอกดค้นหามันก็ออกมาตามรูปเลยครับ

Code (PHP)
<form id="form1" name="form1" method="get" action="searchprice.php">
<table width="60" border="1" align="center">
<tr>
<td width="50">price1
<label>
<input name="price1" type="text" id="price1" />
</label></td>
<td width="50">price2
<label>
<input name="price2" type="text" id="price2" />
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center"> <br />
<input name="btok" type="submit" id="btok" value="ตกลง" />
</div></label></td>
</tr>
</table>
</form>
searchprice.php
Code (PHP)
<?
include'config.inc.php';
$eid=$_GET[search];
$sql = "select * from INNER JOIN tb_newstravel ON tb_newstravel.n_id = n_copy.n_id
where n_copy BETWEEN '".$_GET['price1']."' and '".$_GET['price2']."' ORDER BY N_COPY "; //คำสั่ง Sql ที่ใช้
//$sql = "select * from $tblname where $field_search like '%$search%'";
$rs=mysql_query($sql);
$num_rows = mysql_num_rows($rs);
if($num_rows==''){
echo "ยังไม่มีเนื้อหาที่เกี่ยวข้อง";
}
$Per_Page =20
$cols =4; //
$c = $cols;
echo"<table border=0>";
echo" <tr>";
while ($result=mysql_fetch_array($rs)){
$c --;
$r=$d[type_web_id];
#ถ้า หัวข้อกระทู้ ยาวเกินให้ตัดออก
$da1 = substr_utf8($result[n_topic],0,200) . "...";
$da2 = substr_utf8($result[n_title],0,150) . "...";
$da3=eregi_replace(" ", "-", $result[n_topic]);
echo" <td width= >";
if($result[n_image]==""){
echo"<default><img src=$siteurl/images/noimages.jpg width=125 height=150 class='reflect'></default>";
} else {
echo"<a href=Product-$result[n_id]-$da3.html alt='รองเท้าแฟชั่นเกาหลี $da3' target='_blank'><img src=$siteurl/images/news/$result[n_image] alt='รองเท้าแฟชั่นเกาหลี $da3' width=125 height=150 border=0></default></a>";
}
echo"</td><td width=100% valign=top>";
echo"<a href=Product-$result[n_id]-$da3.html alt='รองเท้าแฟชั่นเกาหลี $da3' target='_blank'><font class=head-line>$da1</font> </a> ";
echo"<br/>$da2";
?>
<br/>
<img src="images/time.gif"><font class="time_update"><?=ThaiDatesale($result[a_date]);?></font>
<?
echo" <img src=images/icon/stat.gif><font class='time_update'>$result[pageview] ผุ้เข้าชม</font><br />";
$tags_select = mysql_query("SELECT name FROM `tags` WHERE `topicid`=".$result['n_id']." ") or die(mysql_error());
while($tags_topic = mysql_fetch_array($tags_select)){
echo "<a href=\"tag.php?tag=".$tags_topic['name']."\"> ".$tags_topic['name']."</a>,</font>";
}
echo"</td>";
if($c == 0) {
$c = $cols;
echo" </tr></tr>";
} }
echo"</tr></table>";
// echo"<a href=readnews.php?id=$n_id target='_blank'><font class=head-line>$n_topic</font> </a> ";
//echo "รหัส : $n_topic- ชื่อ : $n_title - เกรด : $grade <BR />"; //แสดงข้อมูล
//echo "รหัส : $n_topic- ชื่อ : $n_title - เกรด : $grade <BR>"; //แสดงข้อมูล
//$i++;
//}
//mysql_close();
?></td>
|
ประวัติการแก้ไข 2013-02-28 12:34:18 2013-02-28 12:34:46
 |
 |
 |
 |
Date :
2013-02-28 12:33:47 |
By :
vanavat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|