Forum Moderators: coopster
Thanks
Stephen
Here is the code for the entire page...
<?
if(isset($_COOKIE["myLoggedInCookie"])){
echo "
<html>
<head>
<title>View All Products</title>
<style type='text/css'>
table { background-color:#eeeeee; }
th { background-color:#cccccc; font-family:verdana; font-size:12pt; color:#333399; border-width:2px; border-color:#3333ff; }
td { background-color:#eeeeee; font-family:verdana; font-size:12pt; color:#333399; border-width:1px; border-color:#3333ff; }
</style>
</head>
<body>
<center>
<br/><br/>
<table width='600'>
<tr>
<th colspan='5'>Products</th>
</tr>
<tr>
<th>Section</th>
<th>Name</th>
<th>Price</th>
<th>Description</th>
<th>Image Url</th>
</tr>
<?php
showProducts();
?>
</table>
<br /><br />
</center>
</body>
</html>
";
}
else {
echo "<script>alert('You are not logged in'); parent.location='index.php';</script>";
}
function showProducts(){
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("databaseName");
$dbQuery="SELECT * FROM products order by section asc";
$result = mysql_query($dbQuery,$db);
while ($arrayVar=mysql_fetch_array($result)) {
$section=$arrayVar["section"];
$name=$arrayVar["name"];
$price=$arrayVar[price];
$desc=$arrayVar["desc"];
$imgurl=$arrayVar["imgurl"];
echo "<tr><td>$section</td>" .
" <td>$name</td>" .
" <td>$price</td>".
" <td>$desc</td>".
" <td>$imgurl</td></tr>";
}
}
?>
Change:
echo "<tr><td>$section</td>" .
" <td>$name</td>" .
" <td>$price</td>".
" <td>$desc</td>".
" <td>$imgurl</td></tr>";
to:
$data = "<tr><td>$section</td>" .
" <td>$name</td>" .
" <td>$price</td>".
" <td>$desc</td>".
" <td>$imgurl</td></tr>";
return $data;