Code compilation issues
This has probably been addressed already, but I want to be able to change elements like headers, paragraph information within one part of the site and do this using an array of images. For instance, if you were to click on image1, the div that may hold the information, name of image, image description, and price, for example, will change.
Now, I know how to do this using a basic function technique, but I end up having to separate the code for each image, and I would like to store all the information lets say, on a database, and call the information as the user clicks. I know that there is a looping technique to do this, but I can not get it to work properly.
Def. need more info to understand what the problem is.
So you've got a navigation at some point on your site with images that, when clicked, will change parts of the page?
Because you've given no code and not much information, I can't give exact code, but it would be something along the lines of:
Let's say you've got 3 columns in your database: name, age, gender. These are now stored in PHP as: $results[$i]['name'], $results[$i]['age'] and $results[$i]['gender'].
// get all the data from the necessary table
$get_data = mysql_query("SELECT * FROM some_table");
for($i = 0; $i < mysql_num_rows($get_data); $i++)
// store the table rows in to a PHP 3-dimensional associative array.
$results[$i] = mysql_fetch_assoc($get_data);
Now in PHP you can echo the results in to each of these arrays like so:
var details= Array(name = Array(),
age = Array(),
gender = Array());
<?php for($i = 0; $i < count($results); $i++) echo "details[".$i."] = '" . $result[$i]["name"] . "',"; ?>
<?php for($i = 0; $i < count($results); $i++) echo "details[".$i."] = '" . $results[$i]["age"] . "',"; ?>
<?php for($i = 0; $i < count($results); $i++) echo "details[".$i."] = '" . $results[$i]["gender"] . "',"; ?>
For example, a button with an onClick event which calls a function "change();". Your "change();" function would look something like:
You can also create a variable and give it a string value containing HTML, and set the .innerHTML value to the value of the variable.
document.getElementById("your_div_id").innerHTML = "something";
Please provide more information so we can help more.
Last edited by George88; 02-23-2012 at 04:43 PM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread