PHP + Javascript
Posted: Thu Dec 21, 2006 8:49 am
Hi,
I'm currently working on a catalog system for a school project.
The product listing is as you can see on this pic:

The problem is, when you have a lot of products, the list is too long and not easy to use.
I have a expand/collapse javascript that does something similar but it only works with one product row since you can only have one id per element.
Is there a suitable solutions to expand/collapse the products when you click on the >>
code:
This is the div that should be hidden or visible
I'm currently working on a catalog system for a school project.
The product listing is as you can see on this pic:

The problem is, when you have a lot of products, the list is too long and not easy to use.
I have a expand/collapse javascript that does something similar but it only works with one product row since you can only have one id per element.
Is there a suitable solutions to expand/collapse the products when you click on the >>
code:
Code: Select all
<?php
$pid = $params['productid'];
$categories = LoadCategoriesOverview();
foreach ($categories as $c) {
DisplayCategory($c);
SubCategories($c->subcategories);
}
function SubCategories($subcategories) {
foreach ($subcategories as $c) {
DisplayCategory($c);
SubCategories($c->subcategories);
}
}
function DisplayCategory($c) {
$tree = GetParentLineup(array(), $c->id);
array_push($tree, $c->id);
echo "<tr><td colspan='11' class='category'>";
foreach ($tree as $parent) {
$cat = LoadCategoryById($parent);
//THIS IS WHERE THE LINK SHOULD BE
echo " » " . $cat->name;
}
echo "</td></tr>";
$products = LoadProductsByCategory($c->id);
foreach ($products as $p)
DisplayProduct($p);
}
function DisplayProduct($p) {
$bInStore = !(is_null($p->price) && is_null($p->reduction) && is_null($p->stock));
if (!$bInStore) {
$p->price = $p->recommended_price;
$p->reduction = 0;
$p->stock = 0;
}
?>Code: Select all
<tr>
<td> </td>
<td class='code'>#<?php echo $p->number;?></td>
<td class='name'><?php echo $p->name;?></td>
<td class="edit">
<form method="post" action="">
<input type="hidden" name="productaction" value="showedit" />
<input type="hidden" name="productid" value="<?php echo $p->id;?>" />
<input type="submit" value="Edit" />
</form>
</td>
<td class="delete">
<form method="post" action="">
<input type="hidden" name="productaction" value="delete" />
<input type="hidden" name="productid" value="<?php echo $p->id;?>" />
<input type="submit" value="Delete" />
</form>
</td>
<td class="splitter"> </td>
<form method="post" action="">
<input type="hidden" name="productaction" value="updatestore" />
<input type="hidden" name="product" value="<?php echo $p->number?>" />
<td class="available"><input type="checkbox" value="1" name="available" <?php echo ($bInStore ? "checked='checked'":"");?> onchange="var b = this.checked; price.disabled = !b; reduction.disabled = !b; stock.disabled = !b; stock.focus();" />Available</td>
<td class="price"><input name="price" type="text" onfocus="this.select();" value="<?php echo $p->price;?>" size="5" <?php echo (!$bInStore ? "disabled='disabled'":"");?> /></td>
<td class="reduction"><input name="reduction" type="text" onfocus="this.select();" value="<?php echo $p->reduction;?>" size="5" <?php echo (!$bInStore ? "disabled='disabled'":"");?> /></td>
<td class="stock"><input name="stock" type="text" onfocus="this.select();" value="<?php echo $p->stock;?>" size="5" <?php echo (!$bInStore ? "disabled='disabled'":"");?> /></td>
<td class="update"><input type="submit" value="Update store" /></td>
</form>
</tr>