4

I would like the results of the 1st column- Short Name of Funds to be hyper linked to additional details about each record. How would I proceed? Or would it be better just to call a link to a details page where another query will run. That seems a little more static.

Here is the example query I'm working with.

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("bdcarterascv2", $con);

$COD_PAIS = '3';
$F_HASTACORTE = '2012-03-31 01:00:00';

$result = mysql_query("SELECT mcarteras.DES_CARTERA_CC                 AS 'Short Name of Fund'
     , mcarterasflias.DES_CARTERAFLIA           AS 'I/C'
     , msociedades.DES_SOCIEDAD_CORTO           AS 'Fund Manager Company'
     , mcarteras_clases.DES_CARTERACLASE        AS 'Class'
     , mcarteras_clasesesp.DES_CARTERACLASE_ESP AS 'Special Class'
     , dr_rentmovil_carteras.POR_RENTCARTERA    AS 'TTR year-to-date %'
     , dficha_mes.POR_REMUNERA_COBRADA          AS 'Mgmt Fee Effectively Charged'
     , dficha_mes.POR_GASTOS_TOTALESC           AS 'Total Expenses %'
     , dficha_mes.VR_CARTERA_FCORTE             AS 'Fund Size'

  FROM mcarteras
    INNER
 JOIN mcarterasflias
    ON mcarterasflias.ID_CARTERAFLIA           = mcarteras.ID_CARTERAFLIA
INNER
  JOIN msociedades
    ON msociedades.ID_SOCIEDAD                 = mcarteras.ID_SOCIEDADADM
INNER
  JOIN mcarteras_clases
    ON mcarteras_clases.ID_CARTERACLASE        = mcarteras.ID_CARTERACLASE
INNER
  JOIN mcarteras_clasesesp
    ON mcarteras_clasesesp.ID_CARTERACLASE_ESP = mcarteras.ID_CARTERACLASE_ESP  
INNER
  JOIN dr_rentmovil_carteras
    ON dr_rentmovil_carteras.ID_CARTERA        = mcarteras.ID_CARTERA   
   AND dr_rentmovil_carteras.COD_PAIS                                       = $COD_PAIS
   AND dr_rentmovil_carteras.F_HASTACORTE                                   = '$F_HASTACORTE'
   AND dr_rentmovil_carteras.ID_FORMATO = 1
   AND dr_rentmovil_carteras. ID_COLUMNA = 5
INNER
  JOIN dficha_mes
    ON dficha_mes.ID_CARTERA                   = mcarteras.ID_CARTERA   
   AND dficha_mes.COD_PAIS                                                  = $COD_PAIS
   AND dficha_mes.F_CORTE                                                   = '$F_HASTACORTE'

 WHERE mcarteras.COD_PAIS                                                   = $COD_PAIS
   AND mcarteras.ID_CARTERATIPO = 4
   AND mcarteras.ID_CARTERAFLIA IN ( 3,4 )
   AND mcarteras.IND_PUBLICACION = 1
   AND mcarteras.COD_ESTADO= 1

")
    or die(mysql_error());

// HTML ... Aliases from Mysql
echo "<table border='1'>
<tr>
<th>Short Name of Fund</th>
<th>I/C</th>
<th>Fund Manager Company</th>
<th>Class</th>
<th>Special Class</th>
<th>TTR year-to-date %</th>
<th>Mgmt Fee Effectively Charged</th>
<th>Total Expenses %</th>
<th>Fund Size</th>

</tr>";

//<tr> specifies table row. for each <td> (table data) will specify a new column.  The     $row specifies the mysql column name (in this case using an alias)
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Short Name of Fund'] . "</td>";
  echo "<td>" . $row['I/C'] . "</td>";
  echo "<td>" . $row['Fund Manager Company'] . "</td>";
  echo "<td>" . $row['Class'] . "</td>";
  echo "<td>" . $row['Special Class'] . "</td>";
  echo "<td>" . $row['TTR year-to-date %'] . "</td>";
  echo "<td>" . $row['Mgmt Fee Effectively Charged'] . "</td>";
  echo "<td>" . $row['Total Expenses %'] . "</td>";
  echo "<td>" . $row['Fund Size'] . "</td>";

  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>
John Harbert
  • 197
  • 2
  • 11

2 Answers2

1

What you would do is, create a link and map it to, most traditionally, the ID or url safe name.

I would hyperlink it to an additional page, as im sure the details will not have the same format as your master table.

Add an ID to your select statement, or change the below to the shortname:

...
echo "<td><a href=\"page.php?id={$row['ID']}\">{$row['Short Name of Fund']}</a></td>";

Then on page.php:

SELECT ... WHERE ID = $_GET['ID'];

Of course, stop using the mysql_* suite of codes as it is deprecated, unsupported, and littered with bad publicity. You should use PDO or MySQLi.

Note: The above is not secured against SQL injection. Switch your driver to PDO or MySQLi and employ some sense of security.

Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87
  • Thanks for the answer. How would I change my driver to PDO or MYSQLi? – John Harbert Aug 29 '12 at 17:11
  • Run a `phpinfo();` See if you have MySQLi or PDO in the output. If so, they are installed and all you need to do is change your syntax. Google php pdo example or php mysql example and you will be set – Mike Mackintosh Aug 29 '12 at 17:13
0

Another option is that if your details are generally short details, basically a few words, or short sentences, you can always print them out as td titles.

This way if the user needs to know that little more detail about some data, he only hovers the mouse over it and woala there it is.

Or a more elegant solution is to use jquerys tooltip plugin, in case of huge detail data. Jquery tooltip can display basically any html code inside a title tag, and its beauty is that the only thing you have to do is define a td title as you would any other title tag, include the jquery lib and tooltip lib in the html header, and use a little js code like this one:

<script>
$('#tableid td').tooltip();
</script>

You can even edit the tooltips style from css.

Demos here: http://jquery.bassistance.de/tooltip/demo/

The only problem with this is that if you want to use it for too many tooltips on the same page, your page load time increases.

user1248047
  • 305
  • 1
  • 3
  • 6