Jump to content

Completely Stuck.


xcandiottix

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

yesss... yes yes yes.... best part is that makes total sense. It works perfectly!

 

I owe you a drink  :D

 

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! :D

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.