0

Here is my script for loading a table and displaying it in a HTML table.

$fields = $this->db->list_fields($tableName);

$fieldData = $this->db->field_data($tableName);


$this->db->from($tableName);
$this->db->order_by($fields[0], "asc");
$query = $this->db->get(); 
$table = $query->result();


$columnsQ = $this->db->query("select count(column_name) from information_schema.columns where table_name = '".$tableName."'");
$columns = $columnsQ->row();

foreach($table as $row) {

    echo "\t<tr class='value'>\n";
    $colNr = 1;

    foreach ($row as $tdVal) {

        $colNr0 = $colNr-1;
        $valType = $fieldData[$colNr0]->type;
        $isForeign; // how to get info?

        if($colNr==1) {
            echo "\t\t<td data-valType='$valType' class='id'>$tdVal</td>\n"; }
        else {
            echo "\t\t<td data-isForeign='$isForeign' data-valType='$valType' data-colNr='$colNr'>$tdVal</td>\n"; }

        $colNr++;
    }

} 


</table>"; 

What query should be under $isForeign to get info about whether the loaded value is a foreign key or not?

van_folmert
  • 4,257
  • 10
  • 44
  • 89

1 Answers1

1

Have a look at the answers posted on this question, you will need to just add the extra constraint you require for your specific column as you iterate your foreach

Similar question and multiple answers

Community
  • 1
  • 1
Chris L
  • 2,262
  • 1
  • 18
  • 33