Display Product
I am designing a florists website, and I would like a way for when the user clicks on "view arrangement" that a page will pop up with the picture, information, price, and "Buy Now" button.
The tricky thing is, I don't want to make a seperate page for each product. I want the "view arrangement" button to have values to be sent to a product page template, and then the values like product name and stuff to be filled in.
Anyone have any ideas?
The Webmistress posted this at 17:22 — 7th March 2004.
She has: 5,586 posts
Joined: Feb 2001
You are going to need to use something like php & a database for this if you don't want individual html pages for the pop-up
Chroder posted this at 18:26 — 7th March 2004.
He has: 91 posts
Joined: Mar 2004
If you don't have a database, you could create a little "config" file and use that for the information.
<?php
// config.php
$products = array(
// #0
array('title' => 'Arrangement One',
'price' => '$13.49',
'image' => 'images/a1.jpg'),
// #1
array('title' => 'Arrangement Two',
'price' => '$15.89',
'image' => 'images/a2.jpg'),
);
?>
<?php
// page to load with your popup. pass the number with the url. ex: thisscript.php?id=0
include('config.php');
if(!isset($_GET['id']) || !isset($producs[$_GET['id']]))
die('Please specify a valid ID.');
$p = $products[$_GET['id']];
<img src=\"=$p['image']\" border=\"0\" /><br />
<b>=$p['price']</b><br />
... etc
?>
The New Tech - New
Webmaster-Talk.com
Chroder.com
airoid3000 posted this at 20:29 — 7th March 2004.
They have: 71 posts
Joined: Mar 2004
Thanks you guys. I do have databases but I need to put in about 380 products and I don't want to spend all day entering them into sql.
I think I'll use the config file. So let me get this straight, I make a config file with a view values (title, price, image). Then I make a popup page that is universal which is the second code you provided.
But how exactly, on the product page that lists all the arrangements, do I make the link to do the popup for that specific ID?
EDIT: Also, you mention a Get ID function, but I don't see it in the config.php code. Where would I put that?
And if I were to use a mysql database, what code would I use?
Chroder posted this at 23:58 — 7th March 2004.
He has: 91 posts
Joined: Mar 2004
$_GET['id'] is PHP's way of getting the data in thw query string, the data after the "?".
So when you call your popup, you're going to pass the ID as part of the query string
[INDENT]http://yourdomain.com/thescript.php?id=1[/INDENT]
The New Tech - New
Webmaster-Talk.com
Chroder.com
airoid3000 posted this at 00:43 — 8th March 2004.
They have: 71 posts
Joined: Mar 2004
When I go to myurl.com/popup.php?id=1 or any other number I get "Please specify a valid ID"
Chroder posted this at 00:57 — 8th March 2004.
He has: 91 posts
Joined: Mar 2004
I speeled it rong
<?php
if(!isset($_GET['id']) || !isset($producs[$_GET['id']]))
die('Please specify a valid ID.');
?>
with
<?php
if(!isset($_GET['id']) || !isset($products[$_GET['id']]))
die('Please specify a valid ID.');
?>
Hence the missing "t" in "products"
The New Tech - New
Webmaster-Talk.com
Chroder.com
airoid3000 posted this at 02:01 — 8th March 2004.
They have: 71 posts
Joined: Mar 2004
Thanks! One more request, how can I start the "id" # at 1001 instead of 1?
Chroder posted this at 02:15 — 8th March 2004.
He has: 91 posts
Joined: Mar 2004
Actually starts at 0
But if you want to start it at a number, change the first one to this:
<?php
// config.php
$products = array(
// #1001
1001 => array('title' => 'Arrangement One',
'price' => '$13.49',
'image' => 'images/a1.jpg'),
// #1002
array('title' => 'Arrangement Two',
'price' => '$15.89',
'image' => 'images/a2.jpg'),
);
?>
The New Tech - New
Webmaster-Talk.com
Chroder.com
Chroder posted this at 02:17 — 8th March 2004.
He has: 91 posts
Joined: Mar 2004
And, if you find it easier you could format the file like this instead:
<?php
// config.php
// #1001
$products[1001]['title'] = 'Arrangement One';
$products[1001]['price'] = '$13.49';
$products[1001]['image'] = 'images/a1.jpg';
// #1002
$products[1002]['title'] = 'Arrangement Two';
$products[1002]['price'] = '$15.89';
$products[1002]['image'] = 'images/a2.jpg';
?>
The New Tech - New
Webmaster-Talk.com
Chroder.com
airoid3000 posted this at 02:43 — 8th March 2004.
They have: 71 posts
Joined: Mar 2004
Your awesome! I have everything working but one thing, the buy now button. It calls a javascript file in order to add the specific product to the cart.
Everytime I click buy now i get an "object expected" error. Is this because .php pages don't allow javascript in them, or what?
Thanks again!
Chroder posted this at 02:49 — 8th March 2004.
He has: 91 posts
Joined: Mar 2004
Thats weird that you say that, I had a discussion about the very same thing on my forum -- never got to the bottom of it. I though I was missing something. I'll search for an answer later -- gotta do homework now
The New Tech - New
Webmaster-Talk.com
Chroder.com
airoid3000 posted this at 03:04 — 8th March 2004.
They have: 71 posts
Joined: Mar 2004
Ah, it was an error in my part, seems to be working fine now. My problem wasn't about having javascript in php, because the javascript was actually after ?> (the close of php) on the page.
Thanks for everything! You're a life saver!
Chroder posted this at 03:12 — 8th March 2004.
He has: 91 posts
Joined: Mar 2004
I'll have to run that by my buddy there
No problem
The New Tech - New
Webmaster-Talk.com
Chroder.com
airoid3000 posted this at 01:11 — 26th March 2004.
They have: 71 posts
Joined: Mar 2004
I have a page that displays all of the flower arrangements and their prices. Is there a way that I can call the prices and names from my config.php file?
Changing prices is very hard because now I have to change them in the config.php file, and the flower arrangement page.
airoid3000 posted this at 01:58 — 26th March 2004.
They have: 71 posts
Joined: Mar 2004
I have tried several different ways, but none worked. Here is what I am looking for exactly:
<?php
// page to load with your popup. pass the number with the url. ex: thisscript.php?id=0
include('database.php');
if(!isset($_GET['id']) || !isset($products[$_GET['id']]))
die('We apologize, but this occasion category is currently unavailable.');
$p = $products[$_GET['id']];
<html>
Arrangement Title: =$products['id'] => '1001'['title']
</html>
?>
Chroder posted this at 04:33 — 26th March 2004.
He has: 91 posts
Joined: Mar 2004
You want to go through each config value and print it on one page? Thats simple enough
<?php
include('database.php');
foreach($products AS $p)
{
<b>=$p['title']</b>: =$p['price']<br />
}
?>
The New Tech - New
Webmaster-Talk.com
Chroder.com
airoid3000 posted this at 22:12 — 27th March 2004.
They have: 71 posts
Joined: Mar 2004
It should be:
1
2
3
Suzanne posted this at 03:41 — 26th March 2004.
She has: 5,507 posts
Joined: Feb 2000
moving it to scripting.
mjs416 posted this at 18:22 — 26th March 2004.
They have: 127 posts
Joined: Dec 2003
Since I am a php newbie, this looked like a good example to play with and try to figure some things out. What keeps happening, however, is that I get the "Please specify a valid ID." Here is what I have:
--------------------------------------
<?php
// config.php
$products = array(
// #0
array('title' => 'Arrangement One',
'price' => '$13.49',
'image' => 'images/1.gif'),
// #1
array('title' => 'Arrangement Two',
'price' => '$15.89',
'image' => 'images/2.gif'),
array('title' => 'Arrangement Three',
'price' => '$17.89',
'image' => 'images/3.gif'),
);
?>
-------------------------------------------
now the script that I call "cart.php"
------------------------------------------
<?php
// page to load with your popup. pass the number with the url. ex: thisscript.php?id=0
include('config.php');
if(!isset($_GET['id']) || !isset($products[$_GET['id']]))
die('Please specify a valid ID.');
$p = $products[$_GET['id']];
?>
" border="0" />
<?=$p['price']?>
---------------------------------------------------
I then have a php page called index that has three links:
1
2
3
But, as mentioned, the code cannot determine a valid ID. Any idea what I am doing wrong? I'm sure I am way off base here. I have a few books on php coming in the mail to aid me, but for right now, any ideas?
Edit: NM, Fixed it myself. This reminds me of the good ol days of troubleshooting my old C code in college. Yikes!!! Anyways, thanks for the input guys.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.