Jump to content

pocobueno1388

Members
  • Posts

    3,369
  • Joined

  • Last visited

    Never

Everything posted by pocobueno1388

  1. Also, just so everyone know, this is how the LIMIT works LIMIT start_from_row, number_of_rows_per_page
  2. AH! I am such an idiot. The reason I was getting duplicates is because I had duplicates in the DB! So I've been doing it right for a while now and didn't even know it, haha. So here is the FINAL working code (hopefully) <?php $username = $_SESSION['username']; $limit = 10; $query_count = "SELECT count(*) FROM goldies WHERE Sender='$username'"; $result_count = mysql_query($query_count) or die("Error: " . mysql_error()); $totalrows = mysql_result($result_count, 0, 0); $numofpages = ceil($totalrows/$limit); $rowsperpage = ceil($totalrows/$numofpages); if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; $offset = ($page - 1) * $rowsperpage; $query = "SELECT * FROM i_horses LIMIT $offset,10"; echo $query .'<br>'; $result = mysql_query($query) or die("Error: " . mysql_error()); //Exit if no records to display if (mysql_num_rows($result) == 0) { exit("Nothing to Display!"); } //Create the table of output data echo "<table>\n"; while ($row = mysql_fetch_array($result)) { //Alternate the row background color $bgcolor = ($bgcolor == "#737373")?'#737373':'#737373'; //Display the row of data echo "<tr bgcolor=\"$bgcolor\">\n"; echo " <td>".$row["Receiver"]."</td>\n"; echo " <td>".$row["Amount"]."</td>\n"; echo " <td>".$row["Date"]."</td>\n"; echo "</tr>"; } echo "</table>\n"; //Enable the Prev link if not first page if ($page > 1) { echo("<a href=\"creditshistory.php?page=".($page-1)."\">PREV</a> "); } else { echo("PREV "); } //Create links for each page in report for ($i=1; $i<=$numofpages; $i++) { if ($i == $page) { echo "$i "; } else { echo "<a href=\"creditshistory.php?page=$i\">$i</a> "; } } //Enable the Next link if not last page if ($page < $numofpages) { echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); } else { echo("NEXT"); } ?>
  3. I've got it to display the correct amount of rows now...but now it keeps repeating information on different pages >.>
  4. That will only show the first 10 records...that works for the first page, but we are trying to figure out how to make it work for all the others as well.
  5. Hold on...I'm trying to figure out how it works.
  6. I'm talking about for the second page...you need two parameters for LIMIT.
  7. See, the query says SELECT * FROM table LIMIT 10, 20 Yet it displays more than results 10-20. Am I confused about how LIMIT works? It should start at result 10, and end on result 20, right?
  8. phpSensei - LMAO, far from it. It's just a lot easier when you test the code out yourself rather than guessing over and over. With pagination it's almost impossible to help with unless you take it into your own hands, hah.
  9. RealDrift - You might want to double check. With me it worked on the first page, then it kept displaying more results than I wanted on the other pages...so make sure thats not happening to you.
  10. Try this <?php $username = $_SESSION['username']; $limit = 10; $query_count = "SELECT count(*) FROM goldies WHERE Sender='$username'"; $result_count = mysql_query($query_count) or die("Error: " . mysql_error()); $totalrows = mysql_result($result_count, 0, 0); $numofpages = ceil($totalrows/$limit); if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; $limitvalue = $page * $limit - ($limit); $limitrange = $limitvalue+$limit; $query = "SELECT * FROM goldies WHERE Sender='$username' LIMIT $limitvalue, $limitrange"; echo $query .'<br>'; $result = mysql_query($query) or die("Error: " . mysql_error()); //Exit if no records to display if (mysql_num_rows($result) == 0) { exit("Nothing to Display!"); } //Create the table of output data echo "<table>\n"; while ($row = mysql_fetch_array($result)) { //Alternate the row background color $bgcolor = ($bgcolor == "#737373")?'#737373':'#737373'; //Display the row of data echo "<tr bgcolor=\"$bgcolor\">\n"; echo " <td>".$row["Receiver"]."</td>\n"; echo " <td>".$row["Amount"]."</td>\n"; echo " <td>".$row["Date"]."</td>\n"; echo "</tr>"; } echo "</table>\n"; //Enable the Prev link if not first page if ($page > 1) { echo("<a href=\"creditshistory.php?page=".($page-1)."\">PREV</a> "); } else { echo("PREV "); } //Create links for each page in report for ($i=1; $i<=$numofpages; $i++) { if ($i == $page) { echo "$i "; } else { echo "<a href=\"creditshistory.php?page=$i\">$i</a> "; } } //Enable the Next link if not last page if ($page < $numofpages) { echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); } else { echo("NEXT"); } ?>
  11. I've almost got it working for you on my server. I will post the code as soon as I finish.
  12. Yes, you can incorporate PHP into CSS. The file must be named with a .php extension though. font-size: <?php echo $newsize; ?>%
  13. Just do this <?php if ($choice=="Banana") { $link1 = "http://www.mysite.com/1"; $link2 = "http://www.mysite.com/2"; } ?>
  14. <?php $query = mysql_query("SELECT SUM(fld1) as Yscore, SUM(fld2) as Gscore FROM table")or die(mysql_error()); $row = mysql_fetch_assoc($query); echo $row['Yscore']; echo $row['Gscore']; ?>
  15. Looks like a great site, I just wish I could get in =/
  16. EDIT: Wow, you beat me by fractions of a second, haha It's because your using a while looop. Do this <?php $query = "SELECT www FROM `adsys_banner` WHERE `shown` < `show` ORDER BY RAND() LIMIT 1"; $result = mysql_query ($query); $row = mysql_fetch_assoc($result); echo $row['www'].'<br>'; ?>
  17. Eh, it just looks bland. The header image is very boring and non-professional looking. It would look better if you made the tables a slightly lighter color than the rest of the site...it would add more depth to it.
  18. Try this tutorial...I looked through it and it actually used $_GET, I have no idea why the other one would assume you had register_globals off. http://www.tonymarston.net/php-mysql/pagination.html
  19. In your code your using "pagenum" as the page number, not "page"...so I don't even understand how your getting that as a URL. You also never define $page as $_GET['page']...
  20. I think it's because your getting a negative number (-4). Try changing $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; To <?php $first_l = ($pagenum - 1) * $page_rows; if ($first_l < 0) $max = '0, '.$page_rows; else $max = $first_l .', ' .$page_rows; ?>
  21. <?php $mins = range(0,59); foreach ($mins as $min){ if (strlen($min) <= 1) $min = '0'.$min; echo $min.'<br>'; } ?>
  22. Okay, you have two "limits" in there. Change this line $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; To $max = ($pagenum - 1) * $page_rows .',' .$page_rows;
  23. Okay, try changing this part of your code <?php //This is your query again, the same one... the only difference is we add $max into it $data_p = mysql_query("SELECT * FROM goldies WHERE Receiver='$username' LIMIT $max") or die(mysql_error()); ?> To <?php //This is your query again, the same one... the only difference is we add $max into it $data_q = "SELECT * FROM goldies WHERE Receiver='$username' LIMIT $max"; $data_p = mysql_query($data_q)or die(mysql_error().'<p>With query:<br>'.$data_q); ?> Post what it gives you
  24. Okay, I would definitely separate the start and end date into two different fields, and make them in the format of yyyy-mm-dd. make them the "date" type in the DB. Once you do that, then we can move on to the next step.
×
×
  • 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.