hi

If you click on the following page

http://www.bluetipdvd.co.uk/indexd.php and the click on the two product
links a new window opens which displays some more info. I am trying to make it so the window that opens
displays info relevant to the the link that was click

e.g
clicking on product one displays info about product one
clicking on product two displays info about product two

At the moment the window will only display the first row in my database an im not sure
what i need to change

this is the code that opens a new window:

<A HREF="javascript:void(0)"
onclick="window.open('longprod.php',
'welcome','width=400,height=400')">
<? echo "$name" ?></A>


and this is the code that displays info in the new window:
<td><? echo "$ID"?> </td><td><? echo "$name"?></td><td><? echo "$longdescription"?></td>

ive tried looking for help elsewhere but im not sure what i should be reading up on

any help would be appreciated and if you cant tell me what the code should be could you tell me what i should be reading up on

thanks

simon

Recommended Answers

All 7 Replies

I'm not sure of your current skill level, so I'm making some assumptions based on what you said. Assuming that you know how to craft a SQL query to select data about a specific product (a specific product ID), and assuming you know how to use PHP to execute that query and how to retrieve the data into PHP variables, then.....

Your javascript is ALMOST there.

<script language="javascript">
function ProductDetail(id) {
  url = 'longprod.php?id='+id;
  window.open(url,'welcome','width=400,height=400');
}
</script>

<a href="javascript:ProductDetail(<?= $ID ?>)"><?= $name ?></a>

I hope that fills in the gaps for you! Enjoy the journey.

hi

thanks

fo the quick reply - unfortunately that hasnt quite worked - see:

http://www.bluetipdvd.co.uk/index.php

Could you tell me what i shoiuld be reading up on so i can go try my luck with some tutorials - its just i dont know what tutorials i should be trying.

Also should i be doing anything to the code in longprod.php (the window that opens.

thanks

simon

Your questions are too general. It is easy enough to understand what you want to do, but it's not clear to me what you don't understand.

If you want general PHP tutorial assistance, Google for "PHP Tutorial". I also highly recommend keeping http://www.php.net open in a browser set to search the function documentation. I use this everyday.

If you want an EXCELLENT text editor to work with PHP code, I suggest the FREE PsPad at www.pspad.com. If you install pspad, be sure to also follow the guidance on the pspad website to install the PHP documentation. It will integrate the documentation from php.net into PsPad so you can hit Alt-F1 on a word and see context-sensitive help.

If you want recommendations for an EXCELLENT ftp client, I recommend the FREE Filezilla. http://sourceforge.net/projects/filezilla/

For your task, you want 2 php scripts. (You can name them whatever you want.):

products.php
This page will select all the products from the database and list them on the page. Maybe it selects all products in a category, etc. Each product listed will be a link to the product_detail.php script. You form this link by adding the product ID to the end of the link url like < href="product_detail.php?id=13">Product XYZ</a>.

product_detail.php
This page will expect a product ID to be passed in on the URL (querystring). You will use this ID to form a SQL query to select the data for the product matching the ID. It will then display the product data however you want.

If we agree that this is the architecture of the solution you want, at what specific points do you need help?

From what I've already seen on your site, it appears to me you know how to use PHP to select the products and display them. I already showed you how to create your links to the detail page.

Perhaps you don't know how to retrieve the passed in product ID from the url? You need to do this, then build a SQL query using it.

/*
Get variable passed in on querystring.
*/
$prod_id = $_GET['id']

/*
Use this ID to build SQL query.
*/
$sql = "SELECT name, description, price from products where product_id = $prod_id";

Does this help you?

hi

i have only been doing this for about 3 days so im affraid you might have to bare with me:

http://www.bluetipdvd.co.uk/index.php

the links now seem to link to the releant product however when you click on them they get an error.

here is the code have for the new window (longprod.php):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php include "vsadmin/db_conn_open.php";
$prod_id = $_GET

$query="SELECT * FROM products where ID = $ID";

$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();
$ID=mysql_result($result,$i,"ID");
$name=mysql_result($result,$i,"name");
$price=mysql_result($result,$i,"price");
$photo=mysql_result($result,$i,"photo");
$longdescription=mysql_result($result,$i,"longdescription");

?>
<table width="100%" height="59" border="0" cellpadding="1" cellspacing="1">
<tr>
<td><? echo "$ID"?> </td><td><? echo "$name"?></td><td><? echo "$longdescription"?></td>
</tr>
</table>

</body>
</html>

i assuming now that all that needs changing is something on this new page

unfortuantely i cant tell you what i do and dont know as i am still quite a novice as you might be able to tell:

thanks again for all your help

sy

You set your id to a variable named $prod_id, then you used $ID in your query. You have to use the same variable name. $ID does not equal anything.

The error your page is giving usually means you simply forgot to end a line with a semicolon.

You have some lines that look like:

$ID=mysql_result($result,$i,"ID"); 
 $name=mysql_result($result,$i,"name"); 
 $price=mysql_result($result,$i,"price"); 
 $photo=mysql_result($result,$i,"photo"); 
 $longdescription=mysql_result($result,$i,"longdescription");

However, you have never set the variable $i. You can either add $i = 0; before these lines, or replace $i with a zero in those lines.

this is the line thats coming up with the error at http://www.blutipdvd.co.uk/index.php

$sql= "SELECT name, longdescription, price FROM products WHERE ID = $ID";

can you see anything wrong with this?

i cant wait to get finally understand it all its really annoying me

cheers

simonCODE FROM longdescription.php
<?php include "vsadmin/db_conn_open.php";


$ID = $_GET
$sql= "SELECT name, longdescription, price FROM products WHERE ID = $ID";



$result=mysql_query($query);
$num=mysql_num_rows($result);


mysql_close();



?>


CODE FROM MAIN PAGE INDEX.PHP


<script language="javascript">
function longdescription(ID) {
url = 'longprod.php?id='+ID;
window.open(url,'welcome','width=400,height=400');
}
</script>


</head>


<body bgcolor="#CCCCCC" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="766" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" rowspan="2" bgcolor="#FFFF00" class="unnamed1"><img src="images/logo.gif" alt="Welcome to our website" width="300" height="80"></td>
<td width="29%" bgcolor="#FFFF00"><div align="center" class="freedelivery">
<p>Free Delivery on all orders<br>
</p>
</div></td>
</tr>
<tr>
<td align="right" valign="bottom" bgcolor="#FFFF00"><form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd3" value="_cart">
<input type="hidden" name="business3" value="orders@bestblanks.co.uk">
<input type="image" src="http://www.bestblanks.co.uk/images/viewcart.gif" border="0" name="submit3" alt="BlueTipDVD.co.uk - view cart">
<input type="hidden" name="display" value="1">
</form></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="3"><div align="center"><font color="#CCCCCC" size="2" face="Arial, Helvetica, sans-serif"><img src="images/bar.gif" width="766" height="16"></font></div>
<div align="center"></div></td>
</tr>
<tr>
<td width="31%" align="center" valign="middle" bgcolor="#FFFFFF"><p><font color="#666666" size="2" face="Arial, Helvetica, sans-serif">Welcom
message........................<br>
............................................... </font></p></td>
<td colspan="2" bgcolor="#FFFFFF"><div align="center"><font color="#666666" size="2" face="Arial, Helvetica, sans-serif">All
prices are incluive of VAT and postage costs so there are no hidden costs</font></div></td>
</tr>
</table>
<table width="766" border="0" align="center" cellpadding="1" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td width="623"><table width="100%" border="1" align="center" bgcolor="#FFFFFF">
<?php include "vsadmin/db_conn_open.php";
$query="SELECT * FROM products";
$result=mysql_query($query);


$num=mysql_num_rows($result);


mysql_close();



$i=0;
while ($i < $num) {


$ID=mysql_result($result,$i,"ID");
$name=mysql_result($result,$i,"name");
$price=mysql_result($result,$i,"price");
$photo=mysql_result($result,$i,"photo");
$longdescription=mysql_result($result,$i,"longdescription");


?>

Add a semi-colon to the line

$ID = $_GET['ID'];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.