Jump to content

Recommended Posts

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

 

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

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-

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.

 

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.

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.