Hi,

I am pretty new to php, but I am loving it! Finding out what's wrong, and finding the solution. But this time I can't find it!

You can see down there a copy screen of the website I'm doing.
There is a menu to the left "Clothing, Bathtime..."
When I click on Clothing, I want to go get the info about the clothing Products that are in the database. The info shows up in the main iframe.
At the bottom there are also thumbnails of all clothing products. So that when I click on a thumbnail, a new info is called from the database, and shows up in the main iframe.

Meanwhile, the main iframe contains a description of the clothing + a photo of the clothing + 3 other thumbnails relative to the clothing (that are zooms of the clothing). Let's call them 'zoom-thumbnails'.
My problem is that I want to be able to click on these zoom-thumbnails and show the big photo related to them in place of the photo of the clothing.

I had done the code in html at first, and I used 2 iframes: the main iframe containing the description, the photo, and the zoom-thumbnails, and another iframe containing the photo in question. So that's like an iframe in an iframe.
But with php/database, it won't be possible to load properly. I haven't tried but I am pretty sure I can't.

I have been using $_GET to pass the variables from the thumbnails at the bottom of the page to the main iframe.
I am wondering if using session variables will allow me what I'm doing? Will it load the second iframe of the photo when I click on the bottom thumbnails?

I hope someone can understand me... And I'm hoping some help! Maybe I've done everything wrong from the beginning but I am willing to learn!

Thank you!

Member Avatar for Zagga

Hi BouhBob,

I am not familiar with iframes but it is very easy to try using SESSIONs to see if it works.

Just place this code at the very top of your main page . . .

<?php
session_start();
	$_SESSION["VariableName"] = "VariableValue";
?>

and see if you can access the variable $_SESSION inside your iframe.

If that doesn't work, you may need to put

<?php
sessiion_start();
?>

at the top of eachirfame (but I am not sure about this as I don't/haven't used iframes)


Hope this helps.
Zagga

Hi Zagga,

Thank you for helping! I will try asap!

So I am curious: what do you use if you don't use iframe? Javascript?
What would you have done for the website I'm doing? instead of using iframe?

Thank you! I will let you know if it works! Otherwise I will ask again!

Member Avatar for diafol

Personally, I would use Ajax for this. I would also use the jQuery javascript framework, utilising json data.
iFrames are a bit intense just for data display.

Just a for instance:

<p>More clothings</p>
<ul>
<li id="thumb1">
<a href="javascript: headlineMe('234');"><img src="/images/thumb234.jpg" /></a>
</li>
<li id="thumb2">
<a href="javascript: headlineMe('345');"><img src="/images/thumb345.jpg" /></a>
</li>
<li id="thumb3">
<a href="javascript: headlineMe('289');"><img src="/images/thumb289.jpg" /></a>
</li>
<li id="thumb4">
<a href="javascript: headlineMe('351');"><img src="/images/thumb351.jpg" /></a>
</li>
<li id="thumb5">
<a href="javascript: headlineMe('12');"><img src="/images/thumb12.jpg" /></a>
</li>
</ul>

The javascript function headlineMe deals with the product id and sends this data to a php file, which processes it and retrieves DB data, and returns it in json format.

The function then applies specific json data to html elements, e.g. your headline image and the satellite images that accompany it.

Anyway, just an idea.

//You could use a js listener for the images as opposed to using a link element, but I'll keep it simple!

Ok so I have tried the session idea.
Sorry Ardav, I don't have time right now to learn so many things you're saying (Ajax, headline...) But thank you! Hopefully I will learn it one day!

So session: Here is my code, and the session doesn't show up... the vartest (a test variable) passes though, so I might just not write something right:

I want to get $clothings[id], and this variable will change each time I click on the thumbnails.

Code in the first page:

<?php
session_start();
$_SESSION["variable"]="$clothings[id]";
$_SESSION["vartest"]="135156468";
?>	

//blabla
<?php
//connection

$sql_clothings=mysql_query("SELECT * FROM products WHERE category='Clothing'")
or die(mysql_error());  

echo ("<br />");
echo ("<div class='text'>");
echo ("More clothings:");
echo ("</div>");
// keeps getting the next row until there are no more to get
while($clothings = mysql_fetch_array($sql_clothings)) {
	// Print out the contents of each row into a table
	
	//echo $clothings['main_thumbnail'];
	//echo ("<img src=\"); echo $clothings['main_thumbnail']; echo ("" alt="dress" width="73" height="73" border="0" class="img" />;
	echo ("<div class='thumbnail'>");
	//echo "<a href='itest.php?product_id=$clothings[id]'>Product Details</a>"; 
	//echo $clothings['id'];
	echo "<a href='iclothing3.php?product_id=$clothings[id]' target='iframe'><img src='".$clothings['main_thumbnail']."' width='73' height='73' border='0' /></a>"; 
	echo ("</div>");
	//echo $clothings['name_product'];
	//echo ("<br />");
} 
?>

Code that should get the value through session (just for a test, see if it is gotten):

echo $_SESSION['variable'];
echo $_SESSION['vartest'];

the vartest is passed, no problem, but not the one I actually want! "variable"

So it there something wrong in my code? Please?

Thank you!

Member Avatar for diafol

No worries, good luck.

Member Avatar for Zagga

Hi bouhbob,

In your code, I don't see where $clothings[id] is being set, so $_SESSION will be blank.

Just to be a bit clearer, you need to add

<?php
session_start();
?>

at the very top of any page that is using sessions. The session variables themselves can be set anywhere you like in the code (inside the while loop for example).

As for your question about what I use instead of Iframes, I don't. I moved away from sites that contained frames years ago and I haven't built anything yet where I need frames (although if I did, I would look at Ajax as ardav suggested).


Hope this helps.
Zagga

It might be quick to use session vars but, if this is a search engine friendly site currently, the implementation of sessions might hurt seo efforts later on down the road, depending on server configuration. Its probably a better decision to use javascript/DOM to implement.

For a refresher on DOM, you might want to check out http://www.w3schools.com/jsref/dom_obj_frame.asp

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.