|
 |
|
สอบถามเกี่ยวกับการ random row ค๊ะ ด้านล่างนี้เป็นฟังก์ชัน captcha ที่หนูเขียนขึ้นค๊ะ |
|
 |
|
|
 |
 |
|
ด้านล่างนี้เป็นฟังก์ชัน captcha ที่หนูเขียนขึ้นค๊ะ ใช้งานได้ ok แต่ติดปัญหาตรงที่ว่า
ถ้าดูจากโค๊ดหนูจะเอาค่า captcha จาก row 3 มา row เดียวเลยค๊ะ หนูอยากจะให้ randow row จะทำอย่างไรดีค๊ะ
Code (PHP)
<?PHP
include("connect.php");
$sql = "SELECT * FROM captcha WHERE id = '3' order by id asc";
$result = mysql_query($sql);
$datas=mysql_fetch_array($result);{
$ask = stripslashes(str_replace('\r\n', '<br>',($datas['ask'])));
$ans = stripslashes(str_replace('\r\n', '<br>',($datas['ans'])));
$id = stripslashes(str_replace('\r\n', '<br>',($datas['id'])));
}
?>
<?php
if(isset($_POST["submit"]))
{
include("connect.php");
$sql = "SELECT * FROM captcha WHERE id = '3' AND ans = '".$_POST["ans"]."' ";
$query = mysql_query($sql);
$result = mysql_fetch_array($query);
if($result)
{
echo("TRUE");
}
else
{
echo("NOT TRUE");
}
}
?>
<div class="captcha">
<div id="allFields">
<div class="fields">
<form name="captcha" method="post" action="" ENCTYPE = "multipart/form-data" onsubmit="return checkform(this);">
<table class="billinginputs" cellpadding="0" cellspacing="0" style="width: 100%; padding: 5px 10px 10px 5px;">
<tbody><tr>
<td class="label">
<label style=" font-size: 14px; " >Captcha : <span class="mandatory">*</span</label>
</td>
<td class="field_left">
<?PHP echo"$ask";?><input type="text" style=" font-size: 14px; " name="ans" value="">
</td>
</tr>
<tr>
<td class="label">
<input type="submit" name="submit" value="submit" />
</td>
<td class="field_left">
</td>
</tr>
</tbody></table>
</form>
</div>
</div>
</div>
ด้านล่างนี้เป็นรูป Table : captcha

หมายเหตุ *******
หนูเคยใช้ฟังก์ชัน random มาใช้ค๊ะ โค๊ดตามด้านล่างนี้นะค๊ะ แต่ใช้ไม่ได้ค๊ะ หนูรู้สึกว่ามันจะ rand ไปเรื่อยๆเลยค๊ะ คำตอบเลยไม่ตรงเลย
Code (PHP)
<?PHP
include("connect.php");
$query = "SELECT MAX(id) FROM captcha";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
$max_id = $row['MAX(id)'];
}
$ran_id =(rand(1,$max_id));
$sql = "SELECT * FROM captcha WHERE id = '$ran_id' order by id asc";
$result = mysql_query($sql);
$datas=mysql_fetch_array($result);{
$ask = stripslashes(str_replace('\r\n', '<br>',($datas['ask'])));
$ans = stripslashes(str_replace('\r\n', '<br>',($datas['ans'])));
$id = stripslashes(str_replace('\r\n', '<br>',($datas['id'])));
}
?>
<?php
if(isset($_POST["submit"]))
{
include("connect.php");
$sql = "SELECT * FROM captcha WHERE id = '$ran_id' AND ans = '".$_POST["ans"]."' ";
$query = mysql_query($sql);
$result = mysql_fetch_array($query);
if($result)
{
echo("TRUE");
}
else
{
echo("NOT TRUE");
}
}
?>
<div class="captcha">
<div id="allFields">
<div class="fields">
<form name="captcha" method="post" action="" ENCTYPE = "multipart/form-data" onsubmit="return checkform(this);">
<table class="billinginputs" cellpadding="0" cellspacing="0" style="width: 100%; padding: 5px 10px 10px 5px;">
<tbody><tr>
<td class="label">
<label style=" font-size: 14px; " >Captcha : <span class="mandatory">*</span</label>
</td>
<td class="field_left">
<?PHP echo"$ask";?><input type="text" style=" font-size: 14px; " name="ans" value="">
</td>
</tr>
<tr>
<td class="label">
<input type="submit" name="submit" value="submit" />
</td>
<td class="field_left">
</td>
</tr>
</tbody></table>
</form>
</div>
</div>
</div>
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2013-03-28 23:15:00 2013-03-28 23:20:50 2013-03-28 23:21:50
|
 |
 |
 |
 |
Date :
2013-03-28 23:13:19 |
By :
dferru |
View :
854 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนแยกเป็น function แล้วเรียกใช้
|
 |
 |
 |
 |
Date :
2013-03-29 08:05:20 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|