|
 |
|
แก้ให้หน่อยครับพี่ คือต้องการวนลูป แล้วเอา $username มาทำการ connect หาข้อมูลแล้ววนหาต่อไปใน DB อื่น |
|
 |
|
|
 |
 |
|
คือผมเอา username ใน ตาราง hotel มาสร้างฐานข้อมูลใหม่นะครับ(โรงแรมแต่ละโรงแรมจะมี DB เป็นของตนเอง)แล้วทีนี้เมื่อลูกค้าทำการจองห้องพักแล้วต้องการจะดูข้อมูลการจองของตนเองในตาราง booking ของโรงแรมมที่จองไว้แล้วนะครับ
1. ต้องการนำ username ใน ตาราง hotel มา connect เพื่อหาข้อมูลที่ทำการจองไว้ หากว่าไม่เจอก็ให้ วนไปยัง username ต่อไป แล้ว connect หา หาจนเจอข้อมูลที่จองไว้แล้วแสดงออกมานะครับ
connect.php
Code (PHP)
<?
$hostname = "localhost";
$user = "root";
$password = "root";
$newDB = $username;
$conn = mysql_pconnect($hostname, $user, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("SET NAMES utf8");
?>
ส่วนนี่เป็นโค้ดที่เขียนไว้ครับ คือต้องการทราบว่าจะทำการวนลูป connect ยังไงหรอครับพี่
Code (PHP)
<?
//วนลูปเอา username มาทำการ connect เพื่อหาห้องพักที่ได้จองไว้
$sql="select username from hotel where hotel_id order by hotel_id asc";
$result=mysql_db_query($database_conn,$sql);
$N = mysql_num_rows($result);
echo $N;
$username="";
for($i=0; $i<$N; $i++)
{
$hotel_arr = mysql_fetch_array($result);
$username=$hotel_arr['username'].",";
}
if(preg_match('/,$/',$username)){ // ตรวจสอบตัวสุดท้ายเป็น ,
$username= preg_replace('/,$/','',$username); // ลบ , ตัวสุดท้ายออก
}
require_once('../Connections/connect.php');
mysql_db_query($newDB,$conn);
$sql="select * from booking where cus_id='$Cus_id'";
$result=mysql_query($sql);
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-11-14 18:43:57 |
By :
giroo |
View :
935 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สรุปว่าทำแบบนี้นี่ไม่สามารถทำได้ใช่ไหมครับ
|
 |
 |
 |
 |
Date :
2009-11-15 23:01:52 |
By :
giroo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|