|
|
|
ขอ code ค้นหา ค้นหา ใน คอลัมถ์ A กดปุ่มค้นหา แล้ว page เปิดขั้นมาตาม url คอลัมภ์ B |
|
|
|
|
|
|
|
ขอรายละเอียดให้ชัดเจนกว่านี้หน่อยครับ เพราะถามแบบนี้โอกาสมีคนตอบน้อยครับ
|
|
|
|
|
Date :
2009-12-03 01:33:24 |
By :
xbeginner01 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอานี่โค้ดนี่ไปเป็นแนวทางละกันนะคับบ
ผมก้อศึกษาอยุ่อ่า
////////// search.php /////////////////
<!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>Untitled Document</title>
</head>
<body>
<?
// เชื่อมต่อฐานข้อมูล
$host="localhost"; // กำหนด host
$username="root"; // กำหนด username
$pass_word="nuiii"; // กำหนด Password
$db="test_create_database"; // กำหนดชื่อฐานข้อมูล
$Conn = mysql_connect( $host,$username,$pass_word) or die ("ติดต่อฐานข้อมูลไม่ได้");// ติดต่อฐานข้อมูล
mysql_query("SET NAMES utf8",$Conn); // set กำหนดมาตราฐาน
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้"); // เลือกฐานข้อมูล
//--->
?>
<form id="form1" name="form1" method="post" action="search.php">
ค้นหา <input name="txt_search" type="text" value="<?=$_POST['txt_search']?>" /> <input name="Search" type="submit" value="ค้นหา" />
</form>
<table width="600" border="1" cellspacing="2" cellpadding="2">
<tr>
<td><div align="center">รหัส</div></td>
<td><div align="center">ชื่อ</div></td>
<td><div align="center">นามสกุล</div></td>
<td><div align="center">ที่อยู่</div></td>
<td><div align="center">โทรศัพท์</div></td>
<td><div align="center">แก้ไข</div></td>
</tr>
<?
$sql_show = "select * from customer";
if($_POST['Search'])
{
$txt_search = $_POST['txt_search'];
$sql_show.=" where name like '%$txt_search%' or surname like '%$txt_search%' ";
}
$result_show = mysql_query($sql_show) or die(mysql_error());
while($row_show = mysql_fetch_array($result_show))
{
?>
<tr>
<td><?=$row_show['id']?></td>
<td><?=$row_show['name']?></td>
<td><?=$row_show['surname']?></td>
<td><?=$row_show['address']?></td>
<td><?=$row_show['phone']?></td>
<td><div align="center"><a href="edit.php?edit_id=<?=$row_show[id]?>">แก้ไข</a></div></td>
</tr>
<?
}
?>
</table>
</body>
</html>
|
|
|
|
|
Date :
2009-12-06 17:04:38 |
By :
dootertam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
search.php
<?php require_once('Connections/connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_connect, $connect);
$query_SearchByType = "SELECT * FROM type ORDER BY name_type ASC";
$SearchByType = mysql_query($query_SearchByType, $connect) or die(mysql_error());
$row_SearchByType = mysql_fetch_assoc($SearchByType);
$totalRows_SearchByType = mysql_num_rows($SearchByType);
?>
<!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>หน้าแรก</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
a:link {
color: #F06;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #F06;
}
a:hover {
text-decoration: none;
color: #F3C;
}
a:active {
text-decoration: none;
color: #00F;
}
-->
</style></head>
<body>
<?php include('scipt_function.html')?>
<table width="921" height="749" border="0" align="center">
<tr>
<td height="272" colspan="2" valign="top" bgcolor="#FFCCFF"><?php include('headone.php'); ?></td>
</tr>
<tr >
<td width="213" height="395" bgcolor="#FFCCCC" align="center" valign="top"><table width="100%" border="0" cellspacing="2">
<tr>
<td><form id="form3" name="form3" method="post" action="search.php">
<p align="center">ค้นหาสินค้า</p>
<p>
<label>
<input type="text" name="txtSearch" value="<?=$_POST['txtSearch'];?>"/>
</label>
<label>
<input type="submit" name="button2" id="button2" value="Submit" />
</label>
</p>
</form></td>
</tr>
</table>
<p> </p>
<table width="213" height="192" border="1" bordercolor="#FF3333" align="center" cellspacing="2">
<tr>
<td>
<form id="form1" name="form1" method="post" action="chkmember.php">
<table width="200" border="0" cellspacing="2">
<tr>
<td width="72">username :</td>
<td width="118"><label>
<input name="user_login" type="text" id="textfield" size="20" onkeypress="Checktext()"/>
</label></td>
</tr>
<tr>
<td>password :</td>
<td><label>
<input name="pass_login" type="password" id="textfield2" size="20" />
</label></td>
</tr>
<tr>
<td colspan="2" align="center"><label>
<input type="submit" name="button" id="button" value="เข้าสู่ระบบ" />
|
<a href="user/m_forgetpassword.php">ลืมรหัสผ่าน</a> </label></td>
</tr>
</table>
</form>
<p align="center"><a href="register.php">สมัครสมาชิกใหม่</a></p>
<p align="center"><a href="admin_login.php">สำหรับผู้ดูแลระบบ</a></p></td>
</tr>
</table>
<br />
<table width="213" height="138" border="0" bordercolor="#FF6633" cellspacing="2" align="center">
<tr align="center" bgcolor="#FF0000" >
<td bgcolor="#FFFFCC"><? include('calander.php')?></td>
</tr>
</table></td>
<td width="828" align="center" valign="top" bgcolor="#FFFFCC">
<form id="form2" name="form2" method="post" action="">
<table width="80%" height="342" border="0" align="center" cellspacing="2">
<tr>
<td align="center" valign="top"><h3> </h3>
<!--ค้นหา-->
<?php
include('user/connect.php');
$sql_show = "select * from products";
if($_POST['txtSearch'])
{
$txtSearch=$_POST['txtSearch'];
$sql_show.=" where name_prd like '%txtSearch%'";
}
$result_show = mysql_query($sql_show) or die(mysql_error());
while($row_show = mysql_fetch_array($result_show)){;
$id_prd=$rs[id_prd];
$code=sprintf("%05d",$id_prd);
$name_prd=$rs[name_prd];
$detail_prd=$rs[detail_prd];
$ref_id_type=$rs[ref_id_type];
$price_prd=$rs[price_prd];
$photo_prd=$rs[photo_prd];
$amount=$rs[amount];
$price_send=$rs[price_send];
if ($photo_prd==""){
$photo_prd="picweb/temp.jpg.jpg";
}
echo"
<table border='2'>
<tr bordercolor='#FF9900'>
<td width='30%' valign='top'>
<img width='180' src='$photo_prd'>
</td>
<td width='70%'>
<b>รหัสสินค้า :</b>$code<br>
<b>ประเภทสินค้า :</b>$ref_id_type<br>
<b>ชื่อสินค้า :</b>$name_prd<br>
<b>ราคาสินค้า :</b><samp>".number_format($price_prd,2,'.',',')."</samp>บาท<br><br>
[<a href='view_pro.php?id_prd=$id_prd'>ดูรายละเอียด</a>]
<br>
</td>
</tr>
</table>";
}//end while
?>
</td>
</tr>
<tr bgcolor="#FFCC66" align="center">
<td height="72" align="center"><table width="100%" border="0" align="center" cellspacing="2">
<tr>
<td>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td width="100%" colspan="3" valign="top" bgcolor="#FFCC66"><div align="center"><strong><font color="#FF6633">HAND MADE KIKUYA<br>
Contact Us :</font></strong><strong><font color="#FF6633">Jutamat Sangka & Sompit Poomtong</font></strong><br>
</div>
</td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($SearchByType);
?>
=============================================
พอรันแล้วมันบอกว่า No Database selected
=============================================
อันนี้ Cn.php
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connect = "localhost";
$database_connect = "project";
$username_connect = "root";
$password_connect = "102bc17sau";
$connect = mysql_pconnect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("SET NAMES utf8");
?>
==================================
ช่วยดูให้หน่อยค่ะ ผิดตรงไหน
|
|
|
|
|
Date :
2012-03-03 01:29:42 |
By :
จุฑามาศ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|