Jump to content

ChompGator

Members
  • Posts

    171
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ChompGator's Achievements

Member

Member (2/5)

0

Reputation

  1. Hey, Ok, well that makes sense, echo the query...but after thats done how would I alter the query - so that it only displays four news-article entries per-page. This is a first for doing pagination for me, so I appreciate all the help thanks!
  2. Nope, the script is running on the index.php it shouldn't be an include, Ill find it and remove it Heres the most updated code if you want to take a look <?php $con = mysql_connect("","","") or die('Could not connect: ' . mysql_error()); mysql_select_db("", $con); $result = mysql_query("SELECT * FROM elections"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id']." - ".$row['articlename']." -- ".$row['date']."<br/><br/> ".$row['description']."<br/><br/>"; } // end if ini_set ("display_errors", "1"); error_reporting(E_ALL); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM elections"; $result = mysql_query($sql) or die(mysql_error()); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 1; // 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 = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT id, number FROM elections LIMIT $offset, $rowsperpage"; $result = mysql_query($sql) or die(mysql_error()); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['id'] . " : " . $list['number'] . "<br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 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 " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // 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 " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?>
  3. Hey, thanks for your input so far, the script is only infact 100 lines long... So why its saying there is an error on line 242, is beyond me. Ive since gotten all the page numbers to appear and all the errors to disappear, the only thing Im fighting with now, is its still showing all the news articles in the database on one page, I need it to only show 4 per page, and right now its showing all the articles in the database on one page, then when you click to page two, it shows all the articles again, and so on.. But the page numbers are showing and they are working so thats a step forward
  4. Ok, I got it all fixed... The problem is now, its showing the page numbers ie: [1], [2] etc.. But its showing them like this: 3:3 4:4 5:5 And its still displaying all the news articles on one page, not 4 on each page. Thanks everyone fior all the input, any more help would be great
  5. Here is the new code, double-check it to make sure I did what you said properly... I made that replacement, but Im still getting the Fatal Error: <?php $con = mysql_connect("***","***","***") or die('Could not connect: ' . mysql_error()); mysql_select_db("legion", $con); $result = mysql_query("SELECT * FROM elections"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id']." - ".$row['articlename']." -- ".$row['date']."<br/><br/> ".$row['description']."<br/><br/>"; } // end if ini_set ("display_errors", "1"); error_reporting(E_ALL); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM elections"; $result = mysql_query($sql) or die(mysql_error()); $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 = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT id, number FROM elections LIMIT $offset, $rowsperpage"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['id'] . " : " . $list['number'] . "<br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 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 " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // 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 " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?>
  6. Ok, the errors are gone, the only error left is Fatal error: SQL in D:\hosting\member\264legion\site1\elections\index.php on line 242 PHP Fatal error: SQL in D:\hosting\member\264legion\site1\elections\index.php on line 242
  7. I fixed that portion, the error is still appearing though
  8. Ok, done, Now its displaying the news articles, but its not creating the pagination, here are the errors its returning: The weird thing is this script is only 100 lines, it doesn't go to 208 Notice: Undefined variable: conn in D:\hosting\member\264legion\site1\elections\index.php on line 208 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\hosting\member\264legion\site1\elections\index.php on line 208 Fatal error: SQL in D:\hosting\member\264legion\site1\elections\index.php on line 208 PHP Notice: Undefined variable: conn in D:\hosting\member\264legion\site1\elections\index.php on line 208 PHP Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\hosting\member\264legion\site1\elections\index.php on line 208 PHP Fatal error: SQL in D:\hosting\member\264legion\site1\elections\index.php on line 208
  9. Hey, Yeah I quickly read through the tutorial to get an idea of what it is that needs to be done...Then I applied it to my code..I believe error reporting is turned...But here is the code, if you want to check it out <?php $con = mysql_connect("","","") or die('Could not connect: ' . mysql_error()); mysql_select_db("legion", $con); $result = mysql_query("SELECT * FROM elections"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id']." - ".$row['articlename']." -- ".$row['date']."<br/><br/> ".$row['description']."<br/><br/>"; } // end if // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM elections"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $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 = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT id, number FROM elections LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['id'] . " : " . $list['number'] . "<br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 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 " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // 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 " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if ?>
  10. Hey there, Ok tried out this tutorial, customized it to my db...and applied it to my page, but its not displaying any news articles at all. Im not getting any errors from the script, my page is just coming up blank..
  11. Hello, I have a real simple question, I have a php script that displays news articles on a page...Im curious as to what would I add to this script to tell it after every 4 articles, add a new page - and Id just want it to start creating page numbers like: Page: [1], [2], [3] <?php $con = mysql_connect("***","***","****") or die('Could not connect: ' . mysql_error()); mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM elections"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id']." - ".$row['articlename']." -- ".$row['date']."<br/><br/> ".$row['description']."<br/><br/>"; } ?>< Any help is appreciated - thanks!
  12. Hello, I have a script, that retrieves a record from a MySQL database,but right now its displaying all the information it retrieves on one line...But I want it to display the ID and Article Name on one line, then the "Article" on the line below that...So How would I create like a line break after the article name, so the description displays below ID and Article Name Code: <?php $con = mysql_connect("","","") or die('Could not connect: ' . mysql_error()); mysql_select_db("legion", $con); $result = mysql_query("SELECT * FROM signalscadet"); while($row = mysql_fetch_assoc($result)){ echo "ID: ".$row['id'].", Article Name:".$row['articlename'] .", Date:".$row['date'].", Description:".$row['description']."<br/>"; } ?> Thanks,
  13. Hello, I recently developed a PHP script that allows users to upload files into a MySQL database. My next step is having a PHP page that shows the files by ID | File Name And the File Name should be linked to the file so when a user clicks on the file name, it starts downloading the file.... Ive tried doing it a few different ways, but none of my methods seem to work...I was wondering if anyone had any advice (my script is below, and the script that inserts the file into the db) This script does not link the file name to the file, I couldn't seem to get that part to work! Thanks Display.php <?php // Connects to your Database mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("Database_Name") or die(mysql_error()); $data = mysql_query("SELECT * FROM uploads") or die(mysql_error()); Print "<table border cellpadding=3>"; while($info = mysql_fetch_array( $data )) { Print "<tr>"; Print "<th>ID:</th> <td>".$info['id'] . "</td> "; Print "<th>File Name:</th> <td>".$info['filename'] . " </td></tr>"; } Print "</table>"; ?> Insert-Into-Db.php <?php mysql_connect("","",""); mysql_select_db(""); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); $id= mysql_insert_id(); print "<p>File ID: <b>$id</b><br>"; print "<p>File Name: <b>$form_data_name</b><br>"; print "<p>File Size: <b>$form_data_size</b><br>"; print "<p>File Type: <b>$form_data_type</b><p>"; print "To upload another file"; ?>
  14. You know what Duh, duh duh! lol - I should have noticed that, what silly mistake...You know sometimes it happens I appreciate your input, it certainly was useful
×
×
  • 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.