Hi everybody,
I would like to have functionalities & interface like this
http://www.bluenile.co.uk/diamond-search?filter_id=0&track=head.

Currently, the search result and checkbox are presented as in the above example.

However, I am not sure of where should we keep the checked value to have something like
in the bottom.
( all selected record will be listed,
then users can remove the records if they change their mind,
before comparing the selected records- http://www.bluenile.co.uk/diamond_comparison.jsp#DIAMONDCOMPARISON_STEP.

I don't think we should keep the value in database..or it is?
Can I use php solely able to do this, or should I combine with javascript?

Many thanks

Recommended Answers

All 12 Replies

This just screams AJAX, or at least at lot of HTML and some serious Javascript... I don't think anyone will just give you anything more than links to tutorials here, but I hope I'm proven wrong!

Good luck with your project :)

Isn't that what $_session is for?

Ahh right after a page-load... the site you linked to was using ajax/js but you could achieve a similar effect using PHP and Javascript to automatically submit the form...

In this scenario you would have to have a bit of JavaScript to submit the form (every time a user selects a product for comparison) able to use $_POST to grab that input's value by referencing the "name" of the input, and load a page which has added that product for comparison.

You could apply an "onchange" attribute when the user selects a product:

http://snippets.dzone.com/posts/show/785

Is that the sort of thing you mean?

each checkbox is a column ID whech is collected from $_POST then stored in $_session for continued use until the selection is modified. The database would need to be accessed anyway, so PHP would work fine with a submit.

Hi jrm & rade,
many thanks four input.
I will try to implement the session here.
If I face any problem,I will come back here :D .
tq

each checkbox is a column ID whech is collected from $_POST then stored in $_session for continued use until the selection is modified. The database would need to be accessed anyway, so PHP would work fine with a submit.

it seems that I need to use form to POST the selected checkbox.
Any help?
thank you

echo "<td><input type=\"checkbox\" name=\"chkid_$i\" value=\"$ID\></td>";

take a look here

Thanks.
Is this what I need to do:

<?

function showCart() {
	$cart = $_SESSION['cart'];
	if ($cart) {
		$items = explode(',',$cart);
		$contents = array();

$cbox = $_SESSION['cbox'];
if ($cbox) {
	$cbox.= ','.$_POST['ID'];
} else {
	$cbox= $_POST['ID'];
}
$_SESSION['cbox'] = $cbox;
?>

or can I use cookie as a session, like in this example.

function GetCartId()
{
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table

if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID

session_start();
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}

?>

Thanks.
Is this what I need to do:

<?

function showCart() {
	$cart = $_SESSION['cart'];
	if ($cart) {
		$items = explode(',',$cart);
		$contents = array();

$cbox = $_SESSION['cbox'];
if ($cbox) {
	$cbox.= ','.$_POST['ID'];
} else {
	$cbox= $_POST['ID'];
}
$_SESSION['cbox'] = $cbox;
?>

I should $_POST[] to retrieve the records from the list ( that was generated from
database (search query) ).
How can I declare the $_POST here.

Thank you

I have had success storing values in cookies. This was particularly useful when I had to transfer values between JavaScript and PHP.

Here is the code I wrote at the time. The context was that latitude and longitude values were being modified in a Google Maps application, and I wanted to be able to pick that up and store the value in a database. So I added a line geoCookies("lat","lon"); in the Google Maps javascript to store the values in a cookie every time the pointer on the map was moved.

Subsequently, my PHP code would read the cookie and write the value to the database record for that location.

geoCookies("lat","lon"); // write latitude & longitude to cookies

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}	// end function createCookie()


function geoCookies(lat,lon) {

	// ~~~ WRITE LATITUDE/LONGITUDE TO COOKIE ~~~
	// this function allows transfer of information from javascript to PHP 
	// (client-side script to server-side script) by storing the information 
	// in cookies.
	// It uses session cookies; they won't be available in future sessions
	// Once written, the cookies can be picked up by PHP to write to database

	// alert("Lat: "+document.getElementById("lat").innerHTML+"\nLng: "+document.getElementById("lng").innerHTML);
	
	createCookie("lat",document.getElementById("lat").innerHTML);
	createCookie("lng",document.getElementById("lng").innerHTML);
	
}	// end function geoCookies()

Then in PHP;

// retrieve latitude & longitude from cookies...
$latitude  = $_COOKIE["lat"];
$longitude = $_COOKIE["lng"];
// ... and write them to the database
$latlon_sql = "UPDATE sac_map_locations SET latitude='$latitude',longitude='$longitude' WHERE id='".$_POST['id']."'";
mysql_query($latlon_sql) 
  or die(__LINE__.": Error updating Latitude/Longitude.  Please advise webmaster: ".mysql_error());

I hope that's useful.

Rob

thanks Robb,
before that, how can I get the checked check boxes with related records and display them in another table?

thank you

I used session and the id of the selected checkbox are passed to another page currently.
now I do another query based on the ID of the selected checkbox.
I want to display the fields from the selected result in columns like this
http://www.bluenile.co.uk/diamond_comparison.jsp#DIAMONDCOMPARISON_STEP

I did this

<?
foreach($acb as $key => $value)
    {
    echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />';
	//print out the values
  
		$query = "SELECT * from lesson WHERE lessonID ='".$value."'" ;
		$result = mysql_query( $query, $con); 
        $result_array = mysql_fetch_array($result);
//echo $query;
// for each pice of info saved in array, display it to users
echo '<table>';
foreach($result_array as $key => $value)
//while($row = mysql_fetch_array($result_array))
{
		if (!is_int($key))
		{
				
	echo '<tr><td>Lesson ID</td><td>'.$result_array['lessonID'].'</td></tr>';
	echo '<tr><td>Year</td><td>'.$result_array['year'].'</td></tr>';
	echo '<tr><td>Subject</td><td>'.$result_array['subject'].'</td></tr>';
	echo '<tr><td>Learning Area</td><td>'.$result_array['learningArea'].'</td></tr>';
	echo '<tr><td>Topic</td><td>'.$result_array['topic'].'</td></tr>';
	echo '<tr><td>Learning Outcome</td><td>'.$result_array['LO'].'</td></tr>';
		}
}
echo '</table>';
}
?>

the result returned is displayed like this

Lesson ID 52
Year 4
Subject ICT
Learning Area Computer Systems
Topic Hardware
Learning Outcome Storage
Lesson ID 52
Year 4
Subject ICT
Learning Area Computer Systems
Topic Hardware
Learning Outcome Storage
Lesson ID 52
Year 4
Subject ICT
Learning Area Computer Systems
Topic Hardware
Learning Outcome Storage

it is loops for several times before showing the next records from the selected checkbox (also several times).
I want to have them displayed in columns like the example above.
can anyone help?
thank you

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.