954,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with php and javascript

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:


<? echo "$name" ?>


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

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

symoore22
Newbie Poster
9 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

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.

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

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

symoore22
Newbie Poster
9 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

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.

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.
[PHP]
/*
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";
[/PHP]

Does this help you?

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 


<?php include "vsadmin/db_conn_open.php";
$prod_id = $_GET['id']

$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");

?>
<? echo "$ID"?> <? echo "$name"?><? echo "$longdescription"?>

symoore22
Newbie Poster
9 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

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:
[PHP]
$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");
[/PHP]
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.

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

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

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

$ID = $_GET['ID']
$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

Welcome to our website Free Delivery on all orders

bar.gif Welcom message........................
...............................................


All
prices are incluive of VAT and postage costs so there are no hidden costs

<?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");

?>

symoore22
Newbie Poster
9 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

Add a semi-colon to the line

$ID = $_GET['ID'];
Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You