SQL to create table in iamaposer databaseDROP TABLE IF EXISTS categories;
CREATE TABLE categories (
CatID int(11) NOT NULL auto_increment,
CatDesc varchar(100) NOT NULL default '',
PRIMARY KEY (CatID)
) TYPE=MyISAM;
#
Contenu de la table categories
#
INSERT INTO categories (CatID, CatDesc) VALUES (1, 'FooCat'),
(2, 'FooBar');
--------------------------------------------------------
#
Structure de la table links
#
DROP TABLE IF EXISTS links;
CREATE TABLE links (
LnkID int(11) NOT NULL auto_increment,
LnkCatID int(11) NOT NULL default '0',
LnkDesc varchar(255) NOT NULL default '',
LnkURL varchar(255) NOT NULL default '',
PRIMARY KEY (LnkID)
) TYPE=MyISAM;
#
Contenu de la table links
#
INSERT INTO links (LnkID, LnkCatID, LnkDesc, LnkURL) VALUES (1, 1, 'FooCat Link', 'http://www.coldware.net'),
(2, 1, 'FooCat Link 2', 'http://www.coldware.net'),
(3, 2, 'FooBar Site', 'http://www.coldware.net');
display.php
<html>
<head><title>Demo Cat/Lnks</title></head>
<body><table border=0 cellspacing=0 cellpadding=2>
<?
function DBConnect(){
// Database access
if(!$db = mysql_connect( "127.0.0.1" , "root" , "" )){
die("<font color=\"#FF0000\">Error, I could not connect to the database at ".DBServer.". Using username ".DBPwd.".<BR>Please go back and try again.");
}
flush();
if(!@mysql_select_db( "iamaposer" , $db)) {
echo "<font color=\"#FF0000\">Database could not be found</font><BR>";
flush();
die( "<font color=\"#FF0000\">Error, count not select database ".DBName.", please create it manually or have your system administrator do it for you and try again.");
}
return $db;
}
$db = DBConnect();
if (isset( $Cat )){
$sql = "SELECT * FROM Links WHERE Links.LnkCatID = $Cat";
$result = mysql_query($sql, $db)
or die("<font color=\"#FF0000\">Query Error</FONT>");
while ($row = mysql_fetch_array($result)) {
echo "<TD><a href=\"".$row["LnkURL"]."\">".$row["LnkDesc"]."</A></TD></TR>";
}
mysql_free_result($result);
} else {
$sql = "SELECT * FROM Categories";
$result = mysql_query($sql, $db)
or die("<font color=\"#FF0000\">Query Error</FONT>");
while ($row = mysql_fetch_array($result)) {
echo "<TD><a href=\"display.php?Cat=".$row["CatID"]."\">".$row["CatDesc"]."</A></TD></TR>";
}
mysql_free_result($result);
}
?>
</table>
</body>
</html>
This code works here...