...

View Full Version : Trying to anchor in PHP



Ipssissimus
01-30-2010, 12:08 PM
Hi Folks

I'm trying to make life a little easier but not sure if it's possible. I have a php file/web page with products on in divs: The first div below contains some code (highlighted in blue) which points to a single product and opens in it's own web page which works but means I have a web page for every product (500 +). What I would like to be able to do (highlighted in red the second div) is somehow have one webpage containing all products (or at least have them in sections) but be able to have an anchor id to the particular product. If this is possible how then would I anchor to the product in the product web page?


<div class="cat-box">
<a href="index.php?page=archangelicbook" onfocus="if(this.blur)this.blur();"><img class="catimage" src="../images/archangelicbook.jpg">
<h2>Archangelic Book of Ritual & Prayer</h2></a>
</div>

<div class="cat-box">
<a href="index.php?page=angelproductsid=001" onfocus="if(this.blur)this.blur();"><img class="catimage" src="../images/archangeliccards.jpg">
<h2>Archangelic Deck</h2></a>
</div>

All pages are loaded into the index.php which contains the div below:


<div id="middle">

<?php include('php/' . $_GET['page'] . '.php'); ?>

<?php
$page = $_GET['page'];
if (!empty($page)) {
$page .= 'php/'.'.php';
include($page);
}
else {
include('php/home.php');
}
?>

</div>

I'm new to PHP and trying to learn as I go along any help would be greatefully received.

many thanks

Andrew

Dormilich
01-30-2010, 12:51 PM
something like index.php?page=angelproducts#id001 (where id001 is the name/id of the anchor)?

Ipssissimus
01-30-2010, 01:18 PM
Thank you for your reply. It almost worked. I have 3 divs in the angelproduct file and it brings them all through but I only want the one related to the specific id. Any ideas how I can stop them all appearing.



<div id="001" class="product-box">
<h1>001 - <SCRIPT LANGUAGE="JavaScript" SRC="http://www.remoteprice.com/data.asp?storeid=33321&itemcode=erbm16&type=1"></script></h1>
<div class="cart-details">
<img class="prodimage" src="../images/erbm16.jpg"></div>

<div id="002" class="product-box">
<h1>002 - <SCRIPT LANGUAGE="JavaScript" SRC="http://www.remoteprice.com/data.asp?storeid=33321&itemcode=erbm16&type=1"></script></h1>
<div class="cart-details">
<img class="prodimage" src="../images/erbm16.jpg</div>


<div id="003" class="product-box">
<h1>003 - <SCRIPT LANGUAGE="JavaScript" SRC="http://www.remoteprice.com/data.asp?storeid=33321&itemcode=erbm16&type=1"></script></h1>
<div class="cart-details">
<img class="prodimage" src="../images/erbm16.jpg</div>

Dormilich
01-30-2010, 01:20 PM
then only insert the one with the appropriate id.

PS. IDs must not start with a digit.

Ipssissimus
01-30-2010, 01:36 PM
These are my menu links:


<div class="cat-box">
<a href="index.php?page=angelprods#id001" <h2>001</h2></a>
</div>

<div class="cat-box">
<a href="index.php?page=angelprods#id002" <h2>002</h2></a>
</div>

<div class="cat-box">
<a href="index.php?page=angelprods#id003" <h2>003</h2></a>
</div>


and this is the angelprods php



<div id="id001" class="product-box">
<h1>Product 001</h1>
</div>

<div id="id002" class="product-box">
<h1>Product 001</h1>
</div>

<div id="id003" class="product-box">
<h1>Product 001</h1>
</div>



I was trying to avoid creating a webpage per product by pulling through just the relevant data from one file. Do you know if there is a better method to do this?

Dormilich
01-30-2010, 01:41 PM
actually, I would create a separate page for every product, though that’s my personal preference.

you could also choose to store the information in XML files (if it’s not too complex info) and fetch it from there or you could of course use a database.

Ipssissimus
01-30-2010, 01:49 PM
Many thanks for your time and help.:)

Ipssissimus
01-30-2010, 06:13 PM
Hi There.

I've used the switch/case functionality and it works a treat.:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum