Jump to content

Hyperlink result in php


hanna1

Recommended Posts

Hi,

 

I have a php program where the query result will turn to hyperlink. But my problem is when i click the hyperlink search result it returns to blank page, I have a hard time working on this around. I'm newbie in php please help me thanks.  :'(

 

Below is my code:

 

//hyperlink_result.php (this code is the hyperlink query result)

 

//echo out construct

$sql = "SELECT * FROM search WHERE $construct";

$run = mysql_query($sql);

 

 

$foundnum = mysql_num_rows($run);

if ($foundnum==0)

echo "No results found.";

else

{

echo "$foundnum results found!<p>";

 

while ($runrows= mysql_fetch_array($run))

{

//hyperlink search result

 

 

$title = $runrows['title'];

 

//echo '<p><a href="hyperlink_results.php?id='.$runrows['id'].'">'.$runrows['title'].'</a></p>';

echo "<a href=\"hyperlink_results.php?id=".$runrows['id']."\">".$title."</a>";

 

 

}

}

 

 

 

 

// hyperlink_results.php (this code will fetch hyperlink query)

 

if (isset($_GET['id']))

{

include ("module/conn.php");

$select=mysql_query("SELECT * FROM search WHERE id='".$_GET['id']."'");

$r = mysql_num_rows($select);

 

while($row= mysql_fetch_array($r)){

 

$des = $row['description'];

$title = $row['title'];

 

echo "$des";

echo "$title";

 

 

}

 

}

}

 

 

Link to comment
Share on other sites

mysql_fetch_array expects a result resource, not the number of rows your query returns. A result resource is returnedby mysql_query. So you need to pass thee $select variable to mysql_fetch_array, not the $r variable

$select=mysql_query("SELECT * FROM search WHERE id='".$_GET['id']."'");
   $r = mysql_num_rows($select);
   
            while($row= mysql_fetch_array($r)){

 

Change $row= mysql_fetch_array($r) to $row= mysql_fetch_array($select) in hyperlink_results.php

 

Also when developing your scripts you should configure PHP so error_reporting is set to E_ALL and set  display_errors to on. You can do this either within your php.ini or within your scripts using

error_reporting(E_ALL);
ini_set('display_errors', 1);

Enabling these two directives will display any PHP errors on screen rather than a blank screen.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.