Jump to content

tmworking

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tmworking's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I've got a sort page, and everything works EXCEPT sort by most and least commented. Can you help me find the error here? I think it's in the query since unions are a bit of a mystery to me, but I'm just learning so any help is appreciated. <?php include('header.php'); //USER INPUT $by = clean($_GET['by']); $by2 = clean($_GET['by2']); $by3 = clean($_GET['by3']); if($by=="best"){ $bylab = "best"; $byquery ="votes1"; $by3query = "DESC"; $byget = "?by=best"; $bestlabel = "<span class='bold red'>Highest</span>"; }else{ $bestlabel = "Highest"; } if($by=="worst"){ $bylab = "worst"; $byquery = "votes2"; $by3query = "DESC"; $byget = "?by=worst"; $worstlabel = "<span class='bold red'>Lowest</span>"; }else{ $worstlabel = "Lowest"; } if($by2=="day"){ } if($by2=="week"){ } if($by3=="least-commented"){ $by3get = "?by3=least-commented"; $by3query = "ASC"; $lcomlabel = "<strong>Least Commented</strong>"; }else{ $lcomlabel = "Least Commented"; } if($by3=="most-commented"){ $by3get = "?by3=most-commented"; $by3query = "DESC"; $mcomlabel = "<strong>Most Commented</strong>"; }else{ $mcomlabel = "Most Commented"; } if(!$by3){ $ncomlabel = "<strong>Neither</strong>"; }else{ $ncomlabel = "Neither"; } // GET TODAY TIMESTAMP FROM BEGINNING OF DAY $datetime = getdate(time()); $mon = $datetime['mon']; $date = $datetime['mday']; $year = $datetime['year']; $wkday = $datetime['wday']; $today = mktime(0,0,0,$mon,$date,$year); // GET TIMESTAMP FROM BEGINNING OF WEEK $startwkday = $date-$wkday+1; $thisweek = mktime(0,0,0,$mon,$startwkday,$year); // GET TIMESTAMP DATA FROM &ID= IN ADDRESS BAR $tstamp = clean($_GET['id']); if($tstamp){ $datetime = getdate($tstamp); $day = $datetime['weekday']; $month = $datetime['month']; $mon = $datetime['mon']; $date = $datetime['mday']; $year = $datetime['year']; $wkday = $datetime['wday']; $startwkday2 = $date-$wkday+1; $chosendatetime = "$day $date $month $year"; } $daylabel = "Day"; $weeklabel = "Week"; $alltimelabel = "All Time"; if($by2=="day"){ $daylabel = "<strong>Day</strong>"; $pretime = mktime(0,0,0,$mon,$date-1,$year); $start = mktime(0,0,0,$mon,$date,$year); $aftertime = mktime(0,0,0,$mon,$date+1,$year); $by2lab = "day"; $by2query = ""; //$by2get = "&by2=day&id=$start"; $by2get = "-by-day-" . $start; $best_query = mysql_query("SELECT * FROM `comps` where Accepted='Yes' and time between '$start' and '$aftertime' ORDER BY `$byquery` DESC LIMIT 5"); } if($by2=="week"){ $weeklabel = "<strong>Week</strong>"; $pretime = mktime(0,0,0,$mon,$startwkday2-7,$year); $start = mktime(0,0,0,$mon,$startwkday2,$year); $aftertime = mktime(0,0,0,$mon,$startwkday2+7,$year); $by2lab = "week"; $by2query = ""; $by2get = "&by2=week&id=$start"; $best_query = mysql_query("SELECT * FROM `comps` where Accepted='Yes' and time between '$start' and '$aftertime' ORDER BY `$byquery` DESC LIMIT 5"); } if(empty($by2)){ $alltimelabel = "<strong>All Time</strong>"; $best_query = mysql_query("SELECT * FROM `comps` ORDER BY `$byquery` $by3query LIMIT 5"); } if($by3){ $bylab = "best"; $query = "(select comps.*, count(comments.id) as cnt from comps, comments where comps.id=comments.comp_id group by comments.comp_id) union ( select comps.*, '0' as cnt from comps where id not in (select comp_id from comments) ) order by cnt $by3query limit 5"; $best_query = mysql_query($query); } $array = $best_query; $cnt = '<form action="submitCompliment.php" class="submit_form" method="POST" target="sendCommentIFrame"> <table id="submissionform"> <tr><td class="input" colspan=5> <textarea onfocus="javascript:document.getElementById(\'commbox\').value=\'\';" name="comp" rows="13" height="75" cols="20" id="commbox">'. $names[4] .'</textarea> </td></tr> <tr><td> <select name="cat">'; while($category = current($catlist)){ $cnt .= '<option value="'. key($catlist) .'">'. current($catlist) .'</option>'; next($catlist); } $cnt .= ' </select></td></tr> <tr><td><input type="submit" name="Ok" value="Submit!" class="button_login2"/> </td></tr> <tr><td> <div id="loadingsubmit_article" style="display:none;"><img src="images/loader.gif"/></div> <div id="resultsubmit_article" style="display:none;"></div> </td></tr> </table> </form><iframe name="sendCommentIFrame" style="display:none"></iframe>'; $maincontent = "<h1><a href=\"javascript:submitToggle();\" class=\"submit\" style=\"font-weight: bold;\">" . $submitpop . "</a></h1><div style=\"display: none;\" id=\"submit\" class=\"post\"><div id=\"result2\" class=\"result\">" . $cnt . "</div></div>"; $maincontent .= ' <div id="result" style="text-align:center;"> <a href="'. $bylab .'-compliments-by-day-'. $today .'">'. $daylabel .'</a> / <a href="'. $bylab .'-compliments-by-week-'. $thisweek .'">'. $weeklabel .'</a> / <a href="'. $bylab .'-compliments">'. $alltimelabel .'</a> <div class="bestworst"> <a href="best-compliments">'. $bestlabel .'</a> / <a href="worst-compliments">'. $worstlabel .'</a> </div> </div> <div class="commented"> <a href="'. $bylab .'-compliments-most-commented">'. $mcomlabel .'</a> / <a href="'. $bylab .'-compliments-least-commented">'. $lcomlabel .'</a> </div> '; $voting_array = mysql_fetch_array(mysql_query("SELECT * FROM `votes` WHERE `ip`='$ip'")); $vote_explode = explode(',', $voting_array['comp_id']); foreach($vote_explode as $vote_ex){ $vote_ex = explode(":", $vote_ex); $compnum = $vote_ex[0]; $compvote = $vote_ex[1]; $compvotearray[$compnum] = $compvote; } if(mysql_num_rows($array) > 0){ while($row = mysql_fetch_array($array, MYSQL_ASSOC)){ // count the comments $commentsCountQuery = "select * from comments where comp_id=" . $row['id']; $commentsCountResult = mysql_query($commentsCountQuery); $commentsCount = mysql_num_rows($commentsCountResult); $maincontent .= "\n<div id=\"result". $row['id'] ."\" class=\"result\">\n"; $maincontent .= stripslashes($row['message']) ."\n<br /><br />\n"; $maincontent .= '<span class="sentBy"><span class="lside"><a href="comment-'. $row['id'] .'" class="commlink">read comments ('. $commentsCount .')</a></span>'; if(!$compvotearray[$row['id']]){ $maincontent .= '<span id="vote_buttons'. $row['id'] .'" class="vote_buttons"> <span id="a1votes_count'. $row['id'] .'"> <a id=":'. $row['id'] .':1:'. $row['votes1'] .':'. $row['votes2'] .':" class="vote_up" title="'. $phrase1 .':'. $phrase2 .'" href="javascript:;"> '. $phrase1 .' ('. $row['votes1'] .')</a></span>'; $maincontent .= ' - <span id="a2votes_count'. $row['id'] .'"> <a id=":'. $row['id'] .':2:'. $row['votes1'] .':'. $row['votes2'] .':" class="vote_down" title="'. $phrase1 .':'. $phrase2 .'" href="javascript:;"> '. $phrase2 .' ('. $row['votes2'] .')</a> </span></span><br />'; } else { $maincontent .= '<span id="vote_buttons'. $row['id'] .'" class="vote_buttons voted"> <span id="a1votes_count'. $row['id'] .'"> '. $phrase1 .' ('. $row['votes1'] .')</span>'; $maincontent .= ' - <span id="a2votes_count'. $row['id'] .'" class="vote_buttons voted"> '. $phrase2 .' ('. $row['votes2'] .') </span></span><br />'; } $maincontent .= '<span class="mesdetail">'. date('F j, Y \a\t g:i a ', $row['time']) .'by <a href="' . $row['user'] . '_' . $row['user'] .'-'. $row['user'] . '">'. $row['user'] .'</a> </span>'; $maincontent .= '<span class="mesdetail"> in - <a href="category-'. $row['cat'] .'_'. $catlist[$row['cat']] .'">'. $catlist[$row['cat']] .'</a></span>'; $maincontent .= "</div>"; } } else { $maincontent .= "<strong>There are no results in this category.</strong>"; } $layout = str_replace("[[main-content]]", $maincontent, $layout); echo $layout; ?>
  2. In case anyone else ever comes across this, the solution is: if(isset($_GET['page'])) { $page=$_GET['page']; } else { $page=1; } $npage=$page-1;
  3. Thought I might add...buying scripts to save time in NOT a good idea, you end up with code like this.
  4. How can I fix my pagination? Links appear, and reload the page, but when I did an echo $page, even though the url is page=2 the echo is showing page 1. Any help would be awesome! Here are the snippets: if(!$page) $page = 1; $npage = $page - 1; if($c){ $addsql = " AND `cat` = '". $c ."'"; $addhtml = "&c=". $c; } $limit1 = $npage * 10; $limit2 = $npage + 10; echo $page; $q = "SELECT * FROM `comps` WHERE `accepted` = 'Yes'". $addsql ." ORDER BY `time` DESC LIMIT ". $limit1 .", ". $limit2; then display stuff Then $q = "SELECT COUNT(*) FROM `comps` WHERE `accepted` = 'Yes'". $addsql; $r = mysql_query($q); $num = mysql_fetch_array($r); $nbrPages = ceil($num[0] / 10); $i = 1; $maincontent .= "<br />"; // Pagination links. $nbrPages = $nbrPages; $thisPage = ""; include("pagination.php"); $maincontent .= $paginationLinks; Below is pagination code <?php //$nbrPages = 300; //$thisPage = "paginationTest.php"; if(strpos($thisPage, "?") === false) { $separator = "?"; } else { $separator = "&"; } if($nbrPages > 1) { if(isset($_REQUEST['page'])) { $currentPage = $_REQUEST['page']; } else { $currentPage = 1; } // pagination links $links = ""; // the first links // Display the first link separatly or not if($currentPage > 5) { // display the link separatly $links .= "<a href=\"" . $thisPage . $separator . "page=1\">1</a> ... "; if($currentPage < 4) { $strt = 2; } else { $strt = $currentPage-4; } for($i=$strt;$i<$currentPage;$i++) { $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> "; } } else { // display the link with the others $links .= ""; if($currentPage <= 4) { $strt = 1; } else { $strt = $currentPage-4; } for($i=$strt;$i<$currentPage;$i++) { $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> "; } } // display the current page 'link' $links .= "<b class=\"currentPage\">" . $currentPage . "</b> "; // Display the last link separatly or not if($currentPage < $nbrPages - 4) { // display the link separatly for($i=$currentPage+1;$i<$currentPage+4;$i++) { $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> "; } $links .= " ... <a href=\"" . $thisPage . $separator . "page=" . $nbrPages . "\">" . $nbrPages . "</a>"; } else { // display the link with the others $links .= ""; for($i=$currentPage+1;$i<$nbrPages+1;$i++) { $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> "; } } // Next and previous links if($currentPage == 1) { $nextLink = "<span style=\"color: rgb(170, 170, 170);\">Previous page</span>"; } else { $nextLink = "<a href=\"" . $thisPage . $separator . "page=" . ($currentPage - 1) . "\"><< Previous page</a>"; } if($currentPage == $nbrPages) { $previousLink = "<span style=\"color: rgb(170, 170, 170);\">Next page </span>"; } else { $previousLink = "<a href=\"" . $thisPage . $separator . "page=" . ($currentPage + 1) . "\">Next page >></a>"; } $paginationLinks = "<div style=\"font-size:11px;font-family:'Lucida Grande','Lucida Sans Unicode',Verdana,Arial,sans-serif\"> <div style=\"float:left;\">[ Pages: " . $links . " ]</div> <div style=\"float:right;\"> <sup></sup> " . $nextLink . " | " . $previousLink . " <sup></sup> </div> </div>"; } else { $paginationLinks = ""; } ?> Looking forward to learning what I'm doing wrong, thanks!
  5. Ok, I've got a script running, that allows users to submit one-liners, but I need to give them the option to add a nickname/moniker instead of just Anonymous if they aren't logged in. Here's the script I've got, but I'm stuck. <?php if($_POST['submit']){ if(!isset($_SESSION['user']['username'])) $username = "Anonymous"; else $username = $_SESSION['user']['username']; @$query = mysql_query("INSERT INTO `comps`(time,message,accepted,votes1,votes2,via,user,cat,numcoms,subcat) VALUES ('". time() ."', '". clean($_POST['comp']) ."', 'No', 0, 0, 'internet', '". $username ."', '". clean($_POST['cat']) ."', '0', '0')") or die(mysql_error()); echo "<strong>Your submission has been received!</strong> <script type=\"text/javascript\"><!-- setTimeout('Redirect()',1000); function Redirect() { opener.location.href='./'; window.close(); } // --></script>"; } else { echo ' <form action="" method="POST"> <table id="submissionform"> <tr><td class="input" colspan=5> <textarea onfocus="javascript:document.getElementById(\'commbox\').innerHTML=\'\';" name="comp" rows="13" height="75" cols="20" id="commbox">'. $names[4] .'</textarea> </td></tr> <tr><td> <select name="cat"> '; while($category = current($catlist)){ echo '<option value="'. key($catlist) .'">'. current($catlist) .'</option>'; next($catlist); } echo ' </select></td></tr> <tr><td><input type="submit" name="submit" value="Submit!" class="button_login2" /> </td></tr> </table> </form>'; } ?> Anyone able to tell me the next step to make this possible?
×
×
  • 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.