Forum Moderators: coopster
I have a postgresql database.
I have a search facility on there that retrives information from this database.
One peice of information that is retrived is a web site address.
So I would have:
JJB sports, London, www.jjbsports.co.uk
How do i get it so the user is able to click on the www.jjbsports.co.uk and then visit the web site.
Thanks in advance.
You need to:
That reading should get you started. Now here's some direct application including a little code snippet that can follow. Let's say the table that you are storing your data in is called
companiesand the column names in the table are
company,
city, and
url. I'm not sure which parameters you need to make a connection to your database so you may have to make that adjustment:
<?php
$company = 'JJB Sports';
$host = 'localhost';
$port = '5432';
$dbname = 'mydatabasename';
$user = 'myuserid';
$password = 'mypassword';
$dbconn = pg_connect [php.net]("$host $port $dbname $user $password");
if (!$dbconn) exit("A connection error occurred.");
$sql = "SELECT city, url FROM companies WHERE company = '$company'";
$rows = pg_query [php.net]($dbconn, $sql);
if (!$rows) exit("A query execution error occurred.");
$row = pg_fetch_array [php.net]($rows, 1, PGSQL_ASSOC);
print "You can visit $company in " . htmlentities [php.net]($row['city']);
print "<br />You can visit $company online at " . htmlentities [php.net]($row['url']);
pg_close($dbconn);
?>