Jump to content

nonspacial

Members
  • Posts

    13
  • Joined

  • Last visited

nonspacial's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. a few more hours and i am here: function blogs ($dbc, $pg) {// blogs retrieved and sorted from DB //setup user variable $user[]= $q ="SELECT * FROM users WHERE id= '$_COOKIE[userid]' LIMIT 1"; $r = mysqli_query ($dbc, $q); if (mysqli_num_rows ($r) >0) { $user = mysqli_fetch_assoc($r); }; $q="SELECT * FROM abstrktmainblogs f INNER JOIN abstrktmainblogs s ON f.title = s.title WHERE f.page_id ='$pg' AND s.blogcomment < f.blogcomment ORDER BY f.date_posted, f.title, f.blogcomment DESC"; $r = mysqli_query($dbc, $q); while ($blogPosts= mysqli_fetch_assoc ($r)) { // blogs displayed in table date descending while loop 1 foreach ($blogPosts as $value) { echo'<div id="blogPosts"> <table> <tr><h3>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</h3></tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table> <br></br>'; //Comments retrieve and display $q="SELECT * FROM abstrktmainblogs f INNER JOIN abstrktmainblogs s ON f.title = s.title WHERE f.page_id ='$pg' AND s.blogcomment > f.blogcomment AND f.title=s.title ORDER BY f.title, f.date_posted, f.blogcomment DESC"; $r = mysqli_query($dbc, $q); while ($blogComments=mysqli_fetch_assoc ($r)) { //comments while loop 2 if ($blogPosts['title'] == $blogComments['title']) { //if statement to create comments div echo '<div id="blogComments" > <table> <tr><h4>'.$blogComments['title'].' by '.$blogComments['username'].' on '.$blogComments['date_posted'].'</h4></tr> <br></br> <tr>'.$blogComments['post'].'</tr> </table></div> <br></br>'; } //End comments loop 2 } //End if statement if (isset($_COOKIE['userid'])) { //comment posting ability if logged in (display form) echo '<div id="respond"> <form method="post" autocomplete="on"> <label for="comment" class="required">Leave us a comment: </label> <textarea name="comment" id="comment" rows="1" width="90%" tabindex="4" required="required"></textarea> <input type="hidden" name="blogcomment" value="1" id="blogcomment" /><br></br> <input type="hidden" name="title" value="'.$blogPosts['title'].'" id="title" /> <input type="hidden" name="userid" value="'.$user ['username'].'" id="userid" /> <input name="submit" type="submit" value="Post Comment" id="submit" /> </form></div>'; //print_r($_REQUEST); if (isset ($_POST['Post'])==1) { // actions to take when post is made $q ="INSERT INTO abstrktmainblogs (blogcomment, page_id, title, post, username, date_posted) VALUES ( '$_POST[blogcomment]','$_GET ','$_POST[title]','$_POST[post]','$_POST[userid]', now()"; $r=mysqli_query($dbc, $q); } //end Post actions } //end display comment form } //END foreach } //end while loop 1 } //end blogs function echo '</div>' // end post div What this now does is display the 1st post with it's children 7 times. if i remove the foreach it only displays the 1st post once so where am i losing the 2nd Post and it's children?
  2. here is the queried table: id blogcomment page_id title post username date_posted id blogcomment page_id title post username date_posted 1 0 2 testing testing 123 testing post display Robbie 2013-01-12 00:00:00 3 1 2 testing comment 1 Robbie 2013-01-25 22:35:00 1 0 2 testing testing 123 testing post display Robbie 2013-01-12 00:00:00 5 1 2 testing comment 3 Robbie 2013-01-26 06:31:00 2 0 2 testing 2 testing testing work mutha fucker work Robbie 2013-01-12 00:00:20 4 1 2 testing 2 comment 2 Robbie 2013-01-25 22:35:00
  3. i think i have cracked the query but it's now only showing the comments which is effectively the right side of the table here is the query: $q="SELECT * FROM abstrktmainblogs f INNER JOIN abstrktmainblogs s ON f.title = s.titleWHERE f.blogcomment < s.blogcomment ORDER BY f.title, f.date_posted, f.blogcomment DESC"; i now need to find a way to make the while loop table display the main article and comments cascading from eachother: $q="SELECT * FROM abstrktmainblogs f INNER JOIN abstrktmainblogs s ON f.title = s.title WHERE f.blogcomment < s.blogcomment ORDER BY f.title, f.date_posted, f.blogcomment DESC"; $r = mysqli_query($dbc, $q); while ($blogPosts= mysqli_fetch_assoc ($r)) { // blogs displayed in table date descending echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { //comment posting ability if logged in (display form) echo '<div id="respond"> <form method="post" autocomplete="on"> <label for="comment" class="required">Leave us a comment: </label> <textarea name="comment" id="comment" rows="1" width="90%" tabindex="4" required="required"></textarea> <input type="hidden" name="blogcomment" value="1" id="blogcomment" /><br></br> <input type="hidden" name="title" value="'.$blogPosts['title'].'" id="title" /> <input type="hidden" name="userid" value="'.$user ['username'].'" id="userid" /> <input name="submit" type="submit" value="Post Comment" id="submit" /> </form></div>'; Dumping data for table abstrktmainblogs id blogcomment page_id title post username date_posted id blogcomment page_id title post username date_posted 1 0 2 testing testing 123 testing post display Robbie 2013-01-12 00:00:00 3 1 2 testing comment 1 Robbie 2013-01-25 22:35:00 1 0 2 testing testing 123 testing post display Robbie 2013-01-12 00:00:00 5 1 2 testing comment 3 Robbie 2013-01-26 06:31:00 2 0 2 testing 2 testing testing work mutha fucker work Robbie 2013-01-12 00:00:20 4 1 2 testing 2 comment 2 Robbie 2013-01-25 22:35:00
  4. this is the closest i've got and it produces triplicates in the query if i use < or > as it says in the manual i'm reading it comes back as no rows? $q="SELECT * FROM abstrktmainblogs f INNER JOIN abstrktmainblogs s ON f.title = s.title WHERE f.title = s.title ORDER BY f.title, f.date_posted, f.blogcomment DESC LIMIT 0 , 30"
  5. taking your advice i'm getting no rows from this in phpmyadmin or my site i need all rows to be sorted by title and then by blogcomment so that it will go 0,1,1,1, 0,1,1,1 where 0 is main post and 1 is comment... page_id is also important as it's how different pages are referenced for each post SELECT * FROM abstrktmainblogs f INNER JOIN abstrktmainblogs s ON f.title = s.title WHERE page_id=2 ORDER BY 'date_posted' DESC
  6. it seems to be working i get different titles from different boxes in my print out but i'm trying to call a function as a value paramenter and it's now printing the function name in $_POST array but echoing the function above Your message: which is odd as it's a hidden field?
  7. yes that's what i'm doing now with others like username and title but i'm still unsure of how to get the id of the original post... how does the textarea box know it is different and associated with said post id? currently i have 2 main posts and either field provides both with the same print on request ie both posts would display the comment.
  8. Hello people, can someone help me to make this function work how i want it. so it's a bit butchered from a tutorial and code i had already used before but i'm confusing myself with how to associate a posting with the original post that it is being commented on and therefore to make the number populate into the table. my idea is to use the id of the original post in the table as the blogcomment column in the table so the auto incremented id can associate all comments with it and all completely new posts that are put up by admin have this value as 0. i have a working DB connection in $dbc and a working page association in $pg that way i can associate material with different areas of the site. if you look at the last if statement you will see my table structure in the insert into query. i am stuck here without an association of the actual box to the original Post; where i get this value from or how i get it from the table directly i.e. the id. i also have a working cookie system that i have saved userid and usertype so i can retrieve usernames from the users table directly. i obviously need to populate every column in the table for new posts and i need to somehow retrieve them and place them with the original post they refer to... it's hurting my head atm . thanks for your help and input. function blogs ($dbc, $pg) {// blogs retrieved and sorted from DB $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); while ($blogPosts= mysqli_fetch_assoc ($r)) { // blogs displayed in table date descending echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { //comment posting ability if logged in (display form) echo '<div id="respond"> <form method="post" autocomplete="on"> <label for="comment" class="required">Your message: </label> <textarea name="comment" id="comment" rows="1" width="90%" tabindex="4" required="required"></textarea> <input type="hidden" name="comment_post_ID" value="1" id="comment_post_ID" /><br></br> <input name="submit" type="submit" value="Post" /> </form></div>'; print_r($_REQUEST); if (isset ($_POST['Post'])==1) { // actions to take when post is made $q="SELECT * FROM `abstrktmainblogs` WHERE `blogcomment` = 0"; $r = mysqli_query($dbc, $q); $q ="INSERT INTO `abstrktmainblogs`(`id`, `blogcomment`, `page_id`, `title`, `post`, `username`, `date_posted`) VALUES ([],[value-2],['".$pg."'],[value-4],[".$_POST['comment']."],[".$user['username']."],[value-7])"; } //end Post actions } //end display comment form } //end while loop } //end blogs function
  9. ok i think i'm even making it too complicated by ommitting parts and such so here are 3 variations with 3 different results of the full function i am calling in code form only, sorry for any confusion before: This get's me 1 copy of the 1st entry: <?php function blogs ($dbc, $pg) { $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); $blogPosts= mysqli_fetch_assoc ($r); while ($blogPosts= mysqli_fetch_assoc ($r)) { //foreach ($blogPosts as $key => $value){ echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } } //} ?> This gets me 7 copies of the 1st entry: <?php function blogs ($dbc, $pg) { $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); $blogPosts= mysqli_fetch_assoc ($r); while ($blogPosts= mysqli_fetch_assoc ($r)) { foreach ($blogPosts as $key => $value){ echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } } } ?> and this gets me 7 copies of the 2nd entry followed by 2 copies of the 1st entry: <?php function blogs ($dbc, $pg) { $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); //$blogPosts= mysqli_fetch_assoc ($r); while ($blogPosts= mysqli_fetch_assoc ($r)) { foreach ($blogPosts as $key => $value){ echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } } } ?>
  10. hang on i'm even more confused now this get's more repetitions of the 2nd post: $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); while ($blogPosts= mysqli_fetch_assoc ($r)){ foreach ($blogPosts as $key => $value) { echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } } } ?> <?php $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); while ($blogPosts= mysqli_fetch_assoc ($r)){ foreach ($blogPosts as $key => $value) { echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } } } ?> and this does what i said just a second ago: wysiwyg (); $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); $blogPosts= mysqli_fetch_assoc ($r); while ($blogPosts= mysqli_fetch_assoc ($r)) { echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } } ?> <?php $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); $blogPosts= mysqli_fetch_assoc ($r); while ($blogPosts= mysqli_fetch_assoc ($r)) { echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } } ?> what the hell?
  11. ok so that's got back the 1st one but the 2nd is missing so it's not continuing after it retrieves the 1st row in DB table?
  12. i'm trying to get all table entries from a table called abstrktmainblogs with reference to the page number $pg. the connection and SQL are fine it is something in the foreach loop that is only displaying the 2nd (currently last) entry 7 times on the page instead of both the 1st and 2nd only once each. I want this to effectively be infinite posts always adding new ones to the top of the page. $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); $blogPosts= mysqli_fetch_assoc ($r); foreach ($blogPosts as $key => $value) { echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } here it is in code snippet some people prefer either or: <?php $q="SELECT * FROM abstrktmainblogs WHERE page_id='$pg' AND pgassoc='$pg' ORDER BY date_posted DESC"; $r = mysqli_query($dbc, $q); $blogPosts= mysqli_fetch_assoc ($r); foreach ($blogPosts as $key => $value) { echo'<div class="blogPosts"> <table> <tr>'.$blogPosts['title'].' by '.$blogPosts['username'].' on '.$blogPosts['date_posted'].'</tr> <br></br> <tr>'.$blogPosts['post'].'</tr> </table></div> <br></br>'; if (isset($_COOKIE['userid'])) { echo '<form method="post" autocomplete="on"> <input type="text" width="100%" height="30px"> </input> </form>';} } ?>
×
×
  • 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.