Hi there what i'm trying to do is:

return a car manufacturer from a MySQL database and have the text returned a hyperlink to the car manufacturer website.

The below just returns the manufacturer without a hyperlink:

$row

Would i make a row in the database called 'carmakeurl', store the URL in that, then somehow echo it out.

$row


????


Thanks

If you are trying to retrieve 1 row of a mysql table via link then it is probably best to just have a unique number/hash column and link to the php page with that row id in it. Then when retrieving the row, you can just use SELECT * FROM `table` WHERE `id`='".mysql_real_escape_string($value)."' As for how to get the unique hash, just hash the date and time the the field was entered. Alternatively you could just make the id field the manufacturer field.

this is wrong syntax

$row['<a href=&websiteurl">$title</a>']

it could be like

<a href='&websiteurl'>$row[title]</a>

if you are fetching data from db and using it as a link

<a href='&websiteurl'>$row[title]</a>

i think this is what i'm looking for, but what if i want to retrieve the websiteurl from a row in the table as well. would it be like..

<a href='$row[websiteurl]l'>$row[title]</a>

?????

Thanks

Thanks BzzBee that works, but what if i want to retrieve the url from a row as well. rather than entering the URL in php.

<a href='$row[linkurlrow]'>$row[title]</a>

??

Thanks

Thanks BzzBee that works, but what if i want to retrieve the url from a row as well. rather than entering the URL in php.

<a href='$row[linkurlrow]'>$row[title]</a>

??

Thanks

thats going to work, as long as you update the table to include a column of urls, called linkrulrow

OMG!! this is driving me mad!!!!!!!!!!

$sql = 'SELECT * FROM cartable';
$finalurl = <a href='$row[carwebsiteurl]'>$row[carname]</a>;
echo $finalurl;

I have 1 table with 2 rows in my SQL database. The rows are named:

carwebsiteurl - this contains a URL which is http://www.ford.co.uk

&

carname - this contains the text ford.


It still shows errors!!!!

Hi,

You are missing double quotes

$sql = 'SELECT * FROM cartable';
$finalurl = <a href='$row["carwebsiteurl"]'>$row[carname]</a>;
echo $finalurl;

Hi,

You are missing double quotes

$sql = 'SELECT * FROM cartable';
$finalurl = <a href='$row["carwebsiteurl"]'>$row[carname]</a>;
echo $finalurl;

You are also missing the quotes around the html code. Try the following:

$sql = 'SELECT * FROM cartable';
$finalurl = '<a href=\''.$row['carwebsiteurl'].'\'>'.$row['carname'].'</a>';
echo $finalurl;
$sql = 'SELECT * FROM cartable';$finalurl = '<a href=\''.$row['carwebsiteurl'].'\'>'.$row['carname'].'</a>';echo $finalurl;

Now it just shows a blank page, no errors though!!!!

$sql = 'SELECT * FROM cartable';$finalurl = '<a href=\''.$row.'\'>'.$row.'</a>';echo $finalurl;


Now it just shows a blank page, no errors though!!!!

Just to check, you have actually executed the query, right? And fetched the result with mysql_fetch_assoc?

ou will need to paste your code so that we can check what is the actual problem

Just to check, you have actually executed the query, right? And fetched the result with mysql_fetch_assoc?

What exactly do you mean by that? Sorry i'm a complete newbie to this stuff.

i thought you just entered the:

Select * from bla bla bla bit

then it was selected???

Thanks

First you have to connect to your mysql_database with your username and password, and select the database you want to use.

Then you create your query (the select statement) and send that query to the server. Then you get your result back, and you can fetch the values.

// Connect to the database
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

// Select the database you want to use on the server
if (!mysql_select_db('databasename', $link)) {
   die('Could not select database: ' . mysql_error());
}

// Create the query-string. Nothing is selected yet
$query = "SELECT * FROM cartable";
// Send the query-string to actually perform the query
$result = mysql_query($query, $link);
if (!$result) {
    // This happens if there was something wrong with the query
    die('Invalid query: ' . mysql_error());
}

// Iterate over each row the select returned.
// mysql_fetch_assoc returns an associative array
// http://no2.php.net/manual/en/function.mysql-fetch-assoc.php
while ($row = mysql_fetch_assoc($result)) {
    // Now you can print the hyperlink
    print("<a href=\''".$row['carwebsiteurl']."\">".$row['carname']."</a>");
}

// Close the link when you're done
// This is also done automatically when the script ends. Do not open and close database connections for every query you do. You open one global connection to the database, and let all the scripts you execute use that one.
mysql_close($link);

See http://no2.php.net/manual/en/ref.mysql.php for more information about the different mysql_* functions.

Hope this helps :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.