Embedding Query Results as Hyperlinks

admin

Administrator
Staff member
What is the most efficient way to (1) query a table, (2) Grab * to an array; and (3) generate hyperlinks from the array?

The goal is to dynamically generate navigation bars from reference tables in MySQL.

<---- Here's the code that's causing pain -->


<head><title>Data Lookup Test</title></head>
<body>

<?
/* declare lookup variables */
$DBhost = "111.111.111.111";
$DBuser = "root";
$DBpass = "";
$DBName = "thedbname";
$table = "nav_main_bar_top";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); $sqlquery = "SELECT * FROM $table WHERE '1'";
$result = mysql_query($sqlquery);
$number = mysql_numrows($result);

$i = 0;

if ($number < 1) {
print "<CENTER><P>There Were No Results for Your Search</CENTER>";
}
else {
while ($number > $i) {
$mainlabel = mysql_result($result,$i,"nav_main_bar_label");
$mainurl = mysql_result($result,$i,"nav_main_bar_url");

print $mainurl $mainlabel;

$i++;
}
}
?>
</BODY>
 
Back
Top