 |
อยากทราบวิธีดึง url จากฐานข้อมูลมาแสดงแล้วคลิกที่ link ได้เลยครับ |
|
 |
|
|
 |
 |
|
เพิ่งหัดเขียนครับ งมมาหลายวันแล้วครับ คืออย่างนี้ครับ
ผมต้องการจะดึงข้อมูลของลูกค้าจากการพิมหาโดย keyword ออกมาแสดง โดยเลือกแสดง username กับ link ของลูกค้า แต่ทำเท่าใหร่ก็ไม่ได้ ที่ว่าไม่ได้คือผมอยากให้สามารถคลิกตรง url ได้เลย แต่ว่าที่ผมทำมันแสดงเป็น text อย่างเดียวคลิกไม่ได้เลย
หรือไม่ผมก็อยากดึงชื่อร้านค้าของลูกค้ามาแล้วก็คลิกที่ชื่อให้มัน link ไปยัง profile page ของร้านค้าเองน่ะครับ
รบกวนผู้รู้ช่วยบอกหน่อยนะครับว่าต้องทำยังใง
ลองดูโคดที่ผมมีนะครับ(หาเอาจาก thai create นี่แหละอิอิ)
อันนี้หน้าที่ให้พิมsearch
Code (PHP)
<html>
<head>
<title>gubig quick search</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
body,td,th {
font-family: Century Gothic, CordiaUPC, Calibri;
}
.style1 {font-size: 12px}
-->
</style>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Search) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'data.php';
var pmeters = 'mySearch='+Search;
HttPRequest.open('post',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
</script>
<body Onload="JavaScript:doCallAjax('');">
<strong>say what you need ie. travel, shoping, buy.....and they will show up</strong> <strong>below</strong>
<form name="frmMain">
type your key words
<textarea name="txtSearch" cols="40" id="txtSearch"></textarea>
and
<input type="button" name="btnSearch" id="btnSearch" value="go > > >" OnClick="JavaScript:doCallAjax(document.getElementById('txtSearch').value);">
<br>
<br>
<span id="mySpan"></span>
</form>
</body>
</html>
แล้วดึงข้อมูลจากหน้านี้มาแสดง
Code (PHP)
<?php
$strSearch = $_POST["mySearch"];
$objConnect = mysql_connect("localhost","root","pkknui") or die("Error Connect to Database");
$objDB = mysql_select_db("member");
$strSQL = "SELECT * FROM supplier WHERE name LIKE '%".$strSearch."%' or profile LIKE '%".$strSearch."%'ORDER BY name ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?><style type="text/css">
<!--
body,td,th {
font-family: Century Gothic, CordiaUPC, Calibri;
}
.style1 {font-size: 16px}
-->
</style>
<table width="300" border="0">
<tr>
<th width="300"> <div align="center" class="style1">see who match your need</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td height="20"><div align="left"><?=$objResult["name"];?>
| <?php $string = "www.gubig.com/manathai.php";
echo mb_convert_encoding($string , "HTML-ENTITIES" , "UTF-8");?>
</div></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
มันแสดงแบบนี้
say what you need ie. travel, shoping, buy.....and they will show up below
type your key words and
see who match your need
123456 | www.gubig.com/manathai.php
22222 | www.gubig.com/manathai.php
winsdenorth | www.gubig.com/manathai.php อยากให้ตรง url เป็น link ก็ยังดี
รบกวนด้วยนะครับ
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, Report Others
|
|
 |
 |
 |
 |
Date :
2011-02-04 13:40:28 |
By :
thanadol |
View :
8757 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หน้าที่ถูกดึงมาแสดง ตรง
Code (PHP)
$string = "www.gubig.com/manathai.php";
echo mb_convert_encoding($string , "HTML-ENTITIES" , "UTF-8");
ให้เพิ่ม Tag ลิงก์ลงไปครับ
Code (PHP)
$string = "www.gubig.com/manathai.php";
echo "<a href=\"".$string."\">".mb_convert_encoding($string , "HTML-ENTITIES" , "UTF-8")."</a>";
น่าจะได้นะครับ
|
 |
 |
 |
 |
Date :
2011-02-04 14:15:48 |
By :
zankumuro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับผม งมมาตั้งหลายวัน
พอดีมีคำถามอีกน่ะครับ คือว่าผมไปเก็บ link http://www.gubig.com/supplier privacy.php ใว้ในฐานข้อมูล แล้วเวลาดึงมาแสดงผมอยากให้ดึงมาแบบนี้ ชื่อลูกค้า | preview โดยให้คำว่า preview เป็น link ไปยัง url ที่เก็บใว้ในฐานข้อมูลในตารางที่ชื่อ link
แบบนี้พอทำใด้มั้ยคับ ช่วยแนะนำโค๊ดให้หน่อยครับ
นี่โค๊ดที่ผมมีครับ
Code (PHP)
?>
<tr>
<td height="20"><div align="left"><?=$objResult["name"];?>
| <?=$objResult["preview"];?>
</div></td>
</tr>
<?
มันแสดงแบบนี้
say what you need ie. travel, shoping, buy.....and they will show up below
type your key words and
see who match your need
company1 | preview
company2 | preview
winsdenorth | preview อยากให้คลิกที่ preview แล้วลิ้งค์ไปที่ url ที่เก็บใว้เลยน่ะครับ
ขอบคุณมากๆครับผม
|
ประวัติการแก้ไข 2011-02-04 16:56:09
 |
 |
 |
 |
Date :
2011-02-04 16:52:39 |
By :
thanadol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ประมาณนี้ครับ เอาไปลองประยุกต์ใช้ดูครับ
Code (PHP)
?>
<tr>
<td height="20"><div align="left"><?=$objResult["name"];?>
| <?php $string = "www.gubig.com/manathai.php"; ?><a href="<?=$string?>"><?=$objResult["preview"];?></a>
</div></td>
</tr>
<?
|
 |
 |
 |
 |
Date :
2011-02-04 17:12:11 |
By :
zankumuro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณมากครับ อบอุ่นจริงๆบ้านหลังนี้ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2011-02-04 17:38:49 |
By :
thanadol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|