www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need Help in PHP

  1. #1
    Join Date
    Dec 2008
    Posts
    1

    Post Need Help in PHP

    I run a PHP site ..

    Say i create a database that has one column say NAMES: its values are JHON etc. Now i need a code that can be put on my website and when a user visits the page and if the page has got JHON on it. It converts it into a hyperlink?

    Basically some code that calls my database that has NAMES and Fetches all the Name that it has and converts it into a hyperlink.

  2. #2
    Join Date
    Apr 2007
    Posts
    1,664
    There are a lot of PHP MySQL tutorials on the net. What you want to do is about as basic as it gets.

    First you should know a database has tables (which have names) and tables have columns (which have names). Databases don't have columns.

    You will of course need to change the data in this to match your database and table names.

    PHP Code:
    <? php
    mysql_connect
    ("db.YOURDOMAIN""DBUSERNAME""DBPASSWORD");
    mysql_select_db("DBNAME");

    /*
    the imaginary table 'tablename' has this data
    name    url
    bob    bobspage.html    
    john    johnsbetterpage.html
    */


    $query='SELECT * FROM tablename';
    $result=mysql_query($q);

    while(
    $row=mysql_fetch_assoc($r)){
        echo 
    '<a href="'.$row['url'].'">'.$row['name'].'</a><br />';
    }

    ?>

  3. #3
    Join Date
    Nov 2008
    Posts
    2,477
    A couple of typos in the above example, this is what SyCo meant:

    PHP Code:

    $query
    ='SELECT * FROM tablename';
    $result=mysql_query($query);

    while(
    $row=mysql_fetch_assoc($result)){
        echo 
    '<a href="'.$row['url'].'">'.$row['name'].'</a><br />';

    Also I think what you are asking is how to scan a page and replace any instances of name with the link? If so you are really thinking about it the wrong way round. You need to design your page so that the correctly hyperlinked name is there in the first place. Using the technique SyCo posted is the correct way to approach this problem.
    Last edited by Mindzai; 01-03-2009 at 06:00 AM.

  4. #4
    Join Date
    Apr 2007
    Posts
    1,664
    Yea I try not to over abbreviate when posting here but I'm all $q $r $k $v as that means plently to me. I try not to confuse here but sometimes they do slip by. Thanks for the corrections. I try to remind people, all code posted is to be considered is 'pseudo code'

    err I mean, congratulations you spotted the deliberate error of the day.

    I doubt this user even read this, he never did reply!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles