I'm not very new to programming nor am I a prodigy or a maestro at it. Now I'm trying to make a website like Facesmash where
- two images show up randomly from the respective arrays and
- an up-vote is given to the image on which user clicked
- the result is stored as a vote in database
Now I've done with the first part and will do with the third as well with php.
Where I'm facing a problem is the 2nd part.
My code in JavaScript looks like this..
var imagesArray1 = ["a.jpg","b.jpg","c.jpg","d.jpg","e.jpg"];
var imagesArray2 = ["f.jpg","g.jpg","h.jpg","i.jpg","j.jpg"];
function displayImage(){
document.getElementById('nextButton').value="NEXT";
var num1 = Math.floor(Math.random() * (imagesArra1.length));
var num2 = Math.floor(Math.random() * (imagesArray2.length));
document.canvas1.src = imagesArray1[num1];
document.canvas2.src = imagesArray2[num2]; }
As you can see.. I've created two arrays and a random Image is generated from both the two. Now to create a polling system, one solution would be to take two variables p and q. p=num1
and q=num2
If image1 is clicked, the php code reports "p" and value of the index num1
to the DB
If image2 is clicked, php code sends "q" and value of the index num2
num1
and num2
are the randomly generated indices of the image arrays. I'll do with the php part, Just wanted help in this.
Any other code solution would be appreciated. Thanks a ton for time and help