473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dynamic Link with php content from database doesn't appear

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
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $search = $_GET['search'];
  3. $terms = explode(" ", $search);
  4. $query = "SELECT * FROM search WHERE ";
  5. foreach ($terms as $each){
  6. $i++;
  7. if ($i == 1) 
  8. $query .= "keywords LIKE '%$each%' ";
  9. else
  10. $query .= "OR keywords LIKE '%$each%' ";
  11. }
  12.  
  13. $db = mysql_connect("a", "a", "a");
  14. mysql_select_db("a");
  15. mysql_query("SET NAMES UTF8", $db);
  16. $query = mysql_query($query);
  17. $numrows = mysql_num_rows($query);
  18. if ($numrows > 0) {
  19. while ($row = mysql_fetch_array($query)) {
  20. $id = $row['id'];
  21. $title = $row['title'];
  22. $description = $row['description'];
  23. $keywords = $row['keywords'];
  24. $link = $row['link'];
  25.  
  26. echo "<div id='kq' ><a href='http://bytes.com/a/rs.php?id=$id'>$title</a></div></br >";
  27. }
  28. }
  29. else
  30. echo "<div id='kq1'> '$search'</div>";
  31.  
  32. mysql_close ();
  33. ?>
  34.  
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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $newid = (int) $_GET['id'];
  3.  
  4. $servername = "a";
  5. $username = "a";
  6. $password = "a";
  7.  
  8. $conn = new mysqli($servername, $username, $password);
  9. if ($conn->connect_error) {
  10.     die("Connection failed: " . $conn->connect_error);
  11.  
  12. mysql_select_db("a", $db);
  13.  
  14. $newid = (int) $_GET['id'];
  15. $result = mysql_query("SELECT * FROM 'search' WHERE id = 1", $db) ;
  16. $myrow = mysql_fetch_array($result);
  17.  
  18.  
  19. echo $myrow["title"];
  20. mysql_close();
  21. ?> <html> <head> <meta charset='utf-8'> <title>dd</title> </head> <body> <?php echo $myrow['title']; ?> </body> </html>
  22.  
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...
May 2 '15 #1
8 1753
Rabbit
12,516 Expert Mod 8TB
On line 16, you're only looking for Id = 1
May 2 '15 #2
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:
Expand|Select|Wrap|Line Numbers
  1. $newid = (int) $_GET['id'];
  2. $result = mysql_query("SELECT * FROM 'search' WHERE id = $newid", $db) ;
  3. $myrow = mysql_fetch_array($result);
  4.  
  5. echo $newid;
  6. echo sdqsd;
  7. echo $myrow["title"];
  8. mysql_close();
  9. ?>
  10.  
  11. <html>
  12.     <head>
  13.         <meta charset='utf-8'>
  14.         <title>dd</title>
  15.     </head>
  16.  
  17.     <body>
  18.         <?php echo $myrow['title']; ?>
  19.     </body>
  20.  
  21. </html>

Still doesn't work though. I try
Expand|Select|Wrap|Line Numbers
  1. echo $newid
this time, apparently it's fine. It got the right id. But the title doesn't appear.
I also used
Expand|Select|Wrap|Line Numbers
  1. if ($conn->connect_error) {
  2.     die("Connection failed: " . $conn->connect_error);
  3. echo "Connected successfully";
  4. ?>
The connection to database seems to be good too. hmmm Still working on this.
May 2 '15 #3
RonB
589 Expert Mod 512MB
Try dumping $myrow to see if it holds what you expect.

Change:
Expand|Select|Wrap|Line Numbers
  1. <?php echo $myrow['title']; ?>
To:
Expand|Select|Wrap|Line Numbers
  1. <?php print_r($myrow); ?>
or:
Expand|Select|Wrap|Line Numbers
  1. <?php var_dump($myrow); ?>
May 2 '15 #4
Rabbit
12,516 Expert Mod 8TB
You should check that the table has
1) the id you're searching for
2) a field named title
3) the field is populated
May 2 '15 #5
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.
May 2 '15 #6
With
Expand|Select|Wrap|Line Numbers
  1. <?php print_r($myrow['title']); ?>
nothing change . With
Expand|Select|Wrap|Line Numbers
  1. <?php var_dump($myrow['title']); ?>
i got the "NULL". hmm. I check id, title, ... everything was right but it still doesn't work ...
May 2 '15 #7
Thanks god, finally I work it out, thanks so much for your helps.
the problem was
Expand|Select|Wrap|Line Numbers
  1. $servername = "a";
  2. $username = "a";
  3. $password = "a";
  4.  
  5. $conn = new mysqli($servername, $username, $password);
  6. if ($conn->connect_error) {
  7.     die("Connection failed: " . $conn->connect_error);
i changed it to
Expand|Select|Wrap|Line Numbers
  1. $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
May 2 '15 #8
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.
May 2 '15 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
1
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...
0
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,...
2
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,...
1
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();...
2
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
12
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...
1
imarkdesigns
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...
0
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
0
BarryA
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...
1
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...
0
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...
0
marktang
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,...
0
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.