suttercain Posted February 13, 2007 Share Posted February 13, 2007 Hello, I am generating a basic list, which is showing up fine, from MySQL and am having a problem making the links work. I am pulling the ID and Title from a table. The Title are clickable and should be taken to that page based on the ID, but instead the ID is showing up blank: How it's coming up: http://supermandatabase.com/modules.php?name=4ndvddb&rop=show_dvd&id= How it should come up: http://www.supermandatabase.com/modules.php?name=4ndvddb&rop=show_dvd&id=1282 Where am I going wrong? As a bonus I would also like to make the list sortable by the end user. They can click Title and have it alphabetize or ID and have it order by number. <?php $sql = "SELECT id,title FROM tablename"; $result = mysql_query($sql); $link = "<a href='modules.php?name=4ndvddb&rop=show_dvd&id=$row[id]'>"; //uncomment $link and $el if you want it linkable $td = "<td>"; $el = "</a>"; echo "<table border=0 cellspacing=0 cellpadding=2 width=200>"; echo "<tr><td>ID<td>Title"; while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { echo "<tr><td>"; printf ("%s $td $link %s $el", $row[0], $row["title"]); } mysql_free_result($result); ?> Any help would be appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/38336-where-am-i-going-wrong/ Share on other sites More sharing options...
simcoweb Posted February 13, 2007 Share Posted February 13, 2007 You might try doing it this way: <?php while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { echo "<tr><td>"; echo "<a href='modules.php?name=4ndvddb&rop=show_dvd&id=" . $row['id'] . "'> Title: " . $row['title'] . "</a> "; echo "</td></tr>"; } ?> Link to comment https://forums.phpfreaks.com/topic/38336-where-am-i-going-wrong/#findComment-183740 Share on other sites More sharing options...
suttercain Posted February 13, 2007 Author Share Posted February 13, 2007 That is great. Thank you. Not to be too picky, but I hoping to keep the layout as: ID TITLE 1 Super 2 Happy With the code in the reply it allows the links to work great but I lose that layout and get the TITLE echoing and I lose the ID so it look as Title: Super Title: Happy Title: Yo Yo Yo Link to comment https://forums.phpfreaks.com/topic/38336-where-am-i-going-wrong/#findComment-183764 Share on other sites More sharing options...
simcoweb Posted February 13, 2007 Share Posted February 13, 2007 Yes, I assumed you wanted the title to be a hyperlink so I set it up that way. If you want to display the id and title in separate cells and also make the id the hyperlink then you'd do this. Also note that there's a <TH> tag in there that will name your fields for you. <?php echo "<table><tr>"; echo "<th>ID</th><th>Title</th></tr>"; while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { echo "<tr><td><a href='modules.php?name=4ndvddb&rop=show_dvd&id=" . $row['id'] . "'>ID</a><td> " . $row['title'] . "</td></tr> "; } echo "</table><br>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/38336-where-am-i-going-wrong/#findComment-183786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.