using JavaScript with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someone2088
Forum Commoner
Posts: 42
Joined: Thu Nov 17, 2011 1:09 pm

using JavaScript with PHP

Post by someone2088 »

Hi,

I currently have some PHP on my website, which is querying a PostgreSQL database table, and displaying the results of the query in a table on the web page.

The database table contains a list of games, along with their price, description and reference number- my PHP query is pulling all of this information from the database database table, and displaying it in a table on my web page- with one game and its info per row. I have also added a checkbox to the end of each row in my PHP.

What I now need to do, is write some JavaScript to loop through the table, checking which checkboxes the user has ticked, and store the game information for each game the user has selected, in a PHP session variable, so that the user can view the items they've selected on the next page (like a shopping basket).

This is the code that's displaying the table with the games, and all of their information, along with a checkbox.

Code: Select all

<?php
	// print out the data stored in the $gameTitleQueryResult variable in a table
	// put the table inside a form, so that user can add games to shoppingBasket
	echo '<div id="Games">';
	echo '<table id="Games" border="1">';
	while ($a=pg_fetch_row($gameTitlesQueryResult)){
		echo '<tr>';
		for ($i=0; $i<pg_num_fields($gameTitlesQueryResult); $i++){
			echo '<td>'.htmlspecialchars($a[$i], ENT_QUOTES).'</ td>';
		}
	echo "<td><input type='checkbox' name='selectGame[]' value='{$a['refnumber']}' /></ td>
	</ tr>";
	}
	echo '</table></ div>';
?>
If someone could tell me how I can write the JavaScript to keep track of which checkboxes have been selected, I would be very grateful.

Thanks in advance!
Post Reply