extrovertive Posted September 30, 2006 Share Posted September 30, 2006 Seems like it works.Try this:[code=php:0]//$id = $_GET['id'];while($qry_rating = mysql_query("SELECT rating FROM site")){ list($rating) = mysql_fetch_row($qry_rating);$new_rating2 = (string)$rating;print "Vistor Rating: " . $new_rating2 . " "; //gets the average rating from the database and put into an image variable$rateA = explode(".", $new_rating2);$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];//store rating in image2 variable$image2 = $rateA[0] . $rateA[1] . '.png'; //Display user's rating image2print "<img src=\"images/{$image2}\" />";}[/code] Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 30, 2006 Author Share Posted September 30, 2006 Sorry where am i putting this?Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 As a test script somewhere. Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 30, 2006 Author Share Posted September 30, 2006 Parse error: parse error, unexpected T_STRING in C:\public_html\RPG\test.php on line 11Line 11 being:print "Vistor Rating: " . $new_rating2 . " ";Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 Looks fine to me.You're using:[code=php:0]while($qry_rating = mysql_query("SELECT rating FROM site")){ list($rating) = mysql_fetch_row($qry_rating);$new_rating2 = (string)$rating;print "Vistor Rating: " . $new_rating2 . " "; //gets the average rating from the database and put into an image variable$rateA = explode(".", $new_rating2);$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];//store rating in image2 variable$image2 = $rateA[0] . $rateA[1] . '.png'; //Display user's rating image2print "<img src=\"images/{$image2}\" />";}[/code]Right? Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 30, 2006 Author Share Posted September 30, 2006 Yup using:<?php include("includes/dbconnect.php");while($qry_rating = mysql_query("SELECT rating FROM site")){ list($rating) = mysql_fetch_row($qry_rating);$new_rating2 = (string)$rating;print "Vistor Rating: " . $new_rating2 . " "; //gets the average rating from the database and put into an image variable$rateA = explode(".", $new_rating2);$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];//store rating in image2 variable$image2 = $rateA[0] . $rateA[1] . '.png'; //Display user's rating image2print "<img src=\"images/{$image2}\" />";}?> Quote Link to comment Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 Looks fine to me. Perhaps refreshing your browser and did you save the code? Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 30, 2006 Author Share Posted September 30, 2006 ahh, didn't save it properly.But it crashed my IE, just kept on coming up with the image for number 4 and some writing next to it saying something like visitor number 4 ???Peter. Quote Link to comment Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 Ok, so ID = 10 displays has a 1.25 rating right?[code=php:0]$id = $_GET['id'];$id = 10;while($qry_rating = mysql_query("SELECT rating FROM site WHERE id = '$id'")){ list($rating) = mysql_fetch_row($qry_rating);$new_rating2 = (string)$rating;print "Visitor Rating: " . $new_rating2 . " "; //gets the average rating from the database and put into an image variable$rateA = explode(".", $new_rating2);$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];//store rating in image2 variable$image2 = $rateA[0] . $rateA[1] . '.png'; //Display user's rating image2print "<img src=\"images/{$image2}\" />";}[/code]And the image path is correct, right? Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 30, 2006 Author Share Posted September 30, 2006 Yes, thats right, this shows thousands of these:Visitor Rating: 1.25 (Correct image for 1.25 also shown next to each one).Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 For my test script above, did you try that one?$id = $_GET['id'];$id = 10;You're saying my test script above thousands of:"Visitor Rating: 1.25 (Correct image for 1.25 also shown next to each one)"but all ID are unique right?Try taking the while loop out:[code=php:0]$id = $_GET['id'];$id = 10;$qry_rating = mysql_query("SELECT rating FROM site WHERE id = '$id'"); list($rating) = mysql_fetch_row($qry_rating);$new_rating2 = (string)$rating;print "Visitor Rating: " . $new_rating2 . " "; //gets the average rating from the database and put into an image variable$rateA = explode(".", $new_rating2);$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];//store rating in image2 variable$image2 = $rateA[0] . $rateA[1] . '.png'; //Display user's rating image2print "<img src=\"images/{$image2}\" />";[/code]And if the display is correct for ID 10, then you can try to implement that code portion in your full script (removing the "$id = 10;" of course) Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 30, 2006 Author Share Posted September 30, 2006 *sighs*, it worked fine in the test script then when i put it in the list.php code, it just shows the broken image /images/.png. Is another bit of the code messing it up?Thanks.Peter, Quote Link to comment Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 I think I see another problem, which I fixed.You were using $_GET['id'], shouldn't it be $qry['id'] ???Here's the revised version:[code=php:0]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><?php include("includes/dbconnect.php"); ?><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>View Sites</title></head><body><?phpprint "<table border=1 class=list>";echo("<thead><tr><td>Site Name</td><td>Editor Rating</td><td>Visitor Rating</td><td>Date Added</td><td>Publisher</td></tr></thead><tbody>");$result = mysql_query('SELECT * FROM site ORDER BY name DESC');while ($qry = mysql_fetch_array($result)){print "<tr>";print "<td><a href=site.php?id=$qry[id]>$qry[name]</td>";//Assuming each editorrating correpsonding an image name w/ that rating$image = $qry['editorrating'] . '.png';//Display user's rating imageecho "<td><img src=\"images/{$image}\" /></td>";//Get User's ID rating and display rating image based on that rating$id = $qry['id'];$qry_rating = mysql_query("SELECT rating FROM site where id='$id'"); list($rating) = mysql_fetch_row($qry_rating);$new_rating2 = (string)$rating; //gets the average rating from the database and put into an image variable$rateA = explode(".", $new_rating2);$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];//store rating in image2 variable$image2 = $rateA[0] . $rateA[1] . '.png'; //Display user's rating image2echo "<td><img src=\"images/{$image2}\" /></td>";//Display dateaddedprint "<td>$qry[dateadded]</td>";//Display publisherprint "<td>$qry[publisher]</td>";print "</tr>";} print "</tbody></table>";?><p> </p><p> </p></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 30, 2006 Author Share Posted September 30, 2006 SUPER! It works! Thanks for all your help extrovertive. You've been great!Much appreciated!Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 You're welcome. If only I spotted the $_GET error eariler :D Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 30, 2006 Author Share Posted September 30, 2006 Hehe. No Worries. Thanks again!Pete. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.