xcandiottix Posted March 11, 2010 Share Posted March 11, 2010 Okay, So I have a page that pulls an image up and below people can make comments. I've set it to allow 10 responses before a page 2 for comments is created. Right now, the first page works perfectly. After 10 comments if I click 'Next Page' I get a page without the picture [not a big deal], WITH the comment box, WITHOUT the second page of comments. Page 2 says it's on page 1 of 0 but the web address shows php?pagenum2. What's going wrong here? I thinkkk that since the 1st page is a php page that was generated from another php page that the 3rd php page is getting some code interference. For example, for this page to load the picture it gets the whichchart variable. I think when I click next whichchart is no longer available. ex: Browse page shows: abc.jpg [contained in the mysql db as "abc.jpg" in column 'Chart'] on clicking the image var whichchart is set to "abc.jpg" The new page (code below) loads with abc.jpg fullsize then gets information about the pic from the DB uploads. DB comments is then access and the first 10 are printed on screen along with "next page?\" for more comments Clicking on 'next page' shows my issues. If I set $var1 = GET['whichchart'] and echo that, I'll get abc.jpeg on the working page but on the comments page 2 i'll get nothing. Can anyone tackle this beast? <html> </html> <style type="text/css"> <!-- .Arial { font-family: Arial, Helvetica, sans-serif; } .Arial { font-family: Arial, Helvetica, sans-serif; } --> </style> <?php if (isset($_GET['whichchart'])) { $con = mysql_connect("abc.com","DB","PW"); mysql_select_db("DB", $con); $sql = "SELECT Chart, Name, Engine, Model, About, Horsepower, Torque, IM, Social FROM uploads WHERE Chart = '{$_GET['whichchart']}'"; $result = mysql_query($sql); if ($result) { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); echo "<center>"; echo '<img src="http://www.dyno-charts.com/upload/'.$row['Chart'].'"'.'"width="800" height="600"'.' "/><br>'; echo '<span class="Arial">'; echo "Submitted by: {$row['Name']}"; echo "<br>"; echo "Engine: {$row['Engine']}"; echo "<br>"; echo "Model: {$row['Model']}"; echo "<br>"; echo "About: {$row['About']}"; echo "<br>"; echo "Horsepower: {$row['Horsepower']}"; echo "<br>"; echo "Torque: {$row['Torque']}"; echo "<br>"; echo "Contact: {$row['IM']}"; echo "<br>"; echo "Homepage: {$row['Social']}"; echo "<br>"; echo "</span>"; } else { echo "No user found by that name"; } } } // Comment Box Start echo '<html> </style> <p> </p> <table width="100%" border="0"> <tr> <td width="33%"> </td> <td width="33%"><center><form action="commenttest.php" method="post" enctype="multipart/form-data"> <p class="default"> <input name="UserName" type="text" onFocus="if(this.value==this.defaultValue){this.value='."''".';}" value="Your Name" size="47" /> <br> <textarea name="Comment" cols="37" rows="10" onFocus="if(this.value==this.defaultValue){this.value='."''".';}">Commment: 150 chacters max</textarea> <input type="hidden" name="whichchart" value="'.$row['Chart'].'"> <br><br><input type="submit" name="submit" value="Add Your Comment" /></p> </form></center></td> <td width="33%"> </td> </tr> </table> </body> </html></p>'; if (!(isset($pagenum))) { $pagenum = 1; } $con = mysql_connect("abc.com","DB","PW"); mysql_select_db("DB", $con); $data = mysql_query("SELECT * FROM comments WHERE WhichChart = '{$_GET['whichchart']}' " ) or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 10; $last = ceil($rows/$page_rows); $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data = mysql_query("SELECT * FROM comments WHERE WhichChart = '{$_GET['whichchart']}' $max") or die(mysql_error()); $rows = mysql_num_rows($data); while($info = mysql_fetch_array($data)) { echo "<hr><center>"; echo '<span class="Arial">'; echo '<table width="50%" border="0">'; echo "<tr>"; echo '<th width="25%" scope="col">' . $info['UserName'] . ' posted: ' . '<br>'. $info["Comment"] . '</th>'; echo "</tr>"; echo "</table>"; } echo "<p>"; echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'><<-First</a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'><-Previous</a> "; } if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/ Share on other sites More sharing options...
jdorma0 Posted March 11, 2010 Share Posted March 11, 2010 Your form is using method=post. Why are you using $_GET['whichchart']? Should be $_POST['whichchart'] or change your form to method=get. That's the main thing I noticed. Got a live URL? Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/#findComment-1024578 Share on other sites More sharing options...
xcandiottix Posted March 11, 2010 Author Share Posted March 11, 2010 http://www.dyno-charts.com .. go to browse then pick the chart submitted by "Heather" .. that one has 31 comments. Maybe that will answer your question? Feel free to try and post a comment as I can just delete it out Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/#findComment-1024581 Share on other sites More sharing options...
xcandiottix Posted March 11, 2010 Author Share Posted March 11, 2010 on the browse page, each of the little images are linked to their own site via: <a href="/chart.php?whichchart=' . $info["Chart"] . '"> On the page code above, I GET whichchart so the correctly corresponding image is loaded up. Hope that makes sense. Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/#findComment-1024583 Share on other sites More sharing options...
jdorma0 Posted March 11, 2010 Share Posted March 11, 2010 First of all, change this if (!(isset($pagenum))) { $pagenum = 1; } to this if (!(isset($_GET['pagenum']))) { $pagenum = 1; }else{ $pagenum = $_GET['pagenum']; } Let me know when it's uploaded, I'll check it out again. Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/#findComment-1024585 Share on other sites More sharing options...
xcandiottix Posted March 11, 2010 Author Share Posted March 11, 2010 done Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/#findComment-1024586 Share on other sites More sharing options...
jdorma0 Posted March 11, 2010 Share Posted March 11, 2010 That fixed the biggest problem. Now change the end of your script to this: if ($pagenum == 1) { } else { $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&whichchart=".$_GET['whichchart']."'><<-First</a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&whichchart=".$_GET['whichchart']."'><-Previous</a> "; } if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&whichchart=".$_GET['whichchart']."'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&whichchart=".$_GET['whichchart']."'>Last ->></a> "; } ?> in place of if ($pagenum == 1) { } else { $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'><<-First</a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'><-Previous</a> "; } if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/#findComment-1024588 Share on other sites More sharing options...
xcandiottix Posted March 11, 2010 Author Share Posted March 11, 2010 yesss... yes yes yes.... best part is that makes total sense. It works perfectly! I owe you a drink Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/#findComment-1024589 Share on other sites More sharing options...
jdorma0 Posted March 11, 2010 Share Posted March 11, 2010 yesss... yes yes yes.... best part is that makes total sense. It works perfectly! I owe you a drink Great! Yeah, your whichchart variable wasn't being defined once you actually went to a chart.. it attempted to load comments, but it didn't have a chart to pull them from. And the first issue was that your script wasn't getting the variable because it wasn't defined with $_GET. But but modifying like I suggested you corrected those two problems and it's working now, so congrats! Link to comment https://forums.phpfreaks.com/topic/194862-completely-stuck/#findComment-1024594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.