Help with Accessing Data from MySQL DB with PHP Function
Posted: Wed Jan 29, 2003 6:27 pm
If anyone could help me out with this function I wrote on a thumbnail display code for my site. The function is supposed to show specific thumbnails from a table in my database. For instance if you click on business category it would display all the thumbnails from the table with the category business in them.
My code is below.
function template_display() {
$results4 = mysql_query("SELECT * FROM templates ORDER BY tempid DESC");
while($row4 = mysql_fetch_array($results4)) {
$name = $row4['name'];
$price = $row4['price'];
$uniq_price = $row4['uniq_price'];
$designer = $row4['designer'];
print "<table width='400' border='0' cellspacing='0' cellpadding='0' align='center'>
<tr>
<td width='150' valign='top'>
<div align='center'><img src='/files/templates/thumbs/$name.gif' border='1'><a href='preview.php?name=$name'><img src='/images/button_preview.gif' width='59' height='14' border='0'></a>
<a href='cart.php?txt_itemcode=$tempid&txt_mode=addition_new'><img src='images/button_addtocart.gif' width='77' height='14' border='0'></a>
</div>
</td>
<td width='10'> </td>
<td valign='top'>
<table width='100%' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td><b>Name: </b>$name</td>
</tr>
<tr>
<td><b>Price: $</b>$price</td>
</tr>
<tr>
<td><b>Unique: $</b>$uniq_price</td>
</tr>
<tr>
<td><b>Designer: </b>$designer</td>
</tr>
</table>
</td>
</tr>
</table><br><br>";
}
}
When I use this code it will display the thumbnails the way I want, but it will display all the thumbnails in the database. No matter what category I click on it displays all the thumbs from the database.
Can someone please help me order my thumbs by $catid. I have tried different things but they all seem to not work.
Any help is greatly appreciated.
Thanks
Matt Urban
My code is below.
function template_display() {
$results4 = mysql_query("SELECT * FROM templates ORDER BY tempid DESC");
while($row4 = mysql_fetch_array($results4)) {
$name = $row4['name'];
$price = $row4['price'];
$uniq_price = $row4['uniq_price'];
$designer = $row4['designer'];
print "<table width='400' border='0' cellspacing='0' cellpadding='0' align='center'>
<tr>
<td width='150' valign='top'>
<div align='center'><img src='/files/templates/thumbs/$name.gif' border='1'><a href='preview.php?name=$name'><img src='/images/button_preview.gif' width='59' height='14' border='0'></a>
<a href='cart.php?txt_itemcode=$tempid&txt_mode=addition_new'><img src='images/button_addtocart.gif' width='77' height='14' border='0'></a>
</div>
</td>
<td width='10'> </td>
<td valign='top'>
<table width='100%' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td><b>Name: </b>$name</td>
</tr>
<tr>
<td><b>Price: $</b>$price</td>
</tr>
<tr>
<td><b>Unique: $</b>$uniq_price</td>
</tr>
<tr>
<td><b>Designer: </b>$designer</td>
</tr>
</table>
</td>
</tr>
</table><br><br>";
}
}
When I use this code it will display the thumbnails the way I want, but it will display all the thumbnails in the database. No matter what category I click on it displays all the thumbs from the database.
Can someone please help me order my thumbs by $catid. I have tried different things but they all seem to not work.
Any help is greatly appreciated.
Thanks
Matt Urban