SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast comusher's Avatar
    Join Date
    Feb 2008
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple PHP code help needed

    I have a site that is PHP/MySQL and I really do not know programming but can change an existing site.

    The site has "products" with the classic name, description, price, etc variables stored in a database. I want to embed a link in that description. If I do so now it only appears as text.

    How do I make it a link? With a change on the database? Or a change in how it is displayed in the PHP page?

    Thanks in advance for the help!

  2. #2
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's either in the code that inserts the text into the database or the code that is displaying it, one of them appears to be converting the html.

  3. #3
    SitePoint Enthusiast comusher's Avatar
    Join Date
    Feb 2008
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can I tell which one I need to switch and to what?

  4. #4
    SitePoint Addict Smola's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you post some code for us to look at. It'd be beneficial to see what changes you are trying to make and the existing code.
    Humbly,

    Smola

  5. #5
    SitePoint Enthusiast comusher's Avatar
    Join Date
    Feb 2008
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the code which creates the page that shows the product, I would like the link in the description.




    <tr>
    <td width="35&#37;" align="center"><img src="resizeimage.php?image=images/dog/<?php
    echo $db[$i]['image']; ?>&maxheight=200&maxwidth=200" border="1" /></td>
    <td width="65%"><table width="100%">
    <tr>
    <td width="40%">Name</td>
    <td width="60%">: <?php echo $db[$i]['name']; ?></td>
    </tr>
    <tr>
    <td>Gender</td>
    <td>: <?php echo $db[$i]['gender']; ?></td>
    </tr>
    <tr>
    <td>Birth Date</td>
    <td>: <?php
    $vipul = $db[$i]['bdate'];
    $vip = date('m-d-Y', strtotime($vipul));
    echo $vip." "."(MM/DD/YYYY)";
    ?></td>
    </tr>

    <tr>
    <td>Description</td>
    <td>: <?php echo $db[$i]['detail']; ?></td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td width="100%" valign="top" align="left" background="images/line_dot.gif" height="1" colspan="2"><img border="0" src="images/line_dot.gif" width="1" height="1"></td>
    </tr>

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you want to be the Text of the link? ie, what text do you click on? Where are you getting the link from - the database or is it arbitrary?

  7. #7
    SitePoint Addict Smola's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems as though you haven't altered anything yet. I would decide if there were a common directory for all the pages that would be linked to and then just store the directory and filename in the database and add some code like

    Code php:
    <a href=<?php echo '"http://www.yoursite.com/'.$dir_link.'">'.$link_text; ?></a>
    Humbly,

    Smola

  8. #8
    SitePoint Enthusiast comusher's Avatar
    Join Date
    Feb 2008
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The link I want to be clickable html is in the ['detail'] description which is in the database. But right now it comes out as plain text.

  9. #9
    Non-Member
    Join Date
    Apr 2009
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <td>: <a><?php echo $db[$i]['detail']; ?></a></td>
    See how I set it up? just put the linnks there and echo all that inside the a tag then close it

  10. #10
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    220
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Red face

    Quote Originally Posted by comusher View Post
    The link I want to be clickable html is in the ['detail'] description which is in the database. But right now it comes out as plain text.
    if what u need is converting string of "http://..." into clickable link, this function may help:--

    function convert_link($text,$target){
    return ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a target=\"$target\" href=\"\\0\">\\0</a>", $text);
    }

    $description = $db[$i]['detail'];

    $description = convert_link($description, '_blank');

    <tr>
    <td>Description</td>
    <td>: <?php echo $description; ?></td>
    </tr>
    </table></td>
    </tr>



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
  •