Page 1 of 1

PHP + Javascript

Posted: Thu Dec 21, 2006 8:49 am
by thiscatis
Hi,

I'm currently working on a catalog system for a school project.
The product listing is as you can see on this pic:
Image

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 " &raquo; " . $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;
	}
	?>
This is the div that should be hidden or visible

Code: Select all

<tr>
		<td>&nbsp;</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">&nbsp;</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>

Posted: Thu Dec 21, 2006 10:42 am
by Kieran Huggins
this is a client-side question - search for "javascript toggle visibility"

Cheers,
Kieran

Posted: Thu Dec 21, 2006 1:26 pm
by John Cartwright
Moved to Client-Side.

Posted: Thu Dec 21, 2006 6:50 pm
by thiscatis
Kieran Huggins wrote:this is a client-side question - search for "javascript toggle visibility"

Cheers,
Kieran
yeah, but how can u use that for different rows generated by a database

Posted: Thu Dec 21, 2006 11:05 pm
by Kieran Huggins
Attach the event to the row element!