Note that there are some explanatory texts on larger screens.

plurals
  1. PORandom picture form database and rating system
    primarykey
    data
    text
    <p>Hey i have a problem on my website i want to display a image with a rating under and then when i rate the image it should change to the next picture. And there is my problem because it displays the next picture correctly but it doesn't change the id in the rating system so i am rating the same picture again and again Source code: <pre><code>$place="upload/"; $first = mysql_query("SELECT * FROM images ORDER BY RAND()"); while($wor = mysql_fetch_array($first)) { $id=$wor['id']; $name = $wor['name']; $image = $place . $wor['name']; } $number="1"; $wrongnumber="2"; $random = mysql_query("SELECT * FROM images ORDER BY RAND()"); $place="upload/"; echo '&lt;script&gt; '; while($wor = mysql_fetch_array($random)) { $ids=$wor['id']; $name = $wor['name']; $images = $place . $wor['name']; $number=$number + 1; $wrongnumber=$wrongnumber + 1; echo 'function ' . 'changeSrc' . $number . '() '; ?&gt; { document.getElementById("rand").src="&lt;? echo $images;?&gt;"; document.getElementById("button").onclick=changeSrc&lt;? echo $wrongnumber;?&gt;; document.getElementById("102").id=&lt;? echo $ids;?&gt;; } &lt;? } ?&gt; &lt;/script&gt; &lt;img id="rand" src="&lt;? echo $image;?&gt;"&gt;&lt;br&gt; &lt;div id="button" onclick="changeSrc2()"&gt; &lt;div class="rate_widget" id="102"&gt; &lt;div class="star_1 ratings_stars"&gt;&lt;/div&gt; &lt;div class="star_2 ratings_stars"&gt;&lt;/div&gt; &lt;div class="star_3 ratings_stars"&gt;&lt;/div&gt; &lt;div class="star_4 ratings_stars"&gt;&lt;/div&gt; &lt;div class="star_5 ratings_stars"&gt;&lt;/div&gt; &lt;div class="total_votes"&gt;vote data&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The output code: </p> <pre><code>// This is the first thing we add ------------------------------------------ $(document).ready(function() { $('.rate_widget').each(function(i) { var widget = this; var out_data = { widget_id : $(widget).attr('id'), fetch: 1 }; $.post( 'ratings.php', out_data, function(INFO) { $(widget).data( 'fsr', INFO ); set_votes(widget); }, 'json' ); }); $('.ratings_stars').hover( // Handles the mouseover function() { $(this).prevAll().andSelf().addClass('ratings_over'); $(this).nextAll().removeClass('ratings_vote'); }, // Handles the mouseout function() { $(this).prevAll().andSelf().removeClass('ratings_over'); // can't use 'this' because it wont contain the updated data set_votes($(this).parent()); } ); // This actually records the vote $('.ratings_stars').bind('click', function() { var star = this; var widget = $(this).parent(); var clicked_data = { clicked_on : $(star).attr('class'), widget_id : $(star).parent().attr('id') }; $.post( 'ratings.php', clicked_data, function(INFO) { widget.data( 'fsr', INFO ); set_votes(widget); }, 'json' ); $.post( 'setcookie.php', clicked_data, function(INFO) { widget.data( 'fsr', INFO ); set_votes(widget); }, 'json' ); }); }); function set_votes(widget) { var avg = $(widget).data('fsr').whole_avg; var votes = $(widget).data('fsr').number_votes; var exact = $(widget).data('fsr').dec_avg; window.console &amp;&amp; console.log('and now in set_votes, it thinks the fsr is ' + $(widget).data('fsr').number_votes); $(widget).find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote'); $(widget).find('.star_' + avg).nextAll().removeClass('ratings_vote'); $(widget).find('.total_votes').text( votes + ' votes recorded (' + exact + ' rating)' ); } // END FIRST THING &lt;/script&gt;&lt;script&gt; function changeSrc2() { document.getElementById("rand").src="upload/1329614519daily_erotic_picdump_48-2-500x334.jpg"; document.getElementById("button").onclick=changeSrc3; document.getElementsByClassName('rate_widget').id="125"; } function changeSrc3() { document.getElementById("rand").src="upload/1329614453tumblr_leb4pwc0Xc1qzy9ouo1_1280-1024x640.jpg"; document.getElementById("button").onclick=changeSrc4; document.getElementsByClassName('rate_widget').id="65"; } function changeSrc4() { document.getElementById("rand").src="upload/1329614295daily_erotic_picdump_20-copy-500x333.jpg"; document.getElementById("button").onclick=changeSrc5; document.getElementsByClassName('rate_widget').id="44"; } function changeSrc5() { document.getElementById("rand").src="upload/1329614301daily_erotic_picdump_80-2-500x375.jpg"; document.getElementById("button").onclick=changeSrc6; document.getElementsByClassName('rate_widget').id="51"; } function changeSrc6() { document.getElementById("rand").src="upload/13296142941-3-450x600.jpg"; document.getElementById("button").onclick=changeSrc7; document.getElementsByClassName('rate_widget').id="225"; } function changeSrc7() { document.getElementById("rand").src="upload/1329614284tumblr_l53l0qM6HB1qc4zlyo1_500-450x568.jpg"; document.getElementById("button").onclick=changeSrc8; document.getElementsByClassName('rate_widget').id="19"; } function changeSrc8() { document.getElementById("rand").src="upload/1329614454tumblr_lro15r2fkh1qzlro6o1_500-450x301.jpg"; document.getElementById("button").onclick=changeSrc9; document.getElementsByClassName('rate_widget').id="73"; } function changeSrc9() { document.getElementById("rand").src="upload/tumblr_mccaolmQPE1regfy1o1_500.jpg"; document.getElementById("button").onclick=changeSrc10; document.getElementsByClassName('rate_widget').id="272"; } function changeSrc10() { document.getElementById("rand").src="upload/1329614297Pix-Mix-304-img012-500x312.jpg"; document.getElementById("button").onclick=changeSrc11; document.getElementsByClassName('rate_widget').id="47"; } &lt;/script&gt; &lt;img id="rand" src="upload/1329614465tumblr_lscy8aqOFE1qg7sdjo1_500-450x322.jpg"&gt;&lt;br&gt; &lt;div id="button" onclick="changeSrc2()"&gt; &lt;div class="rate_widget" id="99"&gt; &lt;div class="star_1 ratings_stars"&gt;&lt;/div&gt; &lt;div class="star_2 ratings_stars"&gt;&lt;/div&gt; &lt;div class="star_3 ratings_stars"&gt;&lt;/div&gt; &lt;div class="star_4 ratings_stars"&gt;&lt;/div&gt; &lt;div class="star_5 ratings_stars"&gt;&lt;/div&gt; &lt;div class="total_votes"&gt;vote data&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload