Page 1 of 1

How do you link from mySQL results?

Posted: Sun Jan 25, 2004 3:00 pm
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

Posted: Sun Jan 25, 2004 3:43 pm
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

parse error

Posted: Sun Jan 25, 2004 9:42 pm
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???

Posted: Mon Jan 26, 2004 8:54 am
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.

{
{
{
}
?
?>

Posted: Mon Jan 26, 2004 3:09 pm
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

Posted: Mon Jan 26, 2004 3:09 pm
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