phpnewbie1979 Posted February 3, 2010 Share Posted February 3, 2010 I'm using the script below to show all rows in the database. I want to make each row a link that will open up in another window. I can use javascript onclick href function in the "<tr>" tag but being that each row needs to have a different link I can't figure how to automate this with php and how to add the link using my cms. Any help would be greatly appreciated <?php require_once "connect_to_mysql.php"; $query="SELECT * FROM table_name"; $result=mysql_query($query); $num=mysql_num_rows($result) or die(mysql_error()); mysql_close();?> <div> <table border="0" cellspacing="0" cellpadding="0"> <?php$i=0;while ($i < $num) { $c0=mysql_result($result,$i,"fieldone"); $c1=mysql_result($result,$i,"fieldtwo"); $c2=mysql_result($result,$i,"fieldthree"); $c3=mysql_result($result,$i,"fieldfour"); $c4=mysql_result($result,$i,"fieldfive"); $c5=mysql_result($result,$i,"fieldsix"); $c6=mysql_result($result,$i,"fieldseven"); $c7=mysql_result($result,$i,"fieldeight"); $c8=mysql_result($result,$i,"fieldnine"); $c9=mysql_result($result,$i,"fieldten"); ?> <tr> <td class="td_border_left" width="50"><?php echo $id; ?></td> <td class="td_border_right" width="300"><strong><?php echo $c1; ?></strong><br /> <?php echo $c2; ?><br /><?php echo $c3; ?>, <?php echo $c4; ?><br /> <br /><strong>Program:</strong> <?php echo $c5; ?><br /><br /><strong>Waiting List:</strong> <?php echo $c6; ?><br /><strong>Type:</strong <?php echo $c7; ?><br /><strong>Application Deadline:</strong> <?php echo $c8; ?><br /><strong>Application Deadline:</strong> <?php echo $c9; ?><br /> </td> </form> </tr> <?php$i++; } ?> </table> </div> Quote Link to comment https://forums.phpfreaks.com/topic/190819-help-trying-to-make-a-table-row-into-a-link/ Share on other sites More sharing options...
ChemicalBliss Posted February 3, 2010 Share Posted February 3, 2010 im sure you could use divs. <div style="width: 300; height: 50;" onClick="window.location.href='somepage.htm'">Some link text or whatever</div> You could style them however you want too, and position them to the pixel. -CB- Quote Link to comment https://forums.phpfreaks.com/topic/190819-help-trying-to-make-a-table-row-into-a-link/#findComment-1006264 Share on other sites More sharing options...
phpnewbie1979 Posted February 3, 2010 Author Share Posted February 3, 2010 Thanks for the reply but the script calls for each row in the database to show. if I use <div style="width: 300; height: 50;" onClick="window.location.href='somepage.htm'">Some link text or whatever</div> then each link would be the same. I need each row to link to a different url. Quote Link to comment https://forums.phpfreaks.com/topic/190819-help-trying-to-make-a-table-row-into-a-link/#findComment-1006301 Share on other sites More sharing options...
wildteen88 Posted February 3, 2010 Share Posted February 3, 2010 What is the link you want to create? Could you provide an example. Quote Link to comment https://forums.phpfreaks.com/topic/190819-help-trying-to-make-a-table-row-into-a-link/#findComment-1006305 Share on other sites More sharing options...
phpnewbie1979 Posted February 3, 2010 Author Share Posted February 3, 2010 Each row of the database holds information about an apartment building. When someone clicks on the row I want it to link to the building's website in a new window. My problem is, because each row has a different link I can't figure out how to word the script to accomplish this. Quote Link to comment https://forums.phpfreaks.com/topic/190819-help-trying-to-make-a-table-row-into-a-link/#findComment-1006363 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.