mike12255 Posted March 7, 2009 Share Posted March 7, 2009 I know about 100 times more php then html because i didnt really learn html. But i got the following code that needs rearranged. if you look at (www.stayner.ca/TEST/) about one quarter the way down the page, near the "Questions Answers" part there are numbers ( currently 1 2 3 4) problem is 1 is spaced super far from the rest of the numbers I have located the problem to the part that displays: "Pages 1 2 3 4" is apart of the "Questions Answers" table so i need to rearrange this and create a new table for the numbers. But i dont really know php and was hoping somone could do it for me?: <td height="226" colspan="5" rowspan="4" valign="top" background="images/index-3_13.gif"><br> <table width="467" border="0" align="center" cellpadding="5" cellspacing="5"> <tr> <td width="366" bgcolor="#E6E6E6"><div align="left"><strong>Question:</strong></div></td> <td width="85" bgcolor="#E6E6E6"><div align="center"><strong>Answered?</strong></div></td> </tr> <tr><?php if(isset($_GET['page'])) { $page = $_GET['page']; }else{ $page = 1; } $tolimit = 4; $showend = $page * $tolimit; $showstart = $showend - 4; //Get all Topics (Parentid = 0) $getthreads="SELECT * FROM forumtutorial_posts WHERE parentid ='0' ORDER BY parentid DESC LIMIT $showstart, $tolimit"; $findamount = mysql_query($getthreads) or die (mysql_error());//for showing the four newest posts //the code below will be used to determine how many pages to show $query= "SELECT COUNT(*) as cnt FROM forumtutorial_posts";//efficant way of counting rows $query2 = mysql_query($query) or die (mysql_error());//because we dont want to call it yet we set it to another variable $row = mysql_fetch_array($query2); $num_rows=$row['cnt']; $pagestoshow = floor($num_rows/$tolimit); //grab all the content while($r=mysql_fetch_array($findamount)) { //the format is $variable = $r["nameofmysqlcolumn"]; - makes it easier to call later CAUSE IM LAZY!! $answer=$r["answered"]; $title=$r["title"]; $id=$r["postid"]; if ($answer == 0){ $answer = "no"; }else{ $answer = "yes"; } ?> <td bgcolor="#FFFFFF"><div align="left" class="style17"><a href="showquestion.php?page=<?=$id?>"><?=$title?></a></div></td> <td bgcolor="#FFFFFF"><div align="center" class="style17"><?=$answer?></div></td> </tr> <?php } print "<td>Page: </td>"; for ($i = 1; $i <= $pagestoshow; $i++){ print "<td><a href= 'index.php?page=$i'> $i </a></td>"; } ?> </tr> <tr> <?php if ($session->logged_in){?> <td bgcolor="#FFFFFF">Have a question you would like answered?, <a href="questionform.php">Click Here</a></td> <?php }else{?> <td bgcolor="#FFFFFF">You must be logged in to ask a question, to log in <a href="login.php">Click Here</a></td> <?php } ?> <td bgcolor="#FFFFFF"><div align="center">N/A</div></td> </tr> </table> <strong><br> </strong></td> </tr> <tr> Quote Link to comment Share on other sites More sharing options...
ejaboneta Posted March 7, 2009 Share Posted March 7, 2009 Your code was pretty confusing so I tried to re-organize it. I hope it works, I would have tested it but I can't use your database and I dont feel like setting up a test. I used a couple functions so that the php doesn't have to be all mixed up in the html. <?php ### GET PAGE ### if(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $tolimit = 4; $showend = $page * $tolimit; $showstart = $showend - 4; ### GET TOPICS ### $getthreads="SELECT * FROM forumtutorial_posts WHERE parentid ='0' ORDER BY parentid DESC LIMIT $showstart, $tolimit"; $findamount = mysql_query($getthreads) or die (mysql_error());//for showing the four newest posts ### DETERMINE PAGES ### function pager() { $query= "SELECT COUNT(*) as cnt FROM forumtutorial_posts";//efficant way of counting rows $query2 = mysql_query($query) or die (mysql_error());//because we dont want to call it yet we set it to another variable $row = mysql_fetch_array($query2); $num_rows=$row['cnt']; $pagestoshow = floor($num_rows/$tolimit); for ($i = 1; $i <= $pagestoshow; $i++){ print "<a href='index.php?page=$i'> $i </a>"; } } ### GRAB CONTENT ### function grabContent($r) { $answer=$r["answered"]; $title=$r["title"]; $id=$r["postid"]; if ($answer == 0){ $answer = "no"; } else { $answer = "yes"; } print '<td bgcolor="#FFFFFF"><div align="left" class="style17"><a href="showquestion.php?page=' . $id . '">' . $title . '</a></div></td>'; print '<td bgcolor="#FFFFFF"><div align="center" class="style17">' . $answer . '</div></td>'; } ?> <table width="467" border="0" align="center" cellpadding="5" cellspacing="5"> <tr> <td width="366" bgcolor="#E6E6E6"><div align="left"><strong>Question:</strong></div></td> <td width="85" bgcolor="#E6E6E6"><div align="center"><strong>Answered?</strong></div></td> </tr> <tr> <?php while($r=mysql_fetch_array($findamount)) { grabContent($r); } ?> </tr> <tr> <td>Page: </td> <td><?php pager(); ?> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan="2"> <?php if ($session->logged_in){ print 'Have a question you would like answered?, <a href="questionform.php">Click Here</a>'; } else { print 'You must be logged in to ask a question, to log in <a href="login.php">Click Here</a>'; } ?> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
mike12255 Posted March 7, 2009 Author Share Posted March 7, 2009 well you certianally cleaned up my code, however if you look at (http://www.stayner.ca/TEST/index2.php the "1" is still far away from the 2. Quote Link to comment Share on other sites More sharing options...
ejaboneta Posted March 7, 2009 Share Posted March 7, 2009 Try this. I forgot the <tr></tr> tags for the questions... <?php ### GET PAGE ### if(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $tolimit = 4; $showend = $page * $tolimit; $showstart = $showend - 4; ### GET TOPICS ### $getthreads="SELECT * FROM forumtutorial_posts WHERE parentid ='0' ORDER BY parentid DESC LIMIT $showstart, $tolimit"; $findamount = mysql_query($getthreads) or die (mysql_error());//for showing the four newest posts ### DETERMINE PAGES ### function pager() { $query= "SELECT COUNT(*) as cnt FROM forumtutorial_posts";//efficant way of counting rows $query2 = mysql_query($query) or die (mysql_error());//because we dont want to call it yet we set it to another variable $row = mysql_fetch_array($query2); $num_rows=$row['cnt']; $pagestoshow = floor($num_rows/$tolimit); for ($i = 1; $i <= $pagestoshow; $i++){ print "<a href='index.php?page=$i'> $i </a>"; } } ### GRAB CONTENT ### function grabContent($r) { $answer=$r["answered"]; $title=$r["title"]; $id=$r["postid"]; if ($answer == 0){ $answer = "no"; } else { $answer = "yes"; } print '<tr>'; print '<td bgcolor="#FFFFFF"><div align="left" class="style17"><a href="showquestion.php?page=' . $id . '">' . $title . '</a></div></td>'; print '<td bgcolor="#FFFFFF"><div align="center" class="style17">' . $answer . '</div></td>'; print '</tr>'; } ?> <table width="467" border="0" align="center" cellpadding="5" cellspacing="5"> <tr> <td width="366" bgcolor="#E6E6E6"><div align="left"><strong>Question:</strong></div></td> <td width="85" bgcolor="#E6E6E6"><div align="center"><strong>Answered?</strong></div></td> </tr> <?php while($r=mysql_fetch_array($findamount)) { grabContent($r); } ?> <tr> <td>Page: </td> <td><?php pager(); ?> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan="2"> <?php if ($session->logged_in){ print 'Have a question you would like answered?, <a href="questionform.php">Click Here</a>'; } else { print 'You must be logged in to ask a question, to log in <a href="login.php">Click Here</a>'; } ?> </td> </tr> </table> 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.