
ncovill
Members-
Posts
28 -
Joined
-
Last visited
Never
Everything posted by ncovill
-
Hey all, Quick sum up: I have a social website where users can follow/post/vote etc. I am adding a new facebook-like activity wall feature to each users profiles. I have worked on this bit for a few days now and can't seem to get it to work properly. What I want is, well, exactly like the facebook wall as I mentioned...When a visitor visits a user's profile, that user's activity will display, whether they recently "voted" on a post, commented, or posted something of their own, I would like it to display on their profile and of course, have the most recent entries on top. The problems I am having right now are: it's displaying some things twice and it's not sorting them by the most recent. I am working with 3 tables here (I only posted the columns that I am using): Table structure for table votes_posts Field Type Null Default indexer int(11) No post_id int(11) No vote int(11) No user_name varchar(250) No date varchar(255) No Table structure for table posts Field Type Null Default id int(11) No name varchar(30) No content text No datetimerss varchar(255) No category int(11) No Table structure for table comments Field Type Null Default id int(12) No post_id int(12) No name varchar(30) No content text No type varchar(30) No datetimerss varchar(255) No $users is just $_GET['user'] The timeAgo() function, simply displays the very popular "posted xx ago" date time. <ul class="streamActivity"> <?php $checkActivity = "SELECT votes_posts.post_id, votes_posts.user_name, votes_posts.vote, votes_posts.date, posts.id, posts.content, posts.name, posts.datetimerss, categories.category, comments.post_id AS comm_postid, comments.content AS comm_content, comments.name AS comm_name, comments.datetimerss AS comm_date, comments.type FROM `votes_posts` LEFT OUTER JOIN `posts` ON votes_posts.post_id = posts.id LEFT OUTER JOIN `comments` ON posts.id = comments.post_id LEFT OUTER JOIN `categories` ON posts.category = categories.cat_id WHERE (votes_posts.post_id = posts.id AND user_name = '$user') OR (comments.post_id = posts.id AND comments.name = '$user') OR (posts.name = '$user') ORDER BY votes_posts.date, posts.datetimerss, comments.datetimerss ASC"; $checkActivityResult = mysql_query($checkActivity); if (mysql_num_rows($checkActivityResult) > 0) { while ($sessionAct = mysql_fetch_array($checkActivityResult)) { $category = strtolower($sessionAct['category']); $dateVote = timeAgo($sessionAct['date']); $datePost = timeAgo($sessionAct['datetimerss']); $dateComm = timeAgo($sessionAct['comm_date']); $namePost = $sessionAct['name']; $nameComm = $sessionAct['comm_name']; $nameVote = $sessionAct['user_name']; $idVote = $sessionAct['post_id']; $idPost = $sessionAct['id']; $idComm = $sessionAct['comm_postid']; $contentPost = $sessionAct['content']; $contentComm = $sessionAct['comm_content']; $typeComm = $sessionAct['type']; if ($namePost == $user) { $classList = 'storyPost'; $classIcon = 'iconMuttr'; $name = $namePost; $content = $contentPost .' ... read more'; $datetime = $datePost; } elseif ($nameComm == $user && $typeComm == "Comment") { $classList = 'actionPost'; $classIcon = 'iconComment'; $name = $nameComm; $content = 'Commented "'. $contentComm .'"'; $datetime = $dateComm; } elseif ($nameComm == $user && $typeComm == "Advice") { $classList = 'actionPost'; $classIcon = 'iconAdvice'; $name = $nameComm; $content = 'gave Advice "'. $contentComm .'"'; $datetime = $dateComm; } elseif ($nameVote == $user) { if ($sessionAct['vote'] == "1") { $classList = 'actionPost'; $classIcon = 'iconLaughed'; $name = $nameVote; $content = 'Laughed at "'. $contentPost .'"'; $datetime = $dateVote; } elseif ($sessionAct['vote'] == "2") { $classList = 'actionPost'; $classIcon = 'iconLoved'; $name = $nameVote; $content = 'Showed Love on "'. $contentPost .'"'; $datetime = $dateVote; } elseif ($sessionAct['vote'] == "3") { $classList = 'actionPost'; $classIcon = 'iconIdiot'; $name = $nameVote; $content = 'called '. $namePost .' an Idiot for "'. $contentPost .'"'; $datetime = $dateVote; } } ?> <li class="row-activity <?php echo $classList; ?>"> <a href="" class="avatar"><img src="/images/avatars/default_male.jpg" /></a> <div class="info"> <div class="userName"> <a href=""><?php echo $name; ?></a> </div> <span class="msgBody"><?php echo $content; ?></span> <div class="imgTimeStream"> <span class="img <?php echo $classIcon; ?>"></span> <span class="source"><?php echo $datetime; ?></span> </div> </div> </li> <?php } } else { echo '<p>This user has no recent activity.</p>'; } ?> </ul> I am by no means an expert programmer...everything I know I have pretty much taught myself over the past year or two, so I can only imagine how ugly this truly is lol. I am learning each and everyday though, and I hope to continue Also, within each type of activity, there will be slightly different CSS classes on some things. Example: if the result row is a post then the css class of the list item would be "post" if the result row is a vote then the css class of the list item would be "vote" etc. Any help would be appreciated!
-
Hey all, For some reason a few of my RewriteRule's seem to be conflicting with one another. I have several rules, but these are the conflicting ones: RewriteRule ^([a-zA-Z0-9_-]+)/page=([0-9_-]*)$ /pages.php?cat_id=$1¤tpage=$2 [L] RewriteRule ^([a-zA-Z0-9_-]+)$ /pages.php?cat_id=$1 [L] The rule above works fine (i can go to /category fine, it goes to the proper page and everything). But once I add in: RewriteRule ^([a-zA-Z0-9_-]+)$ /index.php?order=$1 [L] RewriteRule ^([a-zA-Z0-9_-]+)/page=([0-9_-]+)$ /index.php?order=$1¤tpage=$2 [L] The first part stops working (the pages.php rule), but these new rules work fine (the ?order= rules)... The ?order= rules are above the pages.php rule in my .htaccess file, but when I put the order rule below the pages.php rule, then the categories rule works fine, while the order rule no longer does... so confused :/ As always, any kind of help is appreciated!
-
for whatever reason, this continues to happen... do I need to somehow redirect the "/postdetails.php?id=#" link to the new "/category/id#" link or something? I can't think of anything else ;x
-
I am severely confused by this... I have made a bunch of mod_rewrites in my .htaccess and they work perfectly. I have all the links on my site point to the search engine friendly rewritten links and what not. For some reason, each new post made, Google indexes the old "/postdetails.php?id=##" link instead of the new "/category/id#" link. Below is part of my .htaccess: RewriteRule ^page=([0-9_-]*)$ /index.php?currentpage=$1 RewriteRule ^index.php/page=([0-9_-]*)$ /index.php?currentpage=$1 RewriteRule ^([a-zA-Z0-9_-]+)/page=([0-9_-]*)$ /pages.php?action=get_entries&cat_id=$1¤tpage=$2 [L] RewriteRule ^([a-zA-Z0-9_-]+)$ /pages.php?action=get_entries&cat_id=$1 [L] RewriteRule ^([a-zA-Z0-9_-]+)/([0-9_-]+)$ /postdetails.php?cat=$1&id=$2 [L] Any help would be greatly appreciated as this has been eating at me for a bit!
-
[SOLVED] PHP MySQL custom search engine issues with pagination
ncovill replied to ncovill's topic in PHP Coding Help
YES! I DID IT!!! lol i had to get rid of the if ($submit) statement since it was only executing that when the search button was clicked Now... I gotta figure out how to make the keywords all bolded ;x -
[SOLVED] PHP MySQL custom search engine issues with pagination
ncovill replied to ncovill's topic in PHP Coding Help
Well, made some headway anyway... using $_REQUEST['keywords'] and making the links this: "search.php?action=get_entries_search&keywords=$keywords¤tpage=1" Works to the sense as always showing the right # of pages lol. Except still.. when clicking on one of the pagination links, it doesn't display the results, even if i click back to the first page EDIT: having the links "search.php?keywords=$keywords¤tpage=1" also does the same thing... hmm -
[SOLVED] PHP MySQL custom search engine issues with pagination
ncovill replied to ncovill's topic in PHP Coding Help
No go still doing the same thing, I even tried with REQUEST, grrrr.... this is frustrating me to no end! -
[SOLVED] PHP MySQL custom search engine issues with pagination
ncovill replied to ncovill's topic in PHP Coding Help
Thank you for the reply. Sorry about my explanation, I did it quickly before I went out... but the problem isn't showing the pages, it displays the proper amount of pages perfectly, and displays the results even. The only problem is that when clicking on any of the links in the pagination, it goes to a page with every single page number(starting at 1 ending at 26, every single post in the database, not just the searched phrase) in the pagination but nothing is displayed. I am not sure how to make Next, Previous, Last, First, $x all link to the specified search term they have entered. -
A site of mine has now grown enough to where I needed to implement a search feature, so people can simply type a word/phrase into the search field and it will bring up every post with what they searched for. I am having some issues with it. It does work, but the pagination is screwy. It seems to only be the pagination links (such as: Next, Previous, First, Last, etc.). Anyway, I am pretty sure you guys understand what the pagination is supposed to do so, here's some code: The simple form: <form method="post" action="search.php" id="searchform"> <input type="text" name="keywords" /> <input type="submit" name="searchsubmit" value="search" /> </form> the search.php (this is what puts the functions together and displays the info): // connect to the db db_connect(); $keywords = $_POST['keywords']; // And we remind them what they searched for echo '<h1 style="padding: 0px 0px 8px; color: #F68A20; font-size: 24px;"><b>Searched For</b> <span style="font-size: 12px; font-weight: normal; color: #000000;">[ '. $keywords .' ]</span></h1>'; ?> <div class="pagination"> <?php echo pagination_search(); ?> </div> <?php $submit = $_POST['searchsubmit']; if ($submit) { echo "Results:<br />"; $keywords = strip_tags($keywords); $keywords = trim($keywords); if ($keywords == "") { echo "You forgot to enter a search term.<br />"; } // if they did not enter a search term, give them an error $sql = "SELECT * FROM `posts` WHERE `content` LIKE '%$keywords%'"; $result = mysql_query($sql); $anymatches = mysql_num_rows($result); if ($anymatches > 0) { // now we search for our search term echo get_entries_search(); } else { echo "Sorry, but we could not find an entry to match your search.<br /><br />"; } } and the functions, one to get the entries, one for pagination: function get_entries_search() { $connection = db_connect(); /****** pagination ******/ // find out how many rows are in the table $keywords = $_POST['keywords']; $sql = "SELECT COUNT(*) FROM `posts` WHERE `content` LIKE '%$keywords%'"; $testsearch = $_REQUEST['testsearch']; if ($testsearch != "") { $keywords = $testsearch; } $result = mysql_query($sql, $connection); $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 = $_GET['currentpage']; } else { // default page num $currentpage = 1; } // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; /****** end pagination ******/ // get info from the db $query = "SELECT posts.id, posts.content, posts.name, posts.datetime, posts.category, posts.comments, posts.votes1, posts.votes2, posts.votes3, categories.category FROM `posts` LEFT OUTER JOIN `categories` ON posts.category = categories.cat_id "; if ($cat_id = $_REQUEST['cat_id']) { if (is_int($cat_id)) { $query .= " WHERE categories.cat_id = ". $cat_id; } else { $query .= " WHERE categories.category = \""; $query .= mysql_real_escape_string($cat_id); $query .= "\""; } } $query .= " WHERE posts.content LIKE '%$keywords%'"; $query .= " ORDER BY `id` DESC LIMIT ". $offset .", ". $rowsperpage; $result = mysql_query($query, $connection); return create_output($result); } function pagination_search() { $connection = db_connect(); /****** pagination ******/ // find out how many rows are in the table $keywords = $_POST['keywords']; $sql = "SELECT COUNT(*) FROM `posts` WHERE `content` LIKE '%$keywords%'"; $testsearch = $_REQUEST['testsearch']; if ($testsearch != "") { $keywords = $testsearch; } $result = mysql_query($sql, $connection); $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 = $_GET['currentpage']; } else { // default page num $currentpage = 1; } // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // the offset of the list, based on current page //$offset = ($currentpage - 1) * $rowsperpage; /****** build the pagination links ******/ // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo "<div class='paginleft'><a href='search.php?action=get_entries_search&testsearch=$keywords¤tpage=1'>First</a></div>"; } else { echo "<div class='paginleft'>First</div>"; } // 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 "<div class='paginright'><a href='search.php?action=get_entries_search&testsearch=$keywords¤tpage=$nextpage'>Next</a></div>"; } else { echo "<div class='paginright'>Next</div>"; } // if not on page 1, don't show back links if ($currentpage > 1) { // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo "<div class='paginright'>|</div>"; echo "<div class='paginright'><a href='search.php?action=get_entries_search&testsearch=$keywords¤tpage=$prevpage'>Previous</a></div>"; } else { echo "<div class='paginright'>|</div>"; echo "<div class='paginright'>Previous</div>"; } // range of num links to show $range = 5; $range2 = 6; // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range2) + 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 "<div class='paginx'><b>$x</b></div>"; } // if not current page else { // make it a link echo "<div class='paginx'><a href='search.php?action=get_entries_search&testsearch=$keywords¤tpage=$x'>$x</a></div>"; } } } if ($currentpage != $totalpages) { if ($totalpages > 7) { if ($totalpages < (($currentpage + $range2) + 1)) { echo ""; } else { echo "<div class='paginx'> ... </div> "; echo "<div class='paginx'><a href='search.php?action=get_entries_search&testsearch=$keywords¤tpage=$totalpages'>$totalpages</a></div> "; } } // echo forward link for lastpage echo "<div class='paginlast'><a href='search.php?action=get_entries_search&testsearch=$keywords¤tpage=$totalpages'>Last</a></div> "; } else { echo "<div class='paginlast'>Last</div>"; } } As I said, I believe the only problem is with the linkage in the pagination.. it's the only part I'm not quite sure about.
-
Thanks again man, but I still can't get this to display the new post instantly The prepend/append is cool and all, but it even adds the error message to the div. I just want it to prepend/append the successful comment/post, with all the information.
-
I keep hearing about this php.ini file, but I can't find it anywhere, nor do I even know if I have it lol. I do need something to expire sessions ;x
-
lol, simplest thing and it works. I needed to add session_start(); to add_post.php
-
Hey everyone... So, I have a form that submits a message, name, userid, category, and datetime into the database. It all works fine except the userid... I had it working before, but now I have no clue why it stopped working If a person is logged in, the "username" field becomes a dropdown menu and they can choose between Anonymous or their Username. I want it to insert the users 'id' (users table in the DB) into the post as well as update a post count in the users table. It confuses the hell out of me because the same exact fetch array to display their info if they're logged in or not works perfectly (using sessions)... but for w/e reason it's not working in this particular INSERT function. Anyway, here's the add_post.php which displays errors or success, then processes the function if it's a success - db_connect(); is a function to connect to the DB: <?php require_once('functions.php'); db_connect(); $message = $_POST['guestbook_message']; $name = $_POST['guestbook_name']; $datetime = $_POST['datetime']; $category = $_POST['category']; if (strlen($message) < 50) { $msgerror = "<strong>Error:</strong> Your message length is too short."; } if ($category == 1) { $msgerror = "<strong>Error:</strong> Please choose a category."; } $bad_word_list = "<object, </object>, <script, <param, </script>, </param>, <a href, jav, jav&, javas, 	, 
, 
, alert\(, <iframe, <embed, <meta, http://, www., .com, .net, .org, dot com, dot net, dot org, (dot) com, (dot) net, (dot) org"; $bad_words = explode(", ",$bad_word_list); foreach ($bad_words as $word) { if (false !== stripos($message, $word)) { $msgerror = "<strong>Error:</strong> Your message might contain unauthorized words."; } } if($msgerror) { $postmsg = $msgerror; echo "<span class='posterror'>". $postmsg ."</span>"; } else { add_post($message, $name, $userid, $datetime, $category); $postmsg = "<strong>Success!</strong> Your comment has been posted. <script type=\"text/javascript\"><!-- setTimeout('Redirect()',1000); function Redirect() { location.href = 'index.php'; } // --></script>"; echo "<span class='postsuccess'>". $postmsg ."</span>"; } ?> And here is the function: function add_post($message, $name, $userid, $datetime, $category) { $name = mysql_real_escape_string($name); $message = mysql_real_escape_string(stripslashes(ereg_replace("\r\n", "<br />", $message))); $time = strtotime("now"); $time = $time + 3600; $datetime = date("m/d/y @ h:i:sa", $time); $connection = db_connect(); $username = $_SESSION['user']['username']; $user_array = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `username` = '$username'")); $userid = $user_array['id']; $query = "INSERT INTO `posts`(name, userid, content, datetime, category) VALUES('$name', '$userid', '$message', '$datetime', '$category')"; mysql_query($query, $connection); // find the user and update comment count $sql = "SELECT * FROM `users` WHERE `id` = '$userid'"; $result = mysql_query($sql); $rows = mysql_fetch_array($result); if ($rows) { $max_post = $rows['posts'] + 1; } else { $max_post = 1; } $q = "UPDATE `users` SET `posts` = '$max_post' WHERE `id` = '$userid'"; mysql_query($q); db_close($connection); } And I am not sure this is needed but this is the code that works fine, displaying whether or not they're logged in: $session = $_SESSION['in']; if ($session) { $username = $_SESSION['user']['username']; } if($session != "yes") // generate login form { $login = '<form action="login.php" method="post"> <p> <label class="loginField">Username:</label> <input class="login" type="text" name="log" id="log" value="" /> </p> <p> <label class="loginField">Password:</label> <input class="login" type="password" name="pwd" id="pwd" value="" /> </p> <div style="text-align: right;"> <input type="submit" name="submitlogin" value="Submit" class="button_login" id="submit" /> </div> </form><br /> <div id="loginajax"><a href="#submit_register" name="modal"><strong>Sign up</strong> </a> | <a href="forgot.php">Forgot Password?</a></div>'; } else { db_connect(); $username = $_SESSION['user']['username']; $user_array = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `username` = '$username'")); $login = 'Welcome back, <strong>'. $user_array['name'] .'</strong>. <a href="logout.php" name="logout" id="logout">Logout</a><br /><br /><br /> <a href="settings.php">Edit Profile</a> | <a href="profile.php?user='. $username .'">View Profile</a>'; } Like I said...that fetch array brings up the appropriate info, but for w/e reason does not work in the add_post function Any help would be greatly appreciated!!!
-
Also forgot to add that I would need to make the window close after a few seconds of displaying the success message, not sure if there's anyway to do this ;x I am not sure this whole prepend feature will work properly. It needs to bring up the information from the database, just as it does with all of the previous posts. Not sure how to do this with a brand new post without refreshing the page :/ I was using an auto refresh before, so I may just stick with that for now... But, here's the function for displaying posts: function create_output($result) { $output = ""; $ip = $_SERVER['REMOTE_ADDR']; $voting_array = mysql_fetch_array(mysql_query("SELECT * FROM `votes_cast` WHERE `ip` = '$ip'")); $vote_explode = explode(',', $voting_array['entry_id']); foreach($vote_explode as $vote_ex) { $vote_ex = explode(":", $vote_ex); $compnum = $vote_ex[0]; $compvote = $vote_ex[1]; $compvotearray[$compnum] = $compvote; } while($row = mysql_fetch_assoc($result)) { $output .= "<div class='post'>"; $output .= "<div class='postcontain'>"; $output .= "<div class='ventcontain'>"; $user = $row['name']; $user_array = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `username` = '$user'")); if ($user == "Anonymous") { $output .= "<a href='profile.php?user=". $user ."' title=''><img src='images/avatars/avatar_default.jpg' alt='' width='38' height='39' class='avatarimg' style='border: 1px #fcb540 solid;' /></a>"; } else { $output .= "<a href='profile.php?user=". $user ."' title=''><img src='". $user_array['avatar'] ."' alt='' width='38' height='39' class='avatarimg' style='border: 0px;' /></a>"; } if (strlen($row['content']) > 300) { $content = substr($row['content'], 0, 300); $output .= "<div class='vent'> <a href='postdetails.php?id=". $row['id'] ."' style='color: #000000; text-decoration: none;'>". $content ." ... <span style='color: #025AA2; font-size: 11px;'>read more</span></a><hr />"; } else { $output .= "<div class='vent'> <a href='postdetails.php?id=". $row['id'] ."' style='color: #000000; text-decoration: none;'>". $row['content'] ." </a><hr />"; } $output .= "<div class='date'>"; $output .= "<a href='profile.php?user=". $row['name'] ."' title=''>". $row['name'] ."</a> ". $row['datetime'] ." ". $row['category']; $output .= " <a href='postdetails.php?id=". $row['id'] ."'>Comments</a>(". $row['comments'] .")"; $output .= "</div>"; $output .= "<div class='share'>"; if(!$compvotearray[$row['id']]) { $output .= ' <span id="vote_buttons'. $row['id'] .'" class="vote_buttons"> <span id="a1votes_count'. $row['id'] .'" class="vote"> <a id=":'. $row['id'] .':1:'. $row['votes1'] .':'. $row['votes2'] .':'. $row['votes3'] .':" class="vote_laugh" title="Laugh" href="javascript:;"> Laugh</a>('. $row['votes1'] .') </span>'; $output .= ' - <span id="a2votes_count'. $row['id'] .'" class="vote"> <a id=":'. $row['id'] .':2:'. $row['votes1'] .':'. $row['votes2'] .':'. $row['votes3'] .':" class="vote_love" title="Show Love" href="javascript:;"> Show Love</a>('. $row['votes2'] .') </span>'; $output .= ' - <span id="a3votes_count'. $row['id'] .'" class="vote"> <a id=":'. $row['id'] .':3:'. $row['votes1'] .':'. $row['votes2'] .':'. $row['votes3'] .':" class="vote_idiot" title="You\'re an Idiot" href="javascript:;"> You\'re an Idiot</a>('. $row['votes3'] .') </span> </span><br />'; } else { $output .= ' <span id="vote_buttons'. $row['id'] .'" class="vote_buttons voted"> <span id="a1votes_count'. $row['id'] .'"> Laugh('. $row['votes1'] .') </span>'; $output .= ' - <span id="a2votes_count'. $row['id'] .'"> Show Love('. $row['votes2'] .') </span>'; $output .= ' - <span id="a3votes_count'. $row['id'] .'"> You\'re an Idiot('. $row['votes3'] .') </span> </span><br />'; } $output .= "</div>"; $output .= "</div>"; $output .= "</div>"; $output .= "<div class='clear'> </div>"; $output .= "</div>"; $output .= "</div>"; } return $output; } As you can see it's a very complex matter, lol. Has everything, category, message, name, voting, etc. Again, any tips would definitely be helpful as I am new to jquery/ajax.
-
Also forgot to add that I would need to make the window close after a few seconds of displaying the success message, not sure if there's anyway to do this ;x
-
alright, i will have to check all that out. I am more familiar with PHP, jquery is alittle new for me so, this should be fun haha. Thanks again for everything
-
Needs to display all of the posts. So I am guessing somehow need to append the new post.. hmm, any tips on this? lol
-
@joel24 - sweet! thanks a bunch man!!! it works fine now except, once I submit, it just sits there with the success message lol. anyway to make it close the window and show the new post on success? Not sure this will help at all, but here is the jquery for the modal window: //select all the a tag with name equal to modal $('a[name=modal]').click(function(e) { //Cancel the link behavior e.preventDefault(); //Get the A tag var id = $(this).attr('href'); //Get the screen height and width var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Set heigth and width to mask to fill up the whole screen $('#mask').css({'width':maskWidth,'height':maskHeight}); //transition effect $('#mask').fadeIn(100).fadeTo("fast", .6); //Get the window height and width var winH = $(window).height(); var winW = $(window).width(); //Set the popup window to center $(id).css('top', winH/2-$(id).height()/2); $(id).css('left', winW/2-$(id).width()/2); //transition effect $(id).fadeIn(500); }); //if close button is clicked $('.window .close').click(function(e) { //Cancel the link behavior e.preventDefault(); $('#mask').hide(); $('.window').hide(); });
-
I have searched everywhere, but cannot find a solution for this... I have worked all day trying to get my form to work with jquery. It works to a point. So, I have my Form open up in a Jquery Modal Window...works fine. A user has his username in the Name field, they need to select a Category, if they don't it returns an error. Lastly, they must fill out a Message, if they do not have a certain # of characters, it returns an error as well. This all works fine. The errors show up appropriately with the Jquery that I have set. The only problem I am having right now is that no matter how many chars I insert into the Message textarea, it returns the "Your message length is too short" error. The string length must be at least 10 characters. Once all is set I want it to show the Success message, then after a couple of seconds close out the jquery window and display the post without having to refresh. Here is the form code (db_connect(); is a function to connect to the database): <form class="guestbook_form" action="add_post.php" method="post"> <label>Nickname:</label> <?php db_connect(); if(!$_SESSION['user']['username']) { $username = "Anonymous"; echo '<input type="text" readonly="readonly" name="guestbook_name" class="guestbook_name" value="'.$username.'" />'; } else { $username = $_SESSION['user']['username']; echo '<select name="guestbook_name" class="guestbook_name" id="guestbook_name"> <option value="'. $username .'">'. $username .'</option> <option value="Anonymous">Anonymous</option> </select>'; } $query = "SELECT * FROM `categories`"; $results = mysql_query($query); echo '<select name="category" class="category" id="guestbook_category">'; while ($row = mysql_fetch_array($results)) { $catid = $row['cat_id']; $catname = $row['category']; echo '<option value="'.$catid.'">'.$catname.'</option>'; } echo "</select>"; ?> <p class="label"> <label>Message:</label><textarea cols="50" rows="10" name="guestbook_message" id="guestbook_message"></textarea> </p> <p class="label"> <label></label> <span class="postmsg"> </span> </p> <p class="submit"> <button type="submit" class="submit" value="Submit" id="guestbook_submit" name="guestbook_submit">Submit</button> <button type="submit" class="close">Cancel</button> </p> </form> the add_post.php: <?php require_once('functions.php'); db_connect(); $message = $_POST['guestbook_message']; $name = $_POST['guestbook_name']; $datetime = $_POST['datetime']; $category = $_POST['category']; if (strlen($message) < 10) { $msgerror = "<strong>Error:</strong> Your message length is too short."; } if ($category == 1) { $msgerror = "<strong>Error:</strong> Please choose a category."; } $bad_word_list = "<object, </object>, <script, <param, </script>, </param>, <a href, jav, jav&, javas, 	, 
, 
, alert\(, <iframe, <embed, <meta, http://, www., .com, .net, .org, dot com, dot net, dot org"; $bad_words = explode(", ",$bad_word_list); foreach ($bad_words as $word) { if (false !== stripos($message, $word)) { $msgerror = "<strong>Error:</strong> Your message might contain unauthorized words."; } } if($msgerror) { $postmsg = $msgerror; echo "<span class='posterror'>". $postmsg ."</span>"; } else { add_post($message, $name, $datetime, $category); $postmsg = "<strong>Success!</strong> Your Muttr has been posted."; echo "<span class='postsuccess'>". $postmsg ."</span>"; } ?> and finally, the jquery/ajax: $("#guestbook_submit").click(function(){ //get the id //the_id = $(this).attr('id'); $(".postmsg").fadeOut(50); // show the spinner $('.postmsg').append('<img src="images/loader.gif" alt="Loading" />'); //the main ajax request var name = $("#guestbook_name").val(); var category = $("#guestbook_category").val(); var message = $("#guestbook_message").val(); var dataString = 'name='+ name + '&category=' + category + '&message=' + message; $.ajax({ type: "POST", data: dataString, url: "add_post.php", timeout: 2000, cache: false, success: function(msg) { $("#loading").remove(); $(".postmsg").fadeIn(400); $(".postmsg").html(msg); setTimeout("$('.postmsg').fadeOut();",60000); } }); return false; });
-
I added in $('.postmsg').append('<img src="images/loader.gif" alt="Loading" />'); instead of the //$(this).parent().html("<img src='images/ajax-loader.gif' alt='' id='loading' /><button type='submit' class='submit' value='Submit' id='guestbook_submit' name='submit'>Submit</button> <button type='submit' class='close'>Cancel</button>"); and that's working fine... now I gotta figure out why it won't submit the form properly.. keeps giving me my "Error: Your message length is too short." message
-
When you click the link to open the form it opens a jquery modal window which displays the form. the code for the form is: <form class="guestbook_form" action="#" method="post"> <label>Nickname:</label> <?php db_connect(); <input type="text" readonly="readonly" name="guestbook_name" class="guestbook_name" value="username" /> $query = "SELECT * FROM `categories`"; $results = mysql_query($query); echo '<select name="category" class="category" id="guestbook_category">'; while ($row = mysql_fetch_array($results)) { $catid = $row['cat_id']; $catname = $row['category']; echo '<option value="'.$catid.'">'.$catname.'</option>'; } echo "</select>"; ?> <p class="label"> <label>Message:</label><textarea cols="50" rows="10" name="guestbook_message" id="guestbook_message"></textarea> </p> <p class="label"> <label></label> <span class="postmsg"> </span> </p> <p class="submit"> <button type="submit" class="submit" value="Submit" id="guestbook_submit" name="submit">Submit</button> <button type="submit" class="close">Cancel</button> </p> </form> When they click "Submit", add_post.php checks to see if there are any errors or not. I want it to do just that, display the proper message whether its a success or an error right above the submit/cancel buttons. It is displaying errors perfectly, but only once...if you press Submit, get an error, then press it again, it seems to close the screen and then reloads the page. I need it to rinse, wash, and repeat if they click submit a second time and there's another error or what not. Just so you know, the first part of this code is the window popup... but here is the jquery pop up and the jquery/ajax code: $(document).ready(function() { //select all the a tag with name equal to modal $('a[name=modal]').click(function(e) { //Cancel the link behavior e.preventDefault(); //Get the A tag var id = $(this).attr('href'); //Get the screen height and width var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Set heigth and width to mask to fill up the whole screen $('#mask').css({'width':maskWidth,'height':maskHeight}); //transition effect $('#mask').fadeIn(100).fadeTo("fast", .6); //Get the window height and width var winH = $(window).height(); var winW = $(window).width(); //Set the popup window to center $(id).css('top', winH/2-$(id).height()/2); $(id).css('left', winW/2-$(id).width()/2); //transition effect $(id).fadeIn(500); }); //if submit post is clicked $("#guestbook_submit").click(function(e){ // show the spinner $(this).parent().html("<img src='images/ajax-loader.gif' alt='' id='loading' /><button type='submit' class='submit' value='Submit' id='guestbook_submit' name='submit'>Submit</button> <button type='submit' class='close'>Cancel</button>"); //the main ajax request var name = $("#guestbook_name").val(); var category = $("#guestbook_category").val(); var message = $("#guestbook_message").val(); var dataString = 'name='+ name + '&category=' + category + '&message=' + message; $.ajax({ type: "POST", data: dataString, url: "add_post.php", cache: false, success: function(msg) { $("#loading").remove(); $(".postmsg").fadeIn(300); $(".postmsg").html(msg); } }); return false; }); //if close button is clicked $('.window .close').click(function(e) { //Cancel the link behavior e.preventDefault(); $('#mask').hide(); $('.window').hide(); }); }); If you need the add_post.php code, please let me know and I will post it right away Any help would be greatly appreciated, as this is a huge issue for me and my site!
-
Well, I solved it... all I had to do was copy and paste the JOIN and the if statement for the categories
-
no go, still is picking up the category name
-
haha, yea, I believe it is getting "cat_id" from the action cat_id, such as here "pages.php?action=get_entries&cat_id=" and i have $query LEFT OUTER JOIN posts.category with categories.cat_id (posts, is one table with all the posts, categories is another table with only the categories in it) so what it does is in the posts.category column it inputs the category id # but because of: if ($cat_id = $_REQUEST['cat_id']) { if (is_int($cat_id)) { $query .= " WHERE categories.cat_id = ". $cat_id; } else { $query .= " WHERE categories.category = \""; $query .= mysql_real_escape_string($cat_id); $query .= "\""; } } it displays the category name instead
-
Ill post more code here.. how categories are brought up and stuff. this function gets the category and uses the create_output function to display each post: function get_entries_catid() { $connection = db_connect(); /****** pagination ******/ // find out how many rows are in the table $cat_id = $_REQUEST['cat_id']; $sql = "SELECT COUNT(*) FROM `posts`"; $result = mysql_query($sql, $connection); $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 = $_GET['currentpage']; } else { // default page num $currentpage = 1; } // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; /****** end pagination ******/ // get info from the db $query = "SELECT posts.id, posts.content, posts.name, posts.datetime, posts.category, posts.comments, categories.category FROM `posts` LEFT OUTER JOIN `categories` ON posts.category = categories.cat_id "; if ($cat_id = $_REQUEST['cat_id']) { if (is_int($cat_id)) { $query .= " WHERE categories.cat_id = ". $cat_id; } else { $query .= " WHERE categories.category = \""; $query .= mysql_real_escape_string($cat_id); $query .= "\""; } } $query .= " ORDER BY `id` DESC LIMIT ". $offset .", ". $rowsperpage; $result = mysql_query($query, $connection); return create_output($result); } here is the create_output function, which displays each post: function create_output($result) { $output = ""; while($row = mysql_fetch_assoc($result)) { $output .= "<div class='post'>"; $output .= "<div class='postcontain'>"; $output .= "<div class='ventcontain'>"; $user = $row['name']; $user_array = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `username` = '$user'")); if ($user == "Anonymous") { $output .= "<a href='profile.php?user=". $user ."' title=''><img src='images/avatars/avatar_default.jpg' alt='' width='38' height='39' style='border: 1px #fcb540 solid;' /></a>"; } else { $output .= "<a href='profile.php?user=". $user ."' title=''><img src='". $user_array['avatar'] ."' alt='' width='38' height='39' style='border: 0px;' /></a>"; } if (strlen($row['content']) > 300) { $content = substr($row['content'], 0, 300); $output .= "<div class='vent'> <a href='postdetails.php?id=". $row['id'] ."' style='color: #000000; text-decoration: none;'>". $content ." ... <span style='color: #025AA2; font-size: 11px;'>read more</span></a><hr />"; } else { $output .= "<div class='vent'> <a href='postdetails.php?id=". $row['id'] ."' style='color: #000000; text-decoration: none;'>". $row['content'] ." </a><hr />"; } $output .= "<div class='date'>"; //$output .= "<a href='profile.php?user=". $row['name'] ."' title=''>". $row['name'] ."</a> ". $row['datetime'] ." <a href='pages.php?action=get_entries&cat_id=". $row['category'] ."' title=''>". $row['category'] ."</a>"; $output .= "<a href='profile.php?user=". $row['name'] ."' title=''>". $row['name'] ."</a> ". $row['datetime'] ." <a href='pages.php?action=get_entries&cat_id=". $row['category'] ."' title=''>". $row['category'] ."</a>"; $output .= " <a href='postdetails.php?id=". $row['id'] ."'>Comments</a> (". $row['comments'] .")"; $output .= "</div>"; $output .= "<div class='share'> </div>"; $output .= "</div>"; $output .= "</div>"; $output .= "<div class='clear'> </div>"; $output .= "</div>"; $output .= "</div>"; } return $output; }