ThaiSEOBoard.com

พัฒนาเว็บไซต์ => CMS & Free Script => ข้อความที่เริ่มโดย: minmono ที่ 14 มิถุนายน 2018, 19:33:32



หัวข้อ: นำข้อมูลจาก mySql-1 ไปค้นหาต่อที่ mySql-2
เริ่มหัวข้อโดย: minmono ที่ 14 มิถุนายน 2018, 19:33:32
สอบถามวิธีการนำข้อมูลที่กรองออกมาจากดาต้าเบสที่1 ไปค้นหาต่อในดาต้าเบสที่2 ครับ

ดาต้าเบสที่1 เป็นเว็บฝากรูปครับ https://github.com/lfiore/upld/ แล้วได้ทำหน้าเว็บสำหรับแสดงรายการรูปภาพล่าสุดออกมาเป็น
โค๊ด:
<?php

require(&#39;config.php&#39;);
require(&#39;common.php&#39;);

if (!isset($_SESSION[&#39;user&#39;]))
{
exit_message(&#39;You are no authorised to access this page. Please log in.&#39;);
}

$user $_SESSION[&#39;user&#39;];

require(&#39;db.php&#39;);

$page = isset($_POST["page"])? (int) $_POST["page"] : 0;
$images mysqli_prepare($db, &#39;SELECT `id`, `ext`, `time` FROM `images` WHERE `removed` = "0" ORDER BY `time` desc limit &#39;.$page.&#39;, 10 &#39; );

//mysqli_stmt_bind_param($images, &#39;i&#39;, $user);
mysqli_stmt_execute($images);
++
$db_queries;
mysqli_stmt_store_result($images);

if (
mysqli_stmt_num_rows($images) === 0)
{
exit_message(&#39;You haven\&#39;t uploaded any images yet!&#39;);
}

mysqli_stmt_bind_result($images$id$ext$time);

require(&
#39;inc/header.php&#39;);

if (!defined(&#39;IN_SCRIPT&#39;))
{
header(&#39;location: ../index.php&#39;);
exit;
}

?>


<div class="box">
<p class="title" style="text-decoration: underline;">Admin Column mode to View All Image</p>

<?php
echo&
#39;<table style="position: absolute;padding: 0 50px;"><thead>
<tr style="background-color: #a4ed34;">&#39;;
echo &#39;<th style="width: 200px" scope="col">Image ID</th>&#39;;
echo &#39;<th style="width: 200px" scope="col">uploaded</th>&#39;;
echo &#39;<th style="width: 80px" scope="col">View</th>&#39;;
echo &#39;<th style="width: 200px" scope="col">Search</th>&#39;;
echo &#39;</tr></thead>&#39;;

while (mysqli_stmt_fetch($images))
{
echo &#39;<tr>&#39;;
echo &#39;<td>&#39;. $id.&#39;</td>&#39;;
echo &#39;<td>&#39;. $time .&#39;</td>&#39;;
echo &#39;<td><a target="_blank" rel="follow" href="&#39; .VIEW_PATH . $id .&#39;">GO</a></td>&#39;;
echo &#39;<td> </td>&#39;;
echo &#39;</tr>&#39;;
}
echo&#39;</table>&#39;;
?>


<?php

mysqli_stmt_close
($images);
mysqli_close($db);

?>

</div>
<?php

(http://postto.me/1s/838.png)

ต้องทำอย่างไรครับเพื่อให้นำ Image ID($id) จากรายการ > ไปค้นหาต่อในดาต้าเบสที่2 แล้วแสดงผลการค้นหาออกมาด้านหลังได้เลยไม่ต้องไปกดค้นหาที่ล่ะรายการอีกนะครับ


หัวข้อ: Re: นำข้อมูลจาก mySql-1 ไปค้นหาต่อที่ mySql-2
เริ่มหัวข้อโดย: minmono ที่ 16 มิถุนายน 2018, 21:34:27
แทรกคำสั่งลงไปอีกชุดสั่งเปลี่ยน DB ใหม่ก็ใช้ได้เลยเหรอนี่  :wanwan020:
โค๊ด:
	$connect2 = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
$images2 = mysqli_prepare($connect2, "SELECT * FROM messages WHERE body like '%" [b]. $id . [/b]"%'  ");

mysqli_stmt_execute($images2);
++$db_queries;
mysqli_stmt_store_result($images2);

if (mysqli_stmt_num_rows($images2) > 0)
{
echo'<label> Found </label>';
}
else
{
echo'<a>Not Found </a>';
}