Welcome Guest, Not a member yet? Register   Sign In
Linking from database results table
#1

[eluser]danfloun[/eluser]
Hi,

I'm pulling some info from my database and laying it down like so:

Code:
<table>
    <tr>
        <th>Id</th>
        <th>Company</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Landline Tel</th>
        <th>Mobile Tel</th>
        <th>Fax Tel</th>
        <th>Email</th>
    </tr>
    
&lt;?php foreach($query->result() as $row): ?&gt;

    <tr><a href="&lt;?=site_url('main/client_detail/' .$row->id);?&gt;">
        <td>&lt;?=$row->company;?&gt;</td>
        <td>&lt;?=$row->first_name;?&gt;</td>
        <td>&lt;?=$row->last_name;?&gt;</td>
        <td>&lt;?=$row->landline_tel;?&gt;</td>
        <td>&lt;?=$row->mobile_tel;?&gt;</td>
        <td>&lt;?=$row->fax_tel;?&gt;</td>
        <td>&lt;?=$row->email;?&gt;</td></a>
    </tr>

&lt;?php endforeach;?&gt;

</table>

Probably a crap way to do it, but nevertheless it works except I'm not sure how to make each full row linkable to the details page. I've checked an old project and the above worked but not here.

I'm sure the link I have is completely wrong so if anyone can help that would be cool.

I don't just want one column to be linkable I want the whole row.

Thanks

Danny
#2

[eluser]Michael Wales[/eluser]
You can't link across table cells (the TD tags). You were probably using a bit of javascript to determine if a row was clicked on - and if it was - direct the user to the corresponding page.

It could also be done with some CSS and some crazy padding - but that would be a mess.
#3

[eluser]crikey[/eluser]
It's invalid HTML (XHTML 1.0 Transitional) to place your anchor tags there.

As walesmd said, one option would be to use Javascript and add an onClick handler to each <tr> tag. The caveat here of course is that it's device-dependent (ie. only works for mouse users).
#4

[eluser]John_Betong[/eluser]
Hi DanFloun,

>>> I’m not sure how to make each full row linkable to the details page.
&nbsp;
Try this:
&nbsp;
&nbsp;
Code:
&lt;?php foreach($query->result() as $row): ?&gt;

  <tr>
    <td>  
      <a href="&lt;?=site_url('main/client_detail/' .$row->id);?&gt;">
           <span style='margin:0 12em 0 0; '>    &lt;?= $row->company ?&gt;       </span>
           <span style='margin:0 12em 0 0; '>    &lt;?= $row->first_name ?&gt;    </span>
           <span style='margin:0 12em 0 0; '>    &lt;?= $row->last_name ?&gt;     </span>
           <span style='margin:0 12em 0 0; '>    &lt;?= $row->landline_tel ?&gt;  </span>
           <span style='margin:0 12em 0 0; '>    &lt;?= $row->mobile_tel ?&gt;    </span>
           <span style='margin:0 12em 0 0; '>    &lt;?= $row->fax_tel ?&gt;       </span>
           <span style='margin:0 12em 0 0; '>    &lt;?= $row->email ?&gt;         </span>
      </a>
    </td>  
  </tr>

&lt;?php endforeach ?&gt;

&nbsp;
I tried using just width:16em but it did not work so had to use margin:0 12em 0 0; instead. There are other ways of using CSS, give it a try and experiment.
&nbsp;
Cheers,
&nbsp;
John_Betong
&nbsp;
&nbsp;
#5

[eluser]philm[/eluser]
You were pretty close the first time ;-)

Try this...
Code:
&lt;tr onclick="parent.location='&lt;?=site_url('main/client_detail/' .$row-&gt;id);?&gt;'">




Theme © iAndrew 2016 - Forum software by © MyBB