Jump to content

Ashoar

Members
  • Posts

    214
  • Joined

  • Last visited

    Never

Everything posted by Ashoar

  1. I am using pagination for the first time and have run into a few errors. I have used the tutorial from here on php freaks. Here is the code: <?php include "config.php"; $forumid=$_GET[board]; print "<link rel='stylesheet' href='style.css' type='text/css'>"; print "<A href='post.php?board=$forumid'>New Topic</a><br>"; $page = 1; $size = 10; if (isset($_GET['page'])){ $page = (int) $_GET['page']; } print " <table class='maintable'> <tr class='headline'><td width=15%>Topic</td> <td width=5%>Author</td><td width=5%>Replies</td> <td width=20%>Last reply</td> </tr> "; $sql = "SELECT COUNT(*) FROM post_reply"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; $info="SELECT * from post_reply WHERE board='$forumid' AND parentid='0' ORDER BY lastrepliedto DESC LIMIT $offset, $rowsperpage"; $info2=mysql_query($info) or die(mysql_error()); while($info3=mysql_fetch_array($info2)) { $info3[title]=strip_tags($info3[title]); $info3[author]=strip_tags($info3[author]); print " <tr class='mainrow'><td><A href='message.php?id=$info3[postid]'>$info3[title]</a></td> <td><center><A href='member_profile.php?username=$info3[author]'>$info3[author]</a></center></td> <td><center>$info3[numreplies]</center></td> <td>$info3[showtime]<br>Last post by <A href='member_profile.php?username=$info3[lastposter]'>$info3[lastposter]</a></td> </tr> "; } /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ print "</table>"; ?> Here are the errors: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource (line 35) Fatal error: SQL (line 35) What am i doing wrong?
  2. That did the trick. Thank you again Mark.
  3. No i am actually fetching it straight from the database, seeing as the image tags are already on the image when they are entered into the input field. "$postcount3[signature]" I couldn't do it like that as if a user wanted to use text instead of an image that would put img tags around their text.
  4. Im sure you would of noticed that mywebsite.com is just a dummy domain in the script i added. My proper domain is being added to the front of the image URL and the <img> tags don't work. I wanted to know if there was a way of stopping the web url being added to the front of the image.
  5. http://mywebsite.com/forum/%5C%22http://i43.tinypic.com/ip0eag.jpg%5C%22
  6. I have a small area where users can add an image tags for their signature images: e.g: <img src="image url here"> This is done through a forum, you can add whatever you want, text, links or images. There is one problem. When i add an image into this form to test it, when i echo it after fetching it from the database it does not show up, instead it just has the liee broken image icon. What happens is that the code adds my website address to the beginning of the code and then the img tag does not work. Here is the code to add the image: <?php session_start(); if($_SESSION['s_logged_n'] == 'true'){ $username = $_SESSION['s_username']; include 'config.php'; if(isset($_POST['submit'])) { $sig = addslashes(trim($_POST['sig'])); $addsig="Update Users set signature='$signature' WHERE Username=$username"; } ?> <html> <head> <title>Change your signature</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <div id="head">Signature</div> <br> <div id="main"> <p>Change your signature</p> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr class="firstRow"> <td width="50%">Signature</td> <td width="50%"><input name="sig" type="text" class="textBox" id="sig"></td> </tr> <tr class="firstRow"> <td>Submit</td> <td><input name="submit" type="submit" class="textBox" value="Submit"></td> </tr> </table> </form> </div> </div> </body> </html> <? } mysql_close($l); ?> And i use this to fetch and output: $postcount="SELECT * from Users where Username='$username'"; $postcount2=mysql_query($postcount) or die("Could not get postcount"); $postcount3=mysql_fetch_array($postcount2); The output is then just added as an echo or a print. e.g: $postcount3[signature] If it is just text, this works just fine, but it won't work for images. Any solution?
  7. Thank you for clearing that up Mark. I have been playing around with it for a while but can't manage to get it in an order that will work. If there is anyone that knows what order this does need to be in based on Mark's post above i would like to hear
  8. Ah simple mistake. It works perfectly now Thank you.
  9. No joy, still displays the MYSQL error "Could not get postcount".
  10. That just gives an error when outputting. "Could not get postcount"
  11. Yes the database's are all included above. It all works, except instead of displaying the post count it shows an "S". So there is no error that displays, it just shows an s instead of post count. I know that the posts work because i have them displayed in the users profile, but that was easy as all i needed to do was fetch the user name from the URL of the users profile.
  12. I have this small piece of code here that i cannot get to work properly. I have 2 tables that i need to retrieve information from. The first is a table that holds posts and replies while the second is the user data holding all the membership details. What i need to do is fetch all of the post information along with the author of the post so that i can display it. This works perfectly. I then need to grab the post count of the user who posted so i can display it. I need to somehow fetch the postcount of the username where username is the same as the author of the post. I tried adding variable into the MYSQL query but it would not work and just output an "S" next to posts. Here is the piece of code: $gettopic="SELECT * from post_reply where postid='$id'"; $gettopic2=mysql_query($gettopic) or die("Could not get topic"); $gettopic3=mysql_fetch_array($gettopic2); $postcount="SELECT postcount from Users where Username=$gettopic[author]"; print "<tr class='mainrow'><td valign='top'><p><A href='member_profile.php?username=$gettopic3[author]'>$gettopic3[author]</a></p><p>Posts: $postcount[postcount]</p></td><td vakign='top'>Last replied to at $gettopic3[showtime]<br><hr>"; Anyone know how i can do this?
  13. The parent id doesn't effect the boards, that is just to know whether a post is a reply or new thread. The reason that is in there is so that i can get the number of threads for that board. As i said it should have something to do with the order of the query, but i am not to sure as this query is based of Oracle, which Mark from here helped with. He said that the order may need to change to this: SELECT f.forum_name, f.forum_desc, f.board, SUM(p.post) AS threads, MAX(p.lastpostat) AS lastpostat, MAX(p.lastpostid) AS lastpostid FROM forums f INNER JOIN post_reply p ON p.board=f.board AND p.parentid='0' GROUP BY f.forum_name, f.forum_desc, f.board But that did not help either.
  14. Last night i had assistance with merging 2 database query's into one so that i could get specific post information about specific boards. Before doing so, the original query that fetched all of the boards worked as an array so that it would show all boards, the other query grabs post information for the board. Since merging the 2 query's the code will only show the boards on the main page that has posts in it, instead of all of them. Here is the piece of code: <?php include 'config.php'; print "<link rel='stylesheet' href='style.css' type='text/css'>"; print "<table class='maintable'>"; print "<tr class='headline'><td width=5%>Status</td><td width=65%>Board</td><td width=5%>Posts</td><td width=25%>Last post</td></tr>"; $boards = mysql_query("SELECT f.forum_name, f.forum_desc, f.board, COUNT(p.post) AS threads, MAX(p.showtime) AS showtime, MAX(p.lastposter) AS lastposter FROM forums f, post_reply p WHERE p.board=f.board AND p.parentid='0' GROUP BY f.forum_name, f.forum_desc, f.board") or die(mysql_error()); $boardCount = mysql_num_rows($boards); for($count = 1; $count <= $boardCount; $count++) { $board = mysql_fetch_array($boards); echo "<tr class='mainrow'><td><center>On</center><td><A href='board.php?board=".$board['board']."'>".$board['forum_name']."</a><p>".$board['forum_desc']."</p></td><td><center>".$board['threads']."</center></td><td>On ".$board['showtime']."<br><br>By <A href='member_profile.php?username=$board[lastposter]'>$board[lastposter]</a></a></td></tr>"; } print "</table>"; ?> That is the code. SO the array there is only showing boards on the main page that have posts in it. Anyone see a way to fix it? Apparently it may be the structure of the query. Thanks.
  15. I just added a pagination section to my current code by i have a few errors. It is set to 10 posts per page. After reaching over 10 posts the link for the 2nd page is then displayed, except no posts show up on the second page, no matter how many you post. Here is the code <?php include "config.php"; $forumid=$_GET[board]; print "<link rel='stylesheet' href='style.css' type='text/css'>"; print "<A href='post.php?board=$forumid'>New Topic</a>"; $postnumber = 10; if(!isset($_GET['page'])) { $page = 1;}else { $page = (int)$_GET['page'];} $from = (($page * $postnumber) - $postnumber); print " <table class='maintable'> <tr class='headline'><td width=15%>Topic</td> <td width=5%>Author</td><td width=5%>Replies</td> <td width=20%>Last reply</td> </tr> "; $info="SELECT * from post_reply WHERE board='$forumid' AND parentid='0' ORDER BY lastrepliedto DESC LIMIT $from, $postnumber"; $info2=mysql_query($info) or die(mysql_error()); while($info3=mysql_fetch_array($info2)) { $info3[title]=strip_tags($info3[title]); $info3[author]=strip_tags($info3[author]); print " <tr class='mainrow'><td><A href='message.php?id=$info3[postid]'>$info3[title]</a></td> <td><A href='member_profile.php?username=$info3[author]'>$info3[author]</a></td> <td>$info3[numreplies]</td> <td>$info3[showtime]<br>Last post by <A href='member_profile.php?username=$info3[lastposter]'>$info3[lastposter]</a></td> </tr> "; } print "</table>"; $results = mysql_fetch_array(mysql_query("SELECT COUNT(*) as num FROM post_reply where parentid='0'")); $pages = ceil($results['num'] / $postnumber);if ($page > 1) { $prev = ($page - 1); echo "<a href=\"index.php?page=$prev\"><< Newer</a> "; }for($i = 1; $i <= $pages; $i++) { if ($page == $i) { echo "$i "; } else { echo "<A href='board.php?board=$forumid?page=$i>$i</a> "; }} ?> What have i done wrong? Edit: If i make a post while on the 2nd page, that post then gets added to the second page, but i want it to add to the first page.
  16. Also, i tried to change the query around as you had suggested but it still doesn't display all of the boards.
  17. Yes it is the only one with posts inside of it. I am trying to fix that at the moment, but once again it is a bit troubeling because i have never used or seen a MYSQL query being used like such. Also a question for you Mark. Once again this is due to the query type. Am i able to swap the parentid='0' around so that it will only effect the thread count? It comes after the last post as well, so the last post will be the last thread made instead of the last reply. I suspect all i had to do was move the parent id in front of the thread part of the query, but that did not work.
  18. Thanks. One more thing. Using this code though has re-moved my board array, so now only the first board in the MYSQL database is appearing.
  19. Output: Test Board This is a test board. All test posts will be made here to check and make sure everything works. 1 timeofposthere lastpost here Seems that may have worked, there is only 1 post in that board. I will add another to see if it updates. EDIT: That seems to have done the trick, it works perfectly now. Thank you for the help. I will take a look through the coding you provided and work through what i needed to change in my original coding.
  20. Output: Test Board This is a test board. All test posts will be made here to check and make sure everything works. 0 timeofposthere lastpost here So it is still a matter of trying to get some sort of connection between the board id so that the posts for it can display.
  21. Just noticed the php file didn't update wholey and left out half of the code. Once again: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
  22. Output: <= $boardCount; $count++) { $board = mysql_fetch_array($boards); print "$board['forum_name'] $board['forum_desc'] $board['threads']timeofposthere lastpost here"; } ?>
  23. And the parse error: "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING" I wouldn't know how to fix that, i have never merged queries like that before.
  24. I may not have given enough info. I want to select the amount of posts that have been made in each board, just like on a a normal forum, the front mage that has Topics and Replies. When making a post, all information is stored and there is a row on the table for the forumid where the id of the forum the post was made in is saved. What i am trying to do is get the total of all the posts made in each board. I need to try and find a way of matching the posts up with the id of the board on the main page. I thought maybe "$name[board]" would get the name of the board that the script is on and get the posts for it. Maybe there is another way of doing so? The posts are saved to a row called forumid and the board id is a row called "Board"
  25. The output: Query: SELECT post FROM post_reply WHERE board='' AND parentid='0' That's not right
×
×
  • 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.