yoda69 Posted June 8, 2007 Share Posted June 8, 2007 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"; ?> Quote Link to comment Share on other sites More sharing options...
chigley Posted June 8, 2007 Share Posted June 8, 2007 If your rows have ids, <a href="showall.php?id={$row["id"]}">link text</a>, then in showall.php a bit of security and receive the data Quote Link to comment Share on other sites More sharing options...
unidox Posted June 8, 2007 Share Posted June 8, 2007 Damn, chigley posted the answer b4 me Quote Link to comment Share on other sites More sharing options...
yoda69 Posted June 8, 2007 Author Share Posted June 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
penguin0 Posted June 8, 2007 Share Posted June 8, 2007 You really should have an id field for all your tables, that is an auto_increment number. Once you create that in your table teachings, then this will work: echo "<TD>".<a href="showall.php?id={$row["id"]}">link text</a>."</TD>; Quote Link to comment Share on other sites More sharing options...
Mr Chris Posted June 8, 2007 Share Posted June 8, 2007 Is this what you are after Yoda 69, something like below or do I misunderstand? echo "<td><a href='showall.php?id={$row[id]}'>".stripslashes($row[discipline])."</a></td>"; Quote Link to comment Share on other sites More sharing options...
yoda69 Posted June 8, 2007 Author Share Posted June 8, 2007 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>"; Quote Link to comment Share on other sites More sharing options...
yoda69 Posted June 8, 2007 Author Share Posted June 8, 2007 IT WORKS!!!!!!!!!!!!!!!!!! Thank you so much!!!!!!!!!!!!!!! Quote Link to comment Share on other sites More sharing options...
Mr Chris Posted June 8, 2007 Share Posted June 8, 2007 No probs - glad I could help ;-) Quote Link to comment Share on other sites More sharing options...
penguin0 Posted June 8, 2007 Share Posted June 8, 2007 Why do i see [/url] instead of </a>? Does it work the same or am I missing somthing? Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 8, 2007 Share Posted June 8, 2007 The forum does it to stop users posting html in this case anchor tags Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.