In reference to this topic.
My problem is that I insert into a table using PHP 5 columns, but one of them is a foreign key to another table. So, I would see the value and not the link directory.
For example Orders.Name contain values "1", "2", "3", "4" etc... they are contained in tables "Clients" on columns with ID "1" the "Name" is "Jack", ID "2" the "Name" is "Mark", ID "3" the "Name" is "Frank"... and so on. So, I would to see "Jack", not "1".
Example:
Database name: DinamicoWeb
Table name: Orders
Fields name: Id Ord, Ord Date, Name, Price, Total
Second Table name: Clients
Fields name: Id Client, Name, Cell, City, Address
My actual result:
Id Ord Ord Date Name Price Totale
1 14/2/99 1 189 345
Id Client Name Cell City Street
1 Jack 23445456 Italy Road nr 2
My wish result:
Id Ord Ord Date Name Price Totale
1 14/2/99 Jack 189 345
So, this is my code.
config.php
<?php
define ('DBNAME',"./DinamicoWeb.mdb"); // Database name
define ('DBTBL',"Orders"); // Table name 1
define ('PKNAME',"Id Ord"); // Primary Key
define ('PKCOL',0); // Position Primary Key
define ('LINKPK',true); // PK link for edit/delete
?>
test.php
<?php
require_once("config.php");
$cn = new COM("ADODB.Connection");
$cnStr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".
realpath(DBNAME).";";
$cn->open($cnStr);
$rs = $cn->execute("SELECT [Id Ord] AS [ID], [Ord Date] AS [Date], [Name] AS [Name], [Price] AS [Price], [Total] AS [TOTAL] FROM [Orders]");
$numFields = $rs->Fields->count;
// Print HTML
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />';
echo '<title>Gestione degli '.DBTBL.'</title>';
echo '<link href="styles.css" rel="stylesheet" type="text/css" />';
echo '<link rel="stylesheet" href="css/bootstrap.css">';
echo '<link rel="stylesheet" href="css/footable.bootstrap.css">';
echo '<link rel="stylesheet" href="css/footable.bootstrap.min.css">';
echo '<link rel="stylesheet" href="css/footable.core.bootstrap.min.css">';
echo '</head><body>';
echo '<h1>GESTIONE '.DBTBL.'</h1>';
// Elenca records -----
//echo ("<div class='table-responsive'>");
echo ("<table class='datatable table tabella_reponsive ui-responsive' summary='Prova dati con MS Access'>");
echo("<caption>Tabella ".DBTBL."</caption>\n");
echo("<thead><tr>\n");
for ($i=0;$i<$numFields;$i++){
echo("<th scope='col'>");
echo $rs->Fields($i)->name;
echo("</th>\n");
}
echo("</tr></thead>\n");
echo("<tbody>");
$alt = false;
while (!$rs->EOF)
{
echo("<tr>");
for ($i=0;$i<$numFields;$i++){
$altClass = $alt ? " class='alt'" : "";
if (LINKPK && $i==PKCOL){
echo "<td".$altClass."><a href='?id=".$rs->Fields($i)->value
."'>".$rs->Fields($i)->value."</a></td>\n";
}
else{
echo "<td".$altClass.">".$rs->Fields($i)->value."</td>\n";
}
}
echo("</tr>\n");
$rs->MoveNext();
$alt = !$alt;
}
echo("</tbody>");
echo("</table>\n");
echo("</div>");
echo '<script src="js/footable.js"></script>';
echo '<script src="js/footable.min.js"></script>';
}
echo '</body></html>';
$rs->Close();
$cn->Close();
?>
Thanks!
UPDATE:
I have relationship between Client and Order table.
This is my query on Access. (Different name and different request)
SELECT DISTINCT Ordini.[Id Ord], Ordini.[Tipo Ord] AS Tipo, Ordini.[N Ord] AS Numero, Ordini.[Data Ord] AS Data, Ordini.Anno, Anagrafica.CodAnag AS Codice, Ordini.[Ragione sociale], IIf([stato]=0,"inserito",IIf([stato]=1,"stampato","Bloccato")) AS [Stato ord], Ordini.[Data consegna] AS Consegna, Ordini.ValidoFinoAl AS Validità, [tabella pagamenti].Descrizione AS Pagamento, Ordini.Rif1 AS [Ns Riferimenti], Ordini.Rif2 AS [Vs Riferimenti], IIf(Not IsNull([idsped]),[anagrafica spedizioni].[Ragione Sociale] & " " & [anagrafica spedizioni].Indirizzo & " " & [anagrafica spedizioni].Località,IIf(Not IsNull(anagrafica_1.[id anag]),anagrafica_1.[Ragione Sociale] & " " & anagrafica_1.Indirizzo & " " & anagrafica_1.Località)) AS Destinazione, Ordini.TotImp, Ordini.TotNI, Ordini.Cambio, Temp_Ordini_Interroga.ApertoEuro, Temp_Ordini_Interroga.TotaleEuro, Ordini.Sospeso
FROM ((((Ordini INNER JOIN Anagrafica ON Ordini.[Id anag] = Anagrafica.[Id anag]) INNER JOIN [tabella pagamenti] ON Ordini.[Id pagamento] = [tabella pagamenti].[Id pagamento]) LEFT JOIN [anagrafica spedizioni] ON (Ordini.DestSped = [anagrafica spedizioni].CodSped) AND (Ordini.Dest = [anagrafica spedizioni].[Id anag])) LEFT JOIN Anagrafica AS Anagrafica_1 ON Ordini.Dest = Anagrafica_1.[Id anag]) INNER JOIN Temp_Ordini_Interroga ON Ordini.[Id Ord] = Temp_Ordini_Interroga.IdOrd
ORDER BY Ordini.Anno DESC , Ordini.[Data Ord] DESC , Ordini.[N Ord] DESC;