mr_badger Posted April 27, 2007 Share Posted April 27, 2007 I'am doing this tutorial from one of my books and I have copied it all word for word but when it comes to testing I'am gettin alot of errors, I don't know if it's old code syntax or what but I need help. <?php require("config.php"); require("functions.php"); if(pf_check_number($_GET['id']) == TRUE) { $validid = $_GET['id']; } else { header("Location: " . $config_basedir); } require("header.php"); $sql = "SELECT * FROM stories WHERE id = " . $validid . ";"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo "<h1>" . $row['subject'] . "</h1>"; echo date("D jS F Y g.iA" , strtotime($row['dateposted'])) . "<br />"; echo nl2br($row['body']); $avgsql = "SELECT COUNT(id) AS number, AVG(rating)AS avg FROM ratings WHERE story_id = " .$validid . ";"; $avgresult = mysql_query($avgsql); $avgrow = mysql_fetch_assoc($avgresult); echo "<p>"; echo "<strong>Rating</strong> "; if($avgrow['number'] == 0) { echo "No ratings"; } else { $a = (round($avgrow['avg'] * 2) / 2) . "<br />"; $a *= 10; if($a%5 == 0 && $a%10 != ) { $range = ($a / 10) - 0.5; } else { $range = $a / 10; } for($i=1;$i<=$range;$i++) { echo "<img src='" . $config_basedir . "news/full.gif'>"; } if($a%5 == 0 && $a%10 ! = ) { echo "<img src='" . $config_basedir . "news/half.gif'>"; } $a = $a / 10; $remain = 10 - $a; for($range=1;$range<=$remain;$range++) { echo "<img src='" . $config_basedir . "news/off.gif'>"; } } echo "<br />"; echo "<strong>Rate this story</strong>: "; if($_SESSION['SESS_USERNAME']) { for($i=1;$i<=10;$i++) { echo "<a href='ratestory.php?id=" . $validid . "&rating=" . $i . "'>" . $i . "</a> "; } } else { echo "To vote, please <a href='userlogin.php'>login</a>."; } echo "</p>"; require("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/49000-solved-whats-wrong-with-my-code-should-be-simple/ Share on other sites More sharing options...
veridicus Posted April 27, 2007 Share Posted April 27, 2007 What are the first one or two errors (including line numbers)? It'll help us find the problem. Quote Link to comment https://forums.phpfreaks.com/topic/49000-solved-whats-wrong-with-my-code-should-be-simple/#findComment-240015 Share on other sites More sharing options...
Trium918 Posted April 27, 2007 Share Posted April 27, 2007 Question: What is the name of the book and what does this code suppose to do? Quote Link to comment https://forums.phpfreaks.com/topic/49000-solved-whats-wrong-with-my-code-should-be-simple/#findComment-240016 Share on other sites More sharing options...
mr_badger Posted April 27, 2007 Author Share Posted April 27, 2007 Parse error: parse error, unexpected ')' in C:\file\file\file\viewstory.php on line 38. The book is called practical php and mysql 'building eight dynamic web applications'. this code is for a news website and this code is viewstory.php Quote Link to comment https://forums.phpfreaks.com/topic/49000-solved-whats-wrong-with-my-code-should-be-simple/#findComment-240062 Share on other sites More sharing options...
sanfly Posted April 27, 2007 Share Posted April 27, 2007 Your problem is here if($a%5 == 0 && $a%10 != ) { you need to have something after the != if you want it to equal nothing, put two apostrophes eg if($a%5 == 0 && $a%10 != '') { Quote Link to comment https://forums.phpfreaks.com/topic/49000-solved-whats-wrong-with-my-code-should-be-simple/#findComment-240065 Share on other sites More sharing options...
per1os Posted April 27, 2007 Share Posted April 27, 2007 It never siezes to amaze me how books do not teach proper coding strategies. <?php require("config.php"); require("functions.php"); if(pf_check_number($_GET['id'])) { $validid = $_GET['id']; } else { header("Location: " . $config_basedir); } require("header.php"); $sql = "SELECT * FROM stories WHERE id = " . $validid . ";"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo "<h1>" . $row['subject'] . "</h1>"; echo date("D jS F Y g.iA" , strtotime($row['dateposted'])) . "<br />"; echo nl2br($row['body']); $avgsql = "SELECT COUNT(id) AS number, AVG(rating)AS avg FROM ratings WHERE story_id = " .$validid . ";"; $avgresult = mysql_query($avgsql); $avgrow = mysql_fetch_assoc($avgresult); echo "<p>"; echo "<strong>Rating</strong> "; if($avgrow['number'] == 0) { echo "No ratings"; } else { $a = (round($avgrow['avg'] * 2) / 2) . "<br />"; $a *= 10; if(($a%5) == 0 && ($a%10) != ) { // Does not equal WHAT????? $range = ($a / 10) - 0.5; } else { $range = $a / 10; } for($i=0;$i<$range;$i++) { echo "<img src='" . $config_basedir . "news/full.gif'>"; } if(($a%5) == 0 && ($a%10) ! = ) { // Does not equal WHAT???? echo "<img src='" . $config_basedir . "news/half.gif'>"; } $a = $a / 10; $remain = 10 - $a; for($range=0;$range<$remain;$range++) { echo "<img src='" . $config_basedir . "news/off.gif'>"; } } echo "<br />"; echo "<strong>Rate this story</strong>: "; if($_SESSION['SESS_USERNAME']) { for($i=1;$i<=10;$i++) { echo "<a href='ratestory.php?id=" . $validid . "&rating=" . $i . "'>" . $i . "</a> "; } } else { echo "To vote, please <a href='userlogin.php'>login</a>."; } echo "</p>"; require("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/49000-solved-whats-wrong-with-my-code-should-be-simple/#findComment-240066 Share on other sites More sharing options...
mr_badger Posted April 27, 2007 Author Share Posted April 27, 2007 Thankyou for your help, no more errors. Quote Link to comment https://forums.phpfreaks.com/topic/49000-solved-whats-wrong-with-my-code-should-be-simple/#findComment-240132 Share on other sites More sharing options...
MadTechie Posted April 27, 2007 Share Posted April 27, 2007 please click solved Quote Link to comment https://forums.phpfreaks.com/topic/49000-solved-whats-wrong-with-my-code-should-be-simple/#findComment-240133 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.