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.
02-23-2012, 12:15 PM
Def. need more info to understand what the problem is.
02-23-2012, 05:39 PM
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:
// 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);
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'].
var details= Array(name = Array(),
age = Array(),
gender = Array());
Now in PHP you can echo the results in to each of these arrays like so:
For example, a button with an onClick event which calls a function "change();". Your "change();" function would look something like:
document.getElementById("your_div_id").innerHTML = "something";
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.
Please provide more information so we can help more.
02-24-2012, 11:17 AM