Hi everyone, i have been working on this for hours but i can't solve the problem myself. Hope someone can help me out.
So i have a main page with has a search function -
<?php
-
$search = $_GET['search'];
-
$terms = explode(" ", $search);
-
$query = "SELECT * FROM search WHERE ";
-
foreach ($terms as $each){
-
$i++;
-
if ($i == 1)
-
$query .= "keywords LIKE '%$each%' ";
-
else
-
$query .= "OR keywords LIKE '%$each%' ";
-
}
-
-
$db = mysql_connect("a", "a", "a");
-
mysql_select_db("a");
-
mysql_query("SET NAMES UTF8", $db);
-
$query = mysql_query($query);
-
$numrows = mysql_num_rows($query);
-
if ($numrows > 0) {
-
while ($row = mysql_fetch_array($query)) {
-
$id = $row['id'];
-
$title = $row['title'];
-
$description = $row['description'];
-
$keywords = $row['keywords'];
-
$link = $row['link'];
-
-
echo "<div id='kq' ><a href='http://bytes.com/a/rs.php?id=$id'>$title</a></div></br >";
-
}
-
}
-
else
-
echo "<div id='kq1'> '$search'</div>";
-
-
mysql_close ();
-
?>
-
as you can see, every result has link rs.php?id=$id specific to its id. Until now it's fine.
Then i create the rs.php -
<?php
-
$newid = (int) $_GET['id'];
-
-
$servername = "a";
-
$username = "a";
-
$password = "a";
-
-
$conn = new mysqli($servername, $username, $password);
-
if ($conn->connect_error) {
-
die("Connection failed: " . $conn->connect_error);
-
}
-
-
mysql_select_db("a", $db);
-
-
$newid = (int) $_GET['id'];
-
$result = mysql_query("SELECT * FROM 'search' WHERE id = 1", $db) ;
-
$myrow = mysql_fetch_array($result);
-
-
-
echo $myrow["title"];
-
mysql_close();
-
?> <html> <head> <meta charset='utf-8'> <title>dd</title> </head> <body> <?php echo $myrow['title']; ?> </body> </html>
-
When I click on the link of a result, no error found but the title doesn't appear. Ive been looking on this for hours, I found a same question on this website which was posted since 2007. Except the main page, our rs.php pages are exactly the same so i don't know mine doesn't work. Hope someone can help me out. Thank you...
8 1753
On line 16, you're only looking for Id = 1
Yeah I forgot to change that back, I do that to test if there is any problem with the $newid=$_GET['id']; The original code: - $newid = (int) $_GET['id'];
-
$result = mysql_query("SELECT * FROM 'search' WHERE id = $newid", $db) ;
-
$myrow = mysql_fetch_array($result);
-
-
echo $newid;
-
echo sdqsd;
-
echo $myrow["title"];
-
mysql_close();
-
?>
-
-
<html>
-
<head>
-
<meta charset='utf-8'>
-
<title>dd</title>
-
</head>
-
-
<body>
-
<?php echo $myrow['title']; ?>
-
</body>
-
-
</html>
Still doesn't work though. I try
this time, apparently it's fine. It got the right id. But the title doesn't appear.
I also used - if ($conn->connect_error) {
-
die("Connection failed: " . $conn->connect_error);
-
}
-
echo "Connected successfully";
-
?>
The connection to database seems to be good too. hmmm Still working on this.
RonB 589
Expert Mod 512MB
Try dumping $myrow to see if it holds what you expect.
Change: - <?php echo $myrow['title']; ?>
To: - <?php print_r($myrow); ?>
or: - <?php var_dump($myrow); ?>
You should check that the table has
1) the id you're searching for
2) a field named title
3) the field is populated
yes It does. I checked that too. The id is int, auto_incr. the title is varchar limit 250 characters.the field is populated. hmmm.
With - <?php print_r($myrow['title']); ?>
nothing change . With - <?php var_dump($myrow['title']); ?>
i got the "NULL". hmm. I check id, title, ... everything was right but it still doesn't work ...
Thanks god, finally I work it out, thanks so much for your helps.
the problem was - $servername = "a";
-
$username = "a";
-
$password = "a";
-
-
$conn = new mysqli($servername, $username, $password);
-
if ($conn->connect_error) {
-
die("Connection failed: " . $conn->connect_error);
-
}
i changed it to - $db = mysql_connect("a", "a", "a");
and it worked ^_^. Im so happy, finally i can sleep well tonight.
Once again, thanks a lot for your helps :D
RonB 589
Expert Mod 512MB
You just took a step backwards. The mysql_ functions have been depreciated for some time and will removed from the next release.
You should be using mysqli_ or PDO.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ben Allen |
last post by:
Hi,
I've created a mySQL database with the fields id, title and content.
'ID' is a unique field. Any ideas on how I can use PHP to generate a
list of the titles which are links. When you click on...
|
by: brian |
last post by:
This is the first time I have tried to create dynamic
controls. I am trying to create a hyperlink control.
The control will display properly but the event isn't
triggered.
I read a lot of...
|
by: UtilityWarrior |
last post by:
If you use Visual Basic 6 or VB.net and want to create PDFs from images royalty free then this DLL is for you.
The Image to PDF Dynamic Link Library (DLL) will convert one or more images (JPEG,...
|
by: UtilityWarrior |
last post by:
If you use C and want to create PDFs from images royalty free then this
DLL is for you.
The Image to PDF Dynamic Link Library (DLL) will convert one or more
images (JPEG, TIFF, PNG, GIF, BMP,...
|
by: mike888 |
last post by:
I want to create dynamic iframe content like below but in Firefox
<iframe width="100%" height="100" src="#"></iframe>
<script language="JavaScript"><!--
document.frames.document.open();...
|
by: =?GB2312?B?ufnTwr78?= |
last post by:
Hello:
My OS is Linux, I compile my dynamic link libraries , and
want to call the function of my dynamic library through python!
How can I realize the function? Please give me some advices! Thanks
|
by: prashant |
last post by:
hi,
i am trying to create an xml tag ref to hold link.php?id=1; or
link.php?id=2 and so on.
I want the links for all the fields(id) in the databse so that when i
call them in my html page for...
|
by: imarkdesigns |
last post by:
Hi to all masters...
hope someone can help here out to share good or better idea on how to change a dynamic link to plain file link in CMS...
here is my sample page for About us instead of...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |