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
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

 

Link to comment
Share on other sites

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>";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.