jck Posted July 12, 2007 Share Posted July 12, 2007 im trying to create a script for my jokes site that lets u see what others have voted for any joke the strucure of the table is simple itemid,rating and username this is the sample code i wrote for a joke of item id 54 but when i run it i get blank page please help me <? require_once("conn.php"); require_once("templates/MainHeader.php"); $q1 = "select * from dd_rating where ItemID = '54' "; $r1 = mysql_query($q1) or die(mysql_error()); $numvote=mysql_numrows($r1) echo "<b><center>See what Rating others gave for this joke </center></b><br><br>"; $i=0; while($i<$numvote){ $name=mysql_result($r1,$i,"username"); $rate=mysql_result($r1,$i,"Rating"); echo"$name." had given a rating of".$rate." to this joke<br>"; $i++ } require_once("templates/MainFooter.php"); ?> Please tell me whats wrong with it Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/ Share on other sites More sharing options...
cmgmyr Posted July 12, 2007 Share Posted July 12, 2007 try: echo $name." had given a rating of ".$rate." to this joke<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296100 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 even the see whatr others have rated line didnt come Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296104 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 try: echo $name." had given a rating of ".$rate." to this joke<br>"; Still blank Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296105 Share on other sites More sharing options...
cmgmyr Posted July 12, 2007 Share Posted July 12, 2007 how about: <?php require_once("conn.php"); require_once("templates/MainHeader.php"); $q1 = "select * from dd_rating where ItemID = '54' "; $r1 = mysql_query($q1) or die(mysql_error()); $numvote = mysql_num_rows($r1); //<~Semi colon missing echo "<b><center>See what Rating others gave for this joke </center></b><br><br>"; $i=0; while($i<$numvote){ $name=mysql_result($r1,$i,"username"); $rate=mysql_result($r1,$i,"Rating"); echo $name." had given a rating of ".$rate. " to this joke<br>"; $i++ } require_once("templates/MainFooter.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296107 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 still blank ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296109 Share on other sites More sharing options...
JayBachatero Posted July 12, 2007 Share Posted July 12, 2007 Try this. <?php require_once("conn.php"); require_once("templates/MainHeader.php"); $request = mysql_query(" SELECT rt.username, rt.Rating FROM dd_rating AS rt WHERE ItemID = 54") or die(mysql_error()); echo '<b><center>See what Rating others gave for this joke </center></b><br><br>'; while ($row = mysql_fetch_assoc($request)) { $name = $row['username']; $rate = $row['Rating']; echo ' ' . $name . ' had given a rating of ' . $rate . ' to this joke.<br />'; } mysql_free_result($request); require_once("templates/MainFooter.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296115 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 Thank u very much it worked but i have 2 questions the first question is whhat was wrong in mine beside the missing semicolon? Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296117 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 and the secound one how to implement it on */view.php?ItemID=54 Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296121 Share on other sites More sharing options...
JayBachatero Posted July 12, 2007 Share Posted July 12, 2007 You are missing another ; after the counter. I suggest that you enable error reporting while in development. Add error_reporting(E_ALL); to your main file. In this case conn.php. Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296124 Share on other sites More sharing options...
cmgmyr Posted July 12, 2007 Share Posted July 12, 2007 ...damn missed that anyways use something like: $id = $_GET['id']; $request = mysql_query(" SELECT rt.username, rt.Rating FROM dd_rating AS rt WHERE ItemID = $id") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296127 Share on other sites More sharing options...
JayBachatero Posted July 12, 2007 Share Posted July 12, 2007 Try <?php require_once("conn.php"); require_once("templates/MainHeader.php"); if (isset($_GET['ItemID']) && is_numeric($_GET['ItemID'])) { $request = mysql_query(" SELECT rt.username, rt.Rating FROM dd_rating AS rt WHERE ItemID = $_GET[itemID]") or die(mysql_error()); echo '<b><center>See what Rating others gave for this joke </center></b><br><br>'; if (mysql_num_rows($request) > 0) { while ($row = mysql_fetch_assoc($request)) { $name = $row['username']; $rate = $row['Rating']; echo ' ' . $name . ' had given a rating of ' . $rate . ' to this joke.<br />'; } } else echo 'No ratings for this joke.'; } else echo 'The ItemID is not valid.'; require_once("templates/MainFooter.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296128 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 im very new to this could u please explain me what to what was that rt.username thing and obviously ur code will be more efficient than mine can u explain how?? and im very lucky that a devoloper of smf helped me Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296132 Share on other sites More sharing options...
JayBachatero Posted July 12, 2007 Share Posted July 12, 2007 Ok lets break it down. This part checks first to see if "ItemID" is set in the URL. If it's set then it checks to see if it's numeric. The point of that is so that you can have some sanity checks and make sure that a number was entered. if (isset($_GET['ItemID']) && is_numeric($_GET['ItemID'])) In dd_rating AS rt the rt part is the alias for that table. You usually use table alias when you are joining more than one tables. You don't want to keep typing xxx.yyy for each column that you want. SELECT m.id_member, m.name, m.age, rt.ratings FROM members AS m LEFT JOIN ratings AS tr ON (tr.id_member = m.id_member) Imagine having to write members.x each time and so on. Also it is good to select the columns that you will be using instead of doing a SELECT *. Doing that will select all the columns in that table. Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296134 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 thank u very much ive understood a little better now Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296139 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 thanks to chris too Quote Link to comment https://forums.phpfreaks.com/topic/59591-solved-help-please/#findComment-296222 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.