...

View Full Version : how to display mysql results as hyperlinks with php



googleit
08-29-2006, 09:22 PM
how do i get the mysql results to display as veiw.php?id=#
this is my code so far






$link = mysql_connect('host', 'username', 'pass')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('dbname') or die('Could not select database');


$query = 'SELECT * FROM data';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";


mysql_free_result($result);


mysql_close($link);


any help?

GJay
08-29-2006, 09:26 PM
what?

-using 'SELECT *' isn't particularly helpful to others looking at your code
-you're iterating over all of the columns, where does the link come in to this?

googleit
08-29-2006, 09:30 PM
my question was were would i put the code to select the link from the table

Spookster
08-29-2006, 09:35 PM
Are you storing URLs in your database and wanting them to be displayed as hyperlinks or are you wanting to create hyperlinks that can then query your database?

GJay
08-29-2006, 09:37 PM
which link?
what table?

is there a link in 'data'? (not the best name for a table...)
if so, then it will be one of your columns, so something like



foreach ($line as $col_name=>$col_value) {
if($col_name=='link')
echo '<td><a href="'.$col_value.'">Click Here</a></td>';
else
echo "\t\t<td>$col_value</td>\n";

googleit
08-29-2006, 09:37 PM
storing hyperlinks in db



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum