Jump to content

Clinton

Members
  • Posts

    337
  • Joined

  • Last visited

Everything posted by Clinton

  1. Should I just use num_rows like this? $result = mysql_query("SELECT * FROM tablename"); $num_rows = mysql_num_rows($result); echo $num_rows;
  2. <a href="showad.php?id=<?php echo $id; ?>">Link Here!</a> Assuming you're querying your db, selecting the row, extracting the row, and just echoing the id to be retrieved by $_GET on the next page.
  3. I'm just trying to understand this as I read through the manual... How does num come out to 0 because I thought we were setting num in the query? I mean, it's getting the 1-9 somewhere so I thought that num was correct. And I didn't know count(*) was bad practice. Even after I go back and search it seems like that's the way to do it because you can pull the rest of your database information off of instead of running a new query. So I take it running two separate query's trumps?
  4. Anybody know where I could adopt a COUNT with at least a 2 grade education? After I get above 9 entries the count goes to 1. Then if I get into the twenties it goes to 2. It's like it's showing the first number but not the second or third or fourth. Any ideas? $query = "SELECT COUNT(*) as num FROM thelist WHERE username = '$username' ORDER BY notices"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; ?> <div id="breadcrumb"> <div class="module_breadcrumb"> <div> <div> <div> <span class="breadcrumbs pathway"> <?php echo $prefix;?> <?php echo $lname;?>, you currently have <? echo $total_pages['num'];?> notices.
  5. Thanks Premiso. It's amazing how one small thing can ruin it for the rest of the code. :-)
  6. $locked is correctly echoing yes. So why is this not working? if ($locked == "no"); { $query = mysql_query("SELECT crat FROM rat WHERE id = '1'"); $row = mysql_fetch_assoc($query); extract($row); $query = mysql_query("UPDATE employers SET uprat='$crat', locked='yes' WHERE username = '$uid'"); }
  7. I FIGURED IT OUT!!!!!!!!! YES! It was exactly what I thought it was. 5 hours later. LoL if (!$_POST['major'] == NULL) {unset($_SESSION['smajor']); $_SESSION['smajor'] = $_POST['major']; $smajor = $_POST['major']; } else $smajor = $_SESSION['smajor']
  8. I think I figured it out. I think it has to do with $smajor = $_POST['major']; which is called at the very beginning. When you go to the second page there is nothing posted so it's not calling that. Perhaps setting this as a session variable?
  9. I know very little about pagination. I was having problems with a different script earlier and tried another one. This script works up until the point you click on another link. The link is "http://localhost/project/search.php?page=2" but all it does is display a blank page, properly formatted. No information, no results, no nothing. How do I fix this? <?php session_start(); include 'connect/project.htm'; $smajor = $_POST['major']; ?> <html> <head> <title>Intranet - <?php echo $smajor ?> Workings</title> <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" /> <link rel="stylesheet" href="singlec.css" type="text/css" /> <link rel="stylesheet" href="constant.css" type="text/css" /> </head> <body> <div id="tail"> <div class="main"> <div id="top"> <div id="logo"> <a href="index.php"><img src="images/logo.png" alt="" /></a> </div> <div class="right"> <div id="topmenuposition"> </div> <div id="topmenu"> <div class="module_s10"> <div> <div> <div> <ul class="menu-nav"> <li class="item60"><a href="index.php"><span><em>Home</em></span></a></li> <li class="item29"><a href="aboutus.php"><span><em>About Us</em></span></a></li> <li class="item54"><a href="resources.php"><span><em>Resources</em></span></a></li> <li class="item55"><a href="press.php"><span><em>Press/Media</em></span></a></li> <li class="item56"><a href="contact.php"><span><em>Contact Us</em></span></a></li></ul> </div> </div> </div> </div> </div> </div> </div> <div id="header"> <div class="bg-right"> <div class="bg-left"> <div class="space"><img src="images/banner.png" alt="" /></div> </div> </div> </div> <div id="breadcrumb"> <div class="module_breadcrumb"> <div> <div> <div> <span class="breadcrumbs pathway"> </span> </div> </div> </div> </div> </div> <div id="wrapper"> <div class="indent"> <div id="right"> <?php include 'mmenu.php'; ?> <?php include 'linmenu.php'; ?> </div> <div id="content"> <div class="content-tl"> <div class="content-tr"> <div class="width"> <div id="boxes"> <div id="box1"> <div class="module"> <div class="first"> <div class="sec min-height"> <div class="box-indent"> <div class="width"> <h3><span><?php echo $smajor ?> Workings:</span></h3> <table width="95%" border="0" cellspacing="0" cellpadding="1" class="boxtitle"> <?php $tbl_name="thelist"; //your table name // How many adjacent pages should be shown on each side? $adjacents = 3; /* First get total number of rows in data table. If you have a WHERE clause in your query, make sure you mirror it here. */ $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE dmajorp = '$smajor' ORDER BY jposted"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; /* Setup vars for query. */ $targetpage = "search.php"; //your file name (the name of this file) $limit = 4; //how many items to show per page $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; //first item to display on this page else $start = 0; //if no page var is given, set start to 0 /* Get data. */ $sql = "SELECT * FROM $tbl_name WHERE dmajorp = '$smajor' ORDER BY jposted LIMIT $start, $limit"; $result = mysql_query($sql); /* Setup page vars for display. */ if ($page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 /* Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once. */ $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; //previous button if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\">« previous </a>"; else $pagination.= "<span class=\"disabled\">« previous </span>"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter </a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter </a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1 </a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage </a>"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1 </a>"; $pagination.= "<a href=\"$targetpage?page=2\">2 </a>"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter </a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1 </a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage </a>"; } //close to end; only hide early pages else { $pagination.= "<a href=\"$targetpage?page=1\">1 </a>"; $pagination.= "<a href=\"$targetpage?page=2\">2 </a>"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter </a>"; } } } //next button if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\">next » </a>"; else $pagination.= "<span class=\"disabled\">next »</span>"; $pagination.= "</div>\n"; } ?> <?php while($row = mysql_fetch_array($result)) {extract($row); ?> <thead> <tr><td> <a href="showad.php?id=<?php echo $id; ?>"><?php echo $jtitle; ?></a> - $<?php echo $salary; ?> </td></tr> </thead> <tr><td> <?php if (strlen($poverview) > 240) { $poverview = substr($poverview, 0, 239) . '...'; } echo $poverview; ?></td></tr> <tr><td><b><font color="lightgreen">Experience Desired: </font></b><?php echo $wexperience; ?> <b><font color="lightgreen">Location:</font></b> <?php echo $city; ?>, <?php echo $state; ?> <?php echo $zipcode; ?></td></tr> <tr><td><h3> </h3></td></tr> <?php } ?> </table> <?=$pagination?> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <div id="footer"> <div class="bg"> <div class="right-bg"> <div class="left-bg"> <div class="space"> © 2009 </div> </div> </div> </div> </div> </body> </html>
  10. Whatever the problem is it is here: <?php if (!(isset($pagenum))) { $pagenum = 1; } $sql = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted"; $rs = mysql_query($sql); $rows = mysql_num_rows($rs); $page_rows = 2; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last;} $max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; $sql_p = mysql_query("SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted $max"); if(mysql_num_rows($rs) > 0){ while($row = mysql_fetch_array($sql_p) or die(mysql_error())) { extract($row); ?> Because when I take it out everything else (i.e. the footer) shows up just fine. But i'm not getting any errors. w...t...h...???
  11. Lets say that I have a form that has a name and a bio, both of which echo just fine. Well, the bio is hellaciously long and I want to limit the amount of bio that is shown (they can click on the name to view the whole bio). What is the best way to do this? Currently I am using tables but from what I understand the <td> attribute will expand to the content inside regardless of size limitations.
  12. No, that didn't work either. But I just noticed that my footer isn't showing either so there's got to be something in there that's stopping the code period... ??? <div id="content"> <div class="content-tl"> <div class="content-tr"> <div class="width"> <div id="boxes"> <div id="box1"> <div class="module"> <div class="first"> <div class="sec min-height"> <div class="box-indent"> <div class="width"> <h3><span><?php echo $smajor ?> So:</span></h3> <table width="95%" border="0" cellspacing="0" cellpadding="1" class="boxtitle"> <?php if (!(isset($pagenum))) { $pagenum = 1; } $sql = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted"; $rs = mysql_query($sql); $rows = mysql_num_rows($rs); $page_rows = 2; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last;} $max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; $sql_p = mysql_query("SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted $max"); if(mysql_num_rows($rs) > 0){ while($row = mysql_fetch_array($sql_p) or die(mysql_error())) { extract($row); ?> <thead> <tr><td> <a href="showad.php?id=<?php echo $id ?>"><?php echo $title ?></a> - <?php echo $sse ?> - Required: <?php echo $wex ?> </td></tr> </thead> <tr><td> <?php echo $poverview ?><br /> </td></tr> <?php } ?> <?php } ///EVERYTHING BELOW THIS IS NOT SHOWING/// echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) {} else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) {} else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> </table> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <div id="footer"> <div class="bg"> <div class="right-bg"> <div class="left-bg"> <div class="space"> © 2009 </div> </div> </div> </div> </div> </body> </html>
  13. Ok, gotcha. Now it is limiting the search results correctly but it is not displaying the code on the bottom that allows me to go to the next page. Any ideas there? <table width="95%" border="0" cellspacing="0" cellpadding="1" class="boxtitle"> <?php if (!(isset($pagenum))) { $pagenum = 1; } $sql = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted"; $rs = mysql_query($sql); $rows = mysql_num_rows($rs); $page_rows = 2; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last;} $max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; $sql_p = mysql_query("SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jobposted $max"); if(mysql_num_rows($rs) > 0){ while($row = mysql_fetch_array($sql_p) or die(mysql_error())) { extract($row); ?> <thead> <tr><td> <a href="show.php?id=<?php echo $id ?>"><?php echo $jtitle ?></a> </td></tr> </thead> <tr><td> Blah Blah </td></tr> <?php } ///EVERYTHING BELOW THIS IS NOT SHOWING///?> <? echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) {} else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) {} else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> </table> <?php } ?>
  14. Yea, I just got that too. :-) Now I'm not getting those errors anymore but it's not working correctly and it has something to do with that $max variable. "The first thing we do is re-run our query from earlier, only with one slight change. This time we are including the $max variable to limit the query results to those that belong on our current page. After your query you would display your results as normal (using any formatting you wish.)" Their Example - $data_p = mysql_query("SELECT * FROM topsites $max") or die(mysql_error()); :-| Any idea about this?
  15. I think I figured out the first error. I changed: $rows = mysql_num_rows($sql); to $rows = mysql_num_rows($rs); But I'm still getting that second one... :-/
  16. Yea, I searched. Found nothing that helped. Yea, I put that in before I post but it gave me nothing. It just echoed the same error. No details.
  17. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 98 and 108 <?php if (!(isset($pagenum))) { $pagenum = 1; } $sql = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted"; $rs = mysql_query($sql); $rows = mysql_num_rows($sql); ///HERE/// $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last;} $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $sql_p = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted '$max'"; if(mysql_num_rows($rs) > 0){ while($row = mysql_fetch_array($sql_p)) ///AND HERE/// { extract($row); ?> I'm trying to paginate and then echo an else if there are no rows (hence the two statements. Not sure how to fix this.
  18. TY. I searched the threads but didn't find anything useful. Also, yea... you're right. The error was actually in my WHERE syntax. But I still needed the num_rows so I could express what was happening. Thank you.
  19. How can I change the code below so that if it returns 0 rows it doesn't error out and instead say something like "nothing found"? $sql = "SELECT * FROM thelist WHERE dp = $sr ORDER BY jp"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { extract($row);
  20. header("Location: ".$at."member.php"); That's exactly what I needed. I was pretty sure it needed the concoc... however you spell it I just couldn't figure out the right combination. Thank you. All $at is, is a variable that just determines what type of member they are. Just a letter.
  21. I'm trying to redirect my members to a page based upon what type of member they are. The variable echos just fine but no matter what I do I cannot get it to separate from the ' or the " or the \ or the / or the . or... well... you get my point... hopefully. How do I do this? if($row['active'] == NULL) { $_SESSION['user_id'] = $row['username']; $_SESSION['access_type'] = $row['accesstype']; $at = $row['accesstype']; $_SESSION['logged_in'] = TRUE; header("Location: $at'member.php'"); }else {
  22. I changed everything so the form submitted to a login.php form and not to itself. Problem solved.
  23. I stopped submitting the form to self and just created a form elsewhere. Problem solved.
  24. Ok, so I changed everything in between brackets but I can't get this to work properly. This form submits to itself. So, if the user come to the website it displays the login form (the third step in the script). If they submit the form but are currently not logged in they go to the second step. I had to take out header("Location: index.php"); because they were already being called. Then if the index.php page is called and they are logged in it is supposed to show them being logged in and the login box is supposed to disappear. Well... 1) It pulls up the page just fine if somebody is not logged in. 2) If I try to log in with my username only I get no errors. It looks like I just didn't do anything. 3) If I enter my username and password it doesn't find any rows so I get an extract row error but it does show the logged in portion of the script. Should I just use a seperate login.php form to submit this too instead of submitting form to self? Would that solve these problems? <?php } /// IF USER IS NOT LOGGED IN THEN CHECK TO SEE IF FORM IS SUBMITTED /// elseif (isset($_POST['login'])) { if($_POST['username']!='' && $_POST['password']!='') { $query = mysql_query('SELECT id, username, active FROM users WHERE username = "'.mysql_real_escape_string($_POST['username']).'" AND password = "'.mysql_real_escape_string(md5($_POST['password'])).'"'); if(mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); if($row['active'] == NULL) { $_SESSION['user_id'] = $row['id']; $_SESSION['logged_in'] = TRUE; }else { $error = 'Your membership was not activated. Please open the email that we sent and click on the activation link'; } } else { $error = 'Login failed !'; } } else { $error = 'Please user both your username and password to access your account'; } ?> <div class='module_s2'> <div class='first'> <div class='sec'> <h3>Login</h3> <div class='box-indent'> <div class='width'> <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="login" class="form-login"> <label> Username </label> <input type="text" name="username" class="inputbox"/> <label> Password </label> <input type="password" name="password" class="inputbox" /><br /> <input type="checkbox" name="remember" class="checkbox" value="yes" /> <label class="remember"> Remember Me </label> <input type="submit" name="login" class="button" value="login" /> <p> <a href="passwordreset.php"> Forgot your password? </a></p> <p> <a href="usernamefind.php"> Forgot your username?</a> </p> <p> No Account Yet? <a href="register.php"><br /> Create an account</a> </p> </form> </div> </div> </div> </div> </div> <?php } else { ?> <div class='module_s2'> <div class='first'> <div class='sec'> <h3>Login</h3> <div class='box-indent'> <div class='width'> <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="login" class="form-login"> <label> Username </label> <input type="text" name="username" class="inputbox"/> <label> Password </label> <input type="password" name="password" class="inputbox" /><br /> <input type="checkbox" name="remember" class="checkbox" value="yes" /> <label class="remember"> Remember Me </label> <input type="submit" name="login" class="button" value="login" /> <p> <a href="passwordreset.php"> Forgot your password? </a></p> <p> <a href="usernamefind.php"> Forgot your username?</a> </p> <p> No Account Yet? <a href="register.php"><br /> Create an account</a> </p> </form> </div> </div> </div> </div> </div> <?php } ?> <?php /////END LOGIN//// ?>
×
×
  • 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.