I have the following code which outputs results from my database into alternate colours;
Code: Select all
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 25;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM dedicated order by asset LIMIT $from, $max_results");
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM dedicated"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
$numofrows = $total_results;
echo "<TABLE BORDER=\"0\" table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" bgcolor=\"#cccccc\" class=\"standard\">\n";
echo "<TR bgcolor=\"#ffffff\"><TD font colour=\"#999999\" width=\"15%\"><b>Asset</b></TD><TD width=\"30%\"><b>Title</b></TD><TD width=\"25%\"><b>IP address</b></TD><TD width=\"15%\"><b>Reconciled</b></TD><TD width=\"5%\"></TD><TD width=\"5%\"></TD></TR>\n";
for($i = 0; $i < $max_results; $i++) {
$row = mysql_fetch_array($sql); //get a row from our result set
if($i % 2) {
echo "<TR bgcolor=\"ffffff\">\n";
}
else {
echo "<TR bgcolor=\"ffffff\">\n";
}
echo "<TD><a href='viewasset.php?varl=".$row['asset']."' class=\"blue3\">".$row['asset']."</a></font></TD><TD>".$row['title']."</TD><TD>".$row['IP']."</TD><TD>".$row['recon']."</TD><TD><a href='sysdocupdate3.php?varl=".$row['asset']."'><img src=\"edit.gif\" alt=\"Delete\" border=\"0\" /></a></TD><TD><a href='deleteget.php?varl=".$row['asset']."'><img src=\"b_drop.gif\" alt=\"Delete\" border=\"0\" /></a></TD>\n";
echo "</TR>\n";
}
echo "</TABLE>\n";
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />"Ok - In the above code you can see that I pull in a value for IP as, "$row['ip']." - I have now altered my database so that I have a table called ip which can stored multiple ip addresses for each asset.
I need to output the ip addresses in this part, therefore I need to query the other table using the asset number from the $row result. My fields within the ip table are;
asset // the relating asset number
id // the unique key for each ip
ip // the ip address - this needs outputting to the above.
Please help. I have tried to implement a query, but cannot get it to work.