Product Pop-up.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
conscience
Forum Commoner
Posts: 33
Joined: Mon Dec 27, 2004 12:34 pm

Product Pop-up.

Post by conscience »

I've got a PHP-only shopping cart system, and am trying to integrate a function where the user clicks on a product image and a window pops with back/next links and a slideshow above. Currently the URLs of the images are stored in a MySQL database column and can be accessed with $row["itemPic"].

I am very un-savvy in regards to JScript. How could I implement this functionality?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[devnet]+window +open[/devnet]
[google]+window.open[/google]

:)
conscience
Forum Commoner
Posts: 33
Joined: Mon Dec 27, 2004 12:34 pm

Post by conscience »

Right, so I've got a JScript built with all the functionality I want. It pulls the URLs from an array called 'Picture'. How do I populate the array with $row["itemPic"] values from PHP? If the function is called from the middle of the PHP page where this is already defined from the MySQL query, can I just do a FOREACH loop or something?
conscience
Forum Commoner
Posts: 33
Joined: Mon Dec 27, 2004 12:34 pm

Post by conscience »

I'm now echoing the Javascript through PHP.

Would this work? If there are multiple URL values in the "itemPic" column in the MySQL database, is Count() going to lump them together as one value, or as many?

Code: Select all

$pics = $rowї"itemPic"];
$num = count($pics);

for($i = 0; $i < $num; $i++) &#123;
	foreach ($pics as $pic) &#123;
	echo "Picture&#1111;" . $i . "]  = '" . $pic . "';"; &#125;
&#125;
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

If your counting the array you create then count() will count the values so in ohter words you will get the correct number.

You could also use sizeof() ;-)

EDIT: To get the the number of rows in your database use mysql_num_rows($mysql_result); where $mysql_result is the output of your query.
conscience
Forum Commoner
Posts: 33
Joined: Mon Dec 27, 2004 12:34 pm

Post by conscience »

Great. Now.. what do I need to do to make the $pics variable accept a $_GET variable from the previous page? Do I need to make each poppable item its own form?

Tried searching for this sort of thing but I keep getting no results when searching for "$_GET*" or "GET".
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the $_GET variables are set when you go to a url like this: http://imadork.com/page.php?something=nothing

where $_GET['something'] is set to 'nothing'
conscience
Forum Commoner
Posts: 33
Joined: Mon Dec 27, 2004 12:34 pm

Post by conscience »

So in regards to the parent page, I need hidden form elements echoing the item names, and then pass the $_GET values as arguments to the JS pop-up function? Content of the parent page is dynamically generated from a database, so I can't just arbitrarily toss out input names and values.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

true, but they are easily generated. All you need is some unique identifier for the popup to lookup the details of that item. It doesn't require a form, just a link, which you can generate along with the rest of the content.
conscience
Forum Commoner
Posts: 33
Joined: Mon Dec 27, 2004 12:34 pm

Post by conscience »

Unique identifier: Like the item's name or something?

Can you cite an example, please? My brain isn't entirely understanding..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

like every item in a database typically has an id associated with it. Kinda like a product sku, it's unique among your inventory.
conscience
Forum Commoner
Posts: 33
Joined: Mon Dec 27, 2004 12:34 pm

Post by conscience »

I see. How would I use this syntactically?
Post Reply