Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-29-2006, 08:22 PM   PM User | #1
googleit
Regular Coder

 
googleit's Avatar
 
Join Date: Jul 2006
Location: birmingham, uk
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
googleit is an unknown quantity at this point
Question how to display mysql results as hyperlinks with php

how do i get the mysql results to display as veiw.php?id=#
this is my code so far

PHP Code:



$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($resultMYSQL_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?
googleit is offline   Reply With Quote
Old 08-29-2006, 08:26 PM   PM User | #2
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
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?
GJay is offline   Reply With Quote
Old 08-29-2006, 08:30 PM   PM User | #3
googleit
Regular Coder

 
googleit's Avatar
 
Join Date: Jul 2006
Location: birmingham, uk
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
googleit is an unknown quantity at this point
my question was were would i put the code to select the link from the table
googleit is offline   Reply With Quote
Old 08-29-2006, 08:35 PM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
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?
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 08-29-2006, 08:37 PM   PM User | #5
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
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

PHP Code:
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"
GJay is offline   Reply With Quote
Old 08-29-2006, 08:37 PM   PM User | #6
googleit
Regular Coder

 
googleit's Avatar
 
Join Date: Jul 2006
Location: birmingham, uk
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
googleit is an unknown quantity at this point
storing hyperlinks in db
googleit is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:42 AM.


Advertisement
Log in to turn off these ads.