SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A href link with 'id'

    Hello Guys,

    I am a newbie and have spent many hours searching on the net but have not been able to do it.

    I am trying to create a link with a thumbnail image on (summary.php page). When the link is clicked, I want a new page (say detail.php) to open. However, the link is supposed to reveal more pictures and information. All the information sit on one table in the same database and I want a link from the summary.php page to reveal all the information on that same record on the other page (detail.php page). I do not know how to transfer the "id" to the detail page in order to specify in a query to reveal the whole information on the clicked image link.

    Below is the query to display information on the summary page.

    summary.php page

    $sql = mysql_query("SELECT * FROM classified");
    while($row = mysql_fetch_array($sql)){
    echo "<table border = '1'>";
    echo "<tr>";
    $id = $row['id'];
    echo "<td rowspan = '3'>" . '<a href = "details.php?id = $id" . ">"' . "<img src ='" . $row['photo1small'] ."'" . "/>" . "</a>". "</td>";
    echo "<td width = '300'>". $row['title'] . "</td>";
    echo "<td width = '100'>". $row['price'] . "</td>";
    echo "</tr>";
    echo "</table>";
    echo "<br/>";
    }

    detail.php page


    <?php
    $id = $_GET['id'];
    echo $id;

    ?>

    Parse error: syntax error, unexpected '"', expecting ',' or ';' in C:\wamp\www\showclassified.php on line 11

    I keep getting errors like the one above and I would appreciate if someone could help me with this.

    Thank you

    Kofifred

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This code:
    PHP Code:
    $id 15;
    $row['photo1small'] = 'photo1small';

    echo 
    "<td rowspan = '3'>" '<a href = "details.php?id = $id" . ">"' "<img src ='" $row['photo1small'] ."'" "/>" "</a>""</td>"
    produces this output:
    HTML Code:
    <td rowspan = '3'><a href = "details.php?id = $id" . ">"<img src ='photo1small'/></a></td>
    As you can see there are too many spaces that should not be there
    The $id variable didn't behave as a variable
    There is a dot and double quotes that should not be there

    You're better off using a different way to write that string:
    PHP Code:
    $id 15;
    $row['photo1small'] = 'photo1small';

    echo 
    "<td rowspan='3'><a href='details.php?id={$id}'><img src='{$row['photo1small']}'/></a></td>"
    and then you get
    HTML Code:
    <td rowspan='3'><a href='details.php?id=15'><img src='photo1small'/></a></td>
    Denny Schlesinger
    web services

  3. #3
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    It worked. Thank you

    Thank you. It worked. You have saved me a lot.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •