|
|
|
สอบถามเกี่ยวกับการเลือกฐานข้อมูล ซ้ำ table 2 ครั้ง โดยที่แต่ละครั้งกำหนด WHERE ต่างกัน |
|
|
|
|
|
|
|
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
|
|
|
|
|
|
Date :
2012-11-13 12:22:48 |
By :
dferru |
View :
847 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
Date :
2012-11-13 16:17:31 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หรือแบบนี้ก็ได้ครับ
$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 />";
}
|
|
|
|
|
Date :
2012-11-13 16:20:20 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|