Hi David,
Any idea how I'd go about making a page/button to show all products in the database for admin purposes?
Cheers
Hi Mal,
Try this for 2 (or any number of columns):
<?php
require("../includes/common.php");
require("admin_header.php");
require("admin_menu.php");
print "<h2>All Products</h2>";
$sql = "SELECT name FROM ".$config_databaseTablePrefix."products ORDER BY name";
if (database_querySelect($sql,$rows))
{
$columns = 2; // change this value for a different number of columns
$current_column = 0;
print "<table>";
print "<tr>";
foreach($rows as $product)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
}
else
{
$href = $config_baseHREF."products.php?q=".urlencode($product["name"]);
}
print "<td><a href='".$href."'>".$product["name"]."</a></td>";
$current_column++;
if ($current_column == $columns)
{
print "</tr>";
print "<tr>";
$current_column = 0;
}
}
print "</tr>";
print "</table>";
}
else
{
print "<p>There are no products to display.</p>";
}
require("admin_footer.php");
?>
Hope this helps!
Cheers,
David.
Hi Harvey,
This is reasonably easy to do but it could of course be a massive page...! Here's a script you can run in your /admin directory to display all products with a link to that product's page:
allproducts.php:
<?php
require("../includes/common.php");
require("admin_header.php");
require("admin_menu.php");
print "<h2>All Products</h2>";
$sql = "SELECT name FROM ".$config_databaseTablePrefix."products ORDER BY name";
if (database_querySelect($sql,$rows))
{
foreach($rows as $product)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
}
else
{
$href = $config_baseHREF."products.php?q=".urlencode($product["name"]);
}
print "<p><a href='".$href."'>".$product["name"]."</a></p>";
}
}
else
{
print "<p>There are no products to display.</p>";
}
require("admin_footer.php");
?>
Don't forget this needs to go in your admin/ directory!
Hope this helps,
Cheers,
David.