PHP Problemo

Associate
Joined
10 Nov 2008
Posts
408
Location
Leeds
Hi folks, pretty much a php newbie so go easy on me. But I was wondering if you could shed some light and educate me please.

EDIT: after following the previous posts I have the separate tbl_productsizes

So can anyone help me link the pd_id which in the current session to looking up the sizes in tbl_productsizes?



Thanks for you help guys and girls!
 
Last edited:
There are a few ways you can do this I'd say.

Firstly, you need a unique ID value on your products if you haven't already.
Then, if you have many 'sizes' on a product, I'd say have a new table 'tbl_productSizes' which is something like :

sizeID - unique key
product_ID
pd_size

then, I presume you need to have each size option in the drop down per product so i'd have the unique size id and the size description in the drop down.

When you add to a cart, you pass the chosen size id from the drop down and this in turn will give you the size description and product details via the new product sizes table.
 
Ahh that is a cracking idea! I shall give this a go tonight and let you know how I get along...will probably be back for help again. Haha.

Thank you!
 
It's called database normalisation, plenty of great tutorials out there if you get stuck.
 
So who fancies writing me a nice bit of php? :D It certainly confuses me, though I suppose this is one way of learning!
Its the fact I am getting info from two tables in the database that is confusing me I think.

I have set-up an extra table like sist_si said, called tbl_productsizes. With these inside it:
size_id, pd_id, pd_size

size_id is auto increment.
The pd_id is obviously from the other table so I can link it to that product.


So the page I want to pull this information into is my product detail page which obviously already has a pd_id from my product table (tbl_product)

Can someone help me write a bit of code then that displays the sizes relevant to the current pd_id?

I will love you long time!
 
Last edited:
You won't learn anything doing it that way!! ;)

Is it the SQL or the PHP or both that's the problem?

Honestly, you should have a crack yourself. If someone else writes it, you won't gain any understanding of how it all works.

/preach
 
Haha thanks sist si :P Problem is I am running out of time so I am having to resort to asking for help. Though I am sure I can figure out whats going on if someone is so kind :)


I have given it a little go but it comes up with errors unfortunately. I shall have another go though....

Thanks for the preach haha.
 
Right then, given it a bash. Not working though, so I dunno if its at all correct :P

I have inserted this:
Code:
$sql = "SELECT pd_id, pd_size, size_id
		FROM tbl_productsizes
		WHERE pd_id = pd_id IN parent
		ORDER BY pd_size";

Now I have no idea if the IN parent bit is correct at all, the rest of it I THINK is ok?

This is on a page which already has the pd_id in the address of it by the way. So I need it to match the pd_id in tbl_productsizes as the one in the address bar/embedded into the page.

Then to display it I am going to use a drop down menu so guessing its got to be something like this:

Code:
<form id="sizes">
<select name="sizes">
<option> <?php echo pd_size ?></option>

</select>
</form>

Though I am not sure if this would add each entry onto a separate line/option.

Help me please :)

I will send a mars bar to the person who solves my confusion! haha
 
To be honest I considered helping you, but your OP actually confuses me a little. From what I gather, looking at your previous post you seem to have the general idea but your syntax is all wrong. It would be easier to help if you just posted your source.
 
Last edited:
Haha yeah that is understandable, I just re-read the first post and it sounds a load of rubbish! Pretty much ignore that now anyway as I followed what sist_si said.

The previous post code I posted was taken from some code I found on the internet and I changed it to how I thought it should be but it didn't work :(

What do you want me to post up then? The code for the whole page?

Many thanks :)
 
Right here is the pages source:

Code:
<?php
if (!defined('WEB_ROOT')) {
	exit;
}

$product = getProductDetail($pdId, $catId);


// we have $pd_name, $pd_price, $pd_description, $pd_image, $cart_url
extract($product);
?> 
<br />
<br />

<table width="100%" border="0" cellspacing="0" cellpadding="10">
 <tr> 
  <td align="center"><img src="<?php echo $pd_image; ?>" border="1" alt="<p><?php echo $pd_name; ?></p>"></td></td>
  <td valign="middle">
<p><strong><?php echo $pd_name; ?></strong></p><br>


<p>Price : <?php echo displayAmount($pd_price); ?><br></p>
<?php
// if we still have this product in stock
// show the 'Add to cart' button
if ($pd_qty > 0) {
?>
<input type="button" name="btnAddToCart" value="Add To Cart &gt;" "onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton">
<?php
} else {
	echo 'Out Of Stock';
}
?>
  </td>
 </tr>
 <tr align="center"> 
  <td colspan="2"><p><?php echo $pd_description; ?></p></td>
 </tr>
</table>

The information is brought in on the previous page though:

Code:
<?php
if (!defined('WEB_ROOT')) {
	exit;
}

$productsPerRow = 3;
$productsPerPage = 9;

//$productList    = getProductList($catId);
$children = array_merge(array($catId), getChildCategories(NULL, $catId));
$children = ' (' . implode(', ', $children) . ')';

$sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id
		FROM tbl_product pd, tbl_category c
		WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children 
		ORDER BY pd_name";
		
	
		
$result     = dbQuery(getPagingQuery($sql, $productsPerPage));
$pagingLink = getPagingLink($sql, $productsPerPage, "c=$catId");
$numProduct = dbNumRows($result);

// the product images are arranged in a table. to make sure
// each image gets equal space set the cell width here
$columnWidth = (int)(100 / $productsPerRow);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="20">
<?php 
if ($numProduct > 0 ) {

	$i = 0;
	while ($row = dbFetchAssoc($result)) {
	
		extract($row);
		if ($pd_thumbnail) {
			$pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail;
		} else {
			$pd_thumbnail = WEB_ROOT . 'images/no-image-small.png';
		}
	
		if ($i % $productsPerRow == 0) {
			echo '<tr>';
		}

		// format how we display the price
		$pd_price = displayAmount($pd_price);
		
		echo "<td width=\"$columnWidth%\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id" . "\"><img src=\"$pd_thumbnail\" border=\"0\"><br>$pd_name</a><br><p> Price : $pd_price </p>";

		// if the product is no longer in stock, tell the customer
		if ($pd_qty <= 0) {
			echo "<br>Out Of Stock";
		}
		
		echo "</td>\r\n";
	
		if ($i % $productsPerRow == $productsPerRow - 1) {
			echo '</tr>';
		}
		
		$i += 1;
	}
	
	if ($i % $productsPerRow > 0) {
		echo '<td colspan="' . ($productsPerRow - ($i % $productsPerRow)) . '">&nbsp;</td>';
	}
	
} else {
?>
	<tr><td width="100%" align="center" valign="center">No products in this category</td></tr>
<?php	
}	
?>
</table>
<p align="center"><?php echo $pagingLink; ?></p>


I would love to say I wrote all that but I didn't, its all from a tutorial haha.

Hope this is what you meant?
 
Can no one help? :(

All I need is the code to get the p_id from the current session and get the sizes from a table according to that id!

Please! :(
 
Back
Top Bottom