/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SyCoJan 02.2009 — 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.

[code=php]<? 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 />';
}

?>[/code]
Copy linkTweet thisAlerts:
@MindzaiJan 03.2009 — A couple of typos in the above example, this is what SyCo meant:

[code=php]

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

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


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.
Copy linkTweet thisAlerts:
@SyCoJan 05.2009 — 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!
×

Success!

Help @Anurag_Sharma spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...