Below is the code in which I am creating the list of URL s with the information of hotels in a city, the problem is when click on the URL no values are being displayed. please let me know how should i modify the code.

    <?php
    include ('connectdb.php');
    $query = "SELECT type, name, location, landmark FROM table1";
    $result = @mysql_query($query);
    echo mysql_error();
    if ($result) {
    while($arr = mysql_fetch_array($result, MYSQL_ASSOC)){
    $resultlink = "\n\t<li><a href=\"posts.php?ID={$arr['id']}+{$arr['type']}+{$arr['name']}\">{$arr['name']} {$arr['location']}</a></li>";
                $end_result    .= '<li>' . $resultlink . '</li>';
    $resultlink  .=     "
        \n<p>Name: {$arr['name']}</p>
        \n<p>Type: {$arr['type']}</p>
        \n<p>Location: {$arr['location']}</p>";
            }
            echo $end_result;
        }  else {
            echo "<p>Sorry no results for $word</p>";
            }
    ?>
//you
while($arr = mysql_fetch_array($result, MYSQL_ASSOC)){    
    $resultlink = "\n\t<li><a href=\"posts.php?ID={$arr['id']}+{$arr['type']}+{$arr['name']}\">{$arr['name']} {$arr['location']}</a></li>";

// example to try
while ($arr = mysql_fetch_array($results)){
    echo "<a href='posts.php?id='".$arr['id']."&type=".$arr['type']."'>".$arr['name']." ".$arr['location']."</a>";
}

those two outputs would be quite different.

given an example; id=1, type='X', name='test', location='here':

"\n\t<li><a href=\"posts.php?ID={$arr['id']}+{$arr['type']}+{$arr['name']}\">{$arr['name']} {$arr['location']}</a></li>";

"
    <li><a href="posts.php?ID=1+X+test">test here</a></li>"

"<a href='posts.php?id='".$arr['id']."&type=".$arr['type']."'>".$arr['name']." ".$arr['location']."</a>";

"<a href='posts.php?id='1&type=test'>test here</a>"

It all depends on your desired result, but I see nothing wrong with your orriginal link code.

Allow me to point out, however, that your SQL statement does not in fact SELECT anything called 'id' ... and this may be the root of your problem.

Good catch, didnt even see that about the SQL SELECT statement.

id is missing in query.
$query = "SELECT id, type, name, location, landmark FROM table1";

It seems strings are not concatinated properly. Try this:

<?
 $output = "";
 while($arr = mysql_fetch_array($result, MYSQL_ASSOC))
 {
     $output.='<li>
            <a><a href="posts.php?ID='.$arr['id'].'&type='.$arr['type'].'&name='.$arr['name'].'">'.$arr['name'].' '.$arr['location'].'</a>
            <br /><p>Name: '.$arr['name'].'</p>
            <br /><p>Type: '.$arr['type'].'</p>
            <br /><p>Location: '.$arr['location'].'</p>
            </li>';
  }
  echo $output;       
?>

For more on concatenation read this http://www.daniweb.com/web-development/php/threads/369623/syntax-prpblems#post1588766

Hi Vibhaj, I have tried code the way yoy have posted but the values Name, Type, Locations are displayed directly on the bage. Instead i want those values to be displayed when I click on the links. In this case nothing is displayed when i click on the link.

missing 'ID' column is not problem in my code , i have corrected it and the links are displayed correctly. My problem is no values are being displayed when i click on the links.
I want to display,
Name:
Type:
Location:
when i click on the links. please let me know what modifications i have to do?

When user click on link user will be redirected to another page post.php, and on post.php all details should be displayed.. right??

Another case is when you click on link on the same page one popup will display all details using javascript.

So what you want??

I wanted the first case, when user clicks on the link a new page (or in the same page) with all the details should be displayed.

in that case:
let your post listing code is in list.php where all posts names are listed.
Now use below code for generating link.

echo '<li><a href="posts.php?ID='.$arr['id'].'">'.$arr['name'].' '.$arr['location'].'</a></li>';

Now when you click on post name, you will be redirected to posts.php?ID=23 // some ID.
Now on posts.php you need fetch data from database based on passed ID.

$query = "SELECT * FROM table1 where ID=".$_GET['ID'];

and then you can show all data for that id on posts.php.

Hi Vibaj, still i am confused. Could you please eloberate, it is better if you place complete code.
Thanks a lot for your quick responses

any body there to help me?

Member Avatar for diafol

You should use ID if you are using querystring to extract info from the DB.

if(isset($_GET['id'])){
    //get record from DB with SQL based on $_GET['id'] - you need to check/validate this first though
    //if record exists, display it
}

Your link should look like this:

<a href="display.php?id=7">Mytown Myarea</a>

You can produce this easily with the:

$output = '';
while(...){
    $output .= "<h3><a href=\"somepage.php?id={$arr['id']}\">{$arr['name']} {$arr['location']}</a></h3>\n<p>Name: {$arr['name']}</p>\n<p>Type: {$arr['type']}</p>\n<p>Location: {$arr['location']}</p>";
}
...
echo $output;

there is no problem in displaying the values and URLs on the page.
My problem is when i click on the URLs i want the values belonging to only that particluar row should be displayedon a new page like 'display.php?id=7-Mytown-Myarea' but that is not the case all the other URL's data is being displayed on the resulting page

    <?php
    include ('connectdb.php');
    $query = "SELECT type, name, location, landmark FROM table1";
    $result = @mysql_query($query);
    echo mysql_error();
    if ($result) {
    while($arr = mysql_fetch_array($result, MYSQL_ASSOC)){
    $output .= "<h3><a href=\"somepage.php?id={$arr['id']}\">{$arr['name']} {$arr['location']}</a></h3>\n<p>Name: {$arr['name']}</p>\n<p>Type: {$arr['type']}</p>\n<p>Location: {$arr['location']}</p>";
                $end_result    .= '<li>' . $resultlink . '</li>';
            }
            echo $output;
        }  else {
            echo "<p>Sorry no results for $word</p>";
            }
    ?>
Member Avatar for diafol

SHow the code for the resulting page. It should have something like:

if(isset($_GET['id'])){
    //get record from DB with SQL based on $_GET['id'] - you need to check/validate this first though
    //if record exists, display it
}

As my last post stated

i dont think there is a static resulting page, as the URL it self is dynamically created.
please correct me iam wrong

Member Avatar for diafol

If there is no page for the results to be shown - where are the results supposed to appear?
The url may be dynamic wrt querystring parameter (id) but there should be an actual page - or are you trying to show the details in the same page as the list of links. If so, just include the code idea I suggested in that page.

results should be displayed on a dynamically created URL like www.mywebsite.com/display.php?id=7-Mytown-Myarea

yes, so what diafol is referring to is the display.php page code - this is the actual page that displays data dynamically based on the url parameters.

Are you able to post the code you have in display.php ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.