|
 |
|
ขอความช่วยเหลือหน่อยครับ ต้องการ save ข้อมูลจาก record ที่ค้นหาเป็นไฟล์ json ครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<form method="post" action="searchtest.php" accept-charset="utf-8">
<input type="hidden" name="submitted" value="true">
<label> Search Category :
<select name="category" >
<option value="firstname">firstname</option>
<option value="surname">surname</option>
<option value="address">address</option>
<option value="tel">tel</option>
<option value="email">email</option>
<option value="gender">gender</option>
</select>
</label>
<label>Search : <input type="text" name="search"></label>
<input type="submit" name="">
</form>
<?php
if (isset($_POST['submitted'])) {
include('connectdb.php');
$category = $_POST['category'];
$search = $_POST['search'];
$query = "SELECT * FROM users WHERE $category LIKE '%".$search."%'";
$result = mysqli_query($conn, $query) or die ('error');
$user_data = array();
$num_rows = mysqli_num_rows($result);
echo "$num_rows result found";
echo "<table>";
echo "<tr><th>firstname</th><th>surname</th><th>address</th><th>tel</th><th>email</th><th style='text-align:right'>gender</th></tr>";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo"<tr><td>";
echo $row['firstname'];
echo "</td><td>";
echo $row['surname'];
echo "</td><td>";
echo $row['address'];
echo "</td><td>";
echo $row['tel'];
echo "</td><td>";
echo $row['email'];
echo "</td><td style='text-align:right'>";
echo $row['gender'];
echo "</td></tr>";
$user_data[] = array(
'firstname' => $row["firstname"],
'surname' => $row["surname"],
'address' => $row["address"],
'tel' => $row["tel"],
'email' => $row["email"],
'gender' => $row["gender"]
);
}
echo "</table>";
}
?>
ผลลัพธ์จาก code ด้านบน

ต้องการ save record เฉพาะที่ค้นหาเป็นไฟล์ json ครับ
Tag : PHP, MySQL, XAMPP, Windows

|
|
 |
 |
 |
 |
Date :
2018-04-11 22:17:24 |
By :
mysecrecy |
View :
591 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$json_result = json_encode( $record_result);
แล้วจะเอา $json_result ไปเก็บไว้ที่ไหนก็ตามใจ เพราะมันมีรูปแบบ string แล้ว
|
 |
 |
 |
 |
Date :
2018-04-12 07:15:18 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ From ครอบ Division ไว้ก็ได้ครับ เสร็จแล้วข้อมูล ให้เก็บโดยซ่อน textbox
Code (PHP)
<input type="hidden">
เมื่อทำการ hidden เข้าสู่ json โดยการทำ each Loop เพื่อวน Loop data เข้าสู่ DB
|
 |
 |
 |
 |
Date :
2018-04-12 11:31:44 |
By :
dudesaranyu |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|