Jump to content

Display table results as link


yoda69

Recommended Posts

Hey,

So. I've got a php script that pulls data and present it in a table. Now, I would like that results to show up as a link (one field), so the user can click on the link and get a generated page which brings up all the fields of that specific dataraw.

 

questions:

 

1. how to show a result in a table as a link?

2. how to create that link to generate another page with all the fields associated with that specific master key.

 

p.s.

Of course my table has a primary index.

tnx ahead.

 

Here's an example of my script:

 

<?PHP

$db = mysql_connect("localhost","root","password") or die("Problem connecting");

mysql_select_db("education") or die("Problem selecting database");

$query = "SELECT discipline, title, teacher, institution, description  FROM teachings";

$result = mysql_query($query) or die ("Query failed");

//let's get the number of rows in our result so we can use it in a for loop

$numofrows = mysql_num_rows($result);

?>

 

<?PHP

echo "<TABLE BORDER=\"1\" width=\"84%\">\n";

echo "<TR bgcolor=\"lightblue\">

<TD>Discipline</TD>

<TD>Teacher</TD>

<TD>Title</TD>

<TD>Institution</TD>

<TD>Description</TD></TR>\n";

for($i = 0; $i < $numofrows; $i++) {

$row = mysql_fetch_array($result); //get a row from our result set

if($i % 2) { //this means if there is a remainder

echo "<TR bgcolor=\"#CCFFCC\">\n";

} else { //if there isn't a remainder we will do the else

echo "<TR bgcolor=\"#BFD8BC\">\n";

}

echo "<TD>".$row['discipline']."</TD>

<TD>".$row['teacher']."</TD>

<TD>".$row['title']."</TD>

<TD>".$row['institution']."</TD>

<TD>".$row['description']."</TD>

\n";

echo "</TR>\n";

}

 

echo "</TABLE>\n";

?>

 

Link to comment
https://forums.phpfreaks.com/topic/54790-display-table-results-as-link/
Share on other sites

Hey guys,

Sorry for the specifics i'm asking for, but can you please show me how I actually write the entire code line:

:-[

If this is the echo statement:

echo "<TD>".$row['discipline']."</TD>;

 

how do i put this inside:

<a href="showall.php?id={$row["id"]}">link text[/url]

 

Thanks ahead

 

Thanks, this is exactly what i was looking for.

Another question:

 

echo "<td><a href='showall.php?id={$row[id]}'>".stripslashes($row[discipline])."</a></td>";

 

 

the name of my "id" field is primary_index (for some complicated reason - whatever!!!)

 

so, should it be like this:

echo "<td><a href='showall.php?id={$row[primary_index]}'>".stripslashes($row[discipline])."</a></td>";

 

or like this:

echo "<td><a href='showall.php?primary_index={$row[primary_index]}'>".stripslashes($row[discipline])."</a></td>";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.