How do you link from mySQL results?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
tstimple
Forum Commoner
Posts: 53
Joined: Wed Jan 21, 2004 10:12 pm

How do you link from mySQL results?

Post by tstimple »

I have been trying some pre-written PHP scripts that render a results table from a mySQL table query (adodb-pager, ez_results, etc)

These produce nice formatted tables with navigation through the multiple pages.

My question is:
I would like one column of the results on these tables (ie a NAME field) to also be a LINK to another page, so that a user could query a database table and then CLICK on one of the results to get to a more detailed page.

I am trying to learn PHP and have not really sean this implemented.

Does anyone know if one of these canned scripts could be adapted to do this? Or how I would write the code?
Thanks again to all the Pros who answer questions from newbies like me...
--Tim
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Not quite sure what you mean but heres my jab @ it

Code: Select all

<?php
   
 // Connect to the database server 
  $dbcnx = @mysql_connect("localhost", "username", "password"); 
  if (!$dbcnx) { 
    echo( "Unable to connect to the database server at this time." 
    ); 
    exit(); 
    } 
 
if (! @mysql_select_db("your_db") ) { 
     echo( "<p>Unable to locate the " . "database at this time.</p>" ); 

$result = @mysql_query("SELECT * FROM your_row");

while ( $row = mysql_fetch_array($result) ) { 
		$yourlink= $row["yourlink"]; 

echo "<a href="http://www.yourdomain.com/$yourlink">This is a link</a>";
} 


?>

Code: Select all

<?php
$yourlink= $row["yourlink"]; 

?>
The braceted "yourlink" is what the field name is
tstimple
Forum Commoner
Posts: 53
Joined: Wed Jan 21, 2004 10:12 pm

parse error

Post by tstimple »

phenom,

First, is the second piece of php code to be included on the same page?, or is that just for reference to explain what the ["yourlink"] is?

In either case I get a Parse error for the last line of code (the line with the ?>)

help???
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

while ( $row = mysql_fetch_array($result) ) { 
      $yourlink= $row["yourlink"];
$row["yourelink"]; <-- information retrieved from database.

yourlink = downloads
yourlink = uploads
yourlink = baseball

And so on..

parse error;'

NOte that not everthing has been closed.

{
{
{
}
?
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php
<?php 
    
// Connect to the database server 
  $dbcnx = @mysql_connect("localhost", "username", "password"); 
  if (!$dbcnx) { 
    echo( "Unable to connect to the database server at this time." 
    ); 
    exit(); 
    } 

if (! @mysql_select_db("your_db") ) { 
     echo( "<p>Unable to locate the " . "database at this time.</p>" ); 
     } // ADDING A CLOSING BRACKET

$result = @mysql_query("SELECT * FROM your_row"); 

while ( $row = mysql_fetch_array($result) ) { 
      $yourlink= $row["yourlink"]; 

echo "<a href="http://www.yourdomain.com/$yourlink">This is a link</a>"; 
} 


That should fix the parse error

?>
Btw the 2nd bit of code was just a reference, you do not need to add again :D

Phenom
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php
<?php 
    
// Connect to the database server 
  $dbcnx = @mysql_connect("localhost", "username", "password"); 
  if (!$dbcnx) { 
    echo( "Unable to connect to the database server at this time." 
    ); 
    exit(); 
    } 

if (! @mysql_select_db("your_db") ) { 
     echo( "<p>Unable to locate the " . "database at this time.</p>" ); 
     } // ADDING A CLOSING BRACKET

$result = @mysql_query("SELECT * FROM your_row"); 

while ( $row = mysql_fetch_array($result) ) { 
      $yourlink= $row["yourlink"]; 

echo "<a href="http://www.yourdomain.com/$yourlink">This is a link</a>"; 
} 

?>
That should fix the parse error

Btw the 2nd bit of code was just a reference, you do not need to add again :D

#*@( sorry for the double post. :D
Phenom
Post Reply