|
![](/images/resource/spacer.gif) |
|
สอบถามเกี่ยวกับการเลือกฐานข้อมูล ซ้ำ table 2 ครั้ง โดยที่แต่ละครั้งกำหนด WHERE ต่างกัน |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code (PHP)
$sql = "SELECT * FROM users WHERE username = 'AAAA' order by user_id asc";
$result = mysql_query($sql);
$datas=mysql_fetch_array($result);
{
$user_id = stripslashes(str_replace('\r\n', '<br>',($datas['user_id'])));
$name = stripslashes(str_replace('\r\n', '<br>',($datas['name'])));
$email = stripslashes(str_replace('\r\n', '<br>',($datas['email'])));
$username = stripslashes(str_replace('\r\n', '<br>',($datas['username'])));
}
$sql = "SELECT * FROM users WHERE username = 'BBBB' order by user_id asc";
$result = mysql_query($sql);
$datas=mysql_fetch_array($result);
{
$user_id_2 = stripslashes(str_replace('\r\n', '<br>',($datas['user_id'])));
$name_2 = stripslashes(str_replace('\r\n', '<br>',($datas['name'])));
$email_2 = stripslashes(str_replace('\r\n', '<br>',($datas['email'])));
$username_2 = stripslashes(str_replace('\r\n', '<br>',($datas['username'])));
}
echo" $user_id $name $email $username $user_id_2 $name_2 $email_2 $username_2 ";
ไม่ทราบว่าเขียนตามโค๊ดด้านบนนี้ได้มั้ยค๊ะ
หรือว่าในส่วนที่ WHERE username = 'BBBB' จะต้องกำหนดเป็น
Code (PHP)
$sql2 = "SELECT * FROM users WHERE username = 'BBBB' order by user_id asc";
$result2 = mysql_query($sql2);
$datas2=mysql_fetch_array($result2);
{
$user_id_2 = stripslashes(str_replace('\r\n', '<br>',($datas2['user_id'])));
$name_2 = stripslashes(str_replace('\r\n', '<br>',($datas2['name'])));
$email_2 = stripslashes(str_replace('\r\n', '<br>',($datas2['email'])));
$username_2 = stripslashes(str_replace('\r\n', '<br>',($datas2['username'])));
}
คือใส่เลข 2 ที่ $sql, $result, $datas
Tag : PHP, MySQL
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2012-11-13 12:22:48 |
By :
dferru |
View :
853 |
Reply :
2 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code (PHP)
$sql = "SELECT * FROM users WHERE username = 'AAAA' order by user_id asc";
$result = mysql_query($sql);
$datas=mysql_fetch_array($result);
$user_id = stripslashes(str_replace('\r\n', '<br>',($datas['user_id'])));
$name = stripslashes(str_replace('\r\n', '<br>',($datas['name'])));
$email = stripslashes(str_replace('\r\n', '<br>',($datas['email'])));
$username = stripslashes(str_replace('\r\n', '<br>',($datas['username'])));
echo" $user_id $name $email $username<br />";
$sql = "SELECT * FROM users WHERE username = 'BBBB' order by user_id asc";
$result = mysql_query($sql);
$datas=mysql_fetch_array($result);
$user_id = stripslashes(str_replace('\r\n', '<br>',($datas['user_id'])));
$name = stripslashes(str_replace('\r\n', '<br>',($datas['name'])));
$email = stripslashes(str_replace('\r\n', '<br>',($datas['email'])));
$username = stripslashes(str_replace('\r\n', '<br>',($datas['username'])));
echo" $user_id $name $email $username<br />";
|
ประวัติการแก้ไข 2012-11-13 16:21:35
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2012-11-13 16:17:31 |
By :
sakuraei |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
หรือแบบนี้ก็ได้ครับ
$sql = "SELECT * FROM users WHERE username in ('AAAA','BBBB') order by user_id asc";
$result = mysql_query($sql);
while($datas=mysql_fetch_array($result))
{
$user_id = stripslashes(str_replace('\r\n', '<br>',($datas['user_id'])));
$name = stripslashes(str_replace('\r\n', '<br>',($datas['name'])));
$email = stripslashes(str_replace('\r\n', '<br>',($datas['email'])));
$username = stripslashes(str_replace('\r\n', '<br>',($datas['username'])));
echo" $user_id $name $email $username<br />";
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2012-11-13 16:20:20 |
By :
sakuraei |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 00
|