Alexhoward Posted March 17, 2008 Share Posted March 17, 2008 Hi guys i've just modified a paging script, and i'm getting an error. when you 1st visit the page you get the error: Notice: Undefined index: start in *** on line 68 and, Notice: Undefined index: p_f in *** on line 119 but when you press next, then back, it's gone..??? could someone please try and tell me why? here's the code: <?php require "config2.php"; // All database details will be included here $page_name="index.php"; // If you use this code with a different page ( or file ) name then change this $start= $_GET['start']; // To take care global variable if OFF if(!($start > 0)) { // This variable is set to zero for the first page $start = 0; } $eu = ($start -0); $limit = 12; // No of records to be shown per page. $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query2=" SELECT * FROM links "; $result2=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result2); /////// The variable nume above will store the total number of records in the table//// ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page/////////// $query=" SELECT * FROM links limit $eu, $limit "; $result=mysql_query($query); echo mysql_error(); echo "<link href='Images/bkgrnd.css' rel='stylesheet' type='text/css'><table width='100%' border='0'>"; // display the users in table $c = 0; while($row = mysql_fetch_array($result)) { $user2 = html_entity_decode($row['link']); if($c%3 == 0) echo "<tr>"; // If the counter has ticked 5 times, start a new row. echo "<td scope='row' height='150' width='25%' align='center' valign='middle' class='bkgrnd'>$user2</td>"; if($c%3 == 2) echo "</tr>"; // If we're drawing the 6th pic, end this row. $c++; } if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row echo "</table>"; // end the table ////////////////////////////// End of displaying the table with records //////////////////////// ///// Variables set for advance paging/////////// $p_limit=12; // This should be more than $limit and set to a value for whick links to be breaked $p_f= $_GET['p_f']; // To take care global variable if OFF if(!($p_f > 0)) { // This variable is set to zero for the first page $p_f = 0; } $p_fwd=$p_f+$p_limit; $p_back=$p_f-$p_limit; //////////// End of variables for advance paging /////////////// /////////////// Start the buttom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='80%'><tr><td align='left' width='20%'>"; if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align='left' width='10%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0 and ($back >=$p_f)) { print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align='right' width='10%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume and $this1 <($p_f+$p_limit)) { print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td><td align='right' width='20%'>"; if($p_fwd < $nume){ print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT</font></a>"; } echo "</td></tr></table>"; ?> Thank in advance!! p.s. here's the page if you wish to see the error in person www.everyonlinestore.co.uk Link to comment https://forums.phpfreaks.com/topic/96618-error-in-1st-time-visit-paging-script/ Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 It looks like it happens when the start and p_f variables aren't in the URL. Try adding this code near the top of the script: if (!isset($_GET['start'])) { $_GET['start'] = 0; } if (!isset($_GET['p_f'])) { $_GET['p_f'] = 0; } It'll check if those variables are set in the URL, and set them to default values if they're not set. Link to comment https://forums.phpfreaks.com/topic/96618-error-in-1st-time-visit-paging-script/#findComment-494434 Share on other sites More sharing options...
cooldude832 Posted March 17, 2008 Share Posted March 17, 2008 the site you are using is configed with a high level of error reporting thus when you try and use a variable undeclared ie. $_GET['start'] it produces a warning. Link to comment https://forums.phpfreaks.com/topic/96618-error-in-1st-time-visit-paging-script/#findComment-494437 Share on other sites More sharing options...
Alexhoward Posted March 17, 2008 Author Share Posted March 17, 2008 Nice one!! that seems to have done it could you check from your end to see if you see the error...? Thanks alot!! Link to comment https://forums.phpfreaks.com/topic/96618-error-in-1st-time-visit-paging-script/#findComment-494439 Share on other sites More sharing options...
Alexhoward Posted March 17, 2008 Author Share Posted March 17, 2008 how do i configure the error reporting....? sorry i'm new to this Link to comment https://forums.phpfreaks.com/topic/96618-error-in-1st-time-visit-paging-script/#findComment-494442 Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 The server executes all PHP code instead of your computer, so if it doesn't show the error for you it won't show it for anyone. Here's how you configure error reporting: http://ca3.php.net/error_reporting Link to comment https://forums.phpfreaks.com/topic/96618-error-in-1st-time-visit-paging-script/#findComment-494452 Share on other sites More sharing options...
Alexhoward Posted March 17, 2008 Author Share Posted March 17, 2008 OK Thanks Again! Link to comment https://forums.phpfreaks.com/topic/96618-error-in-1st-time-visit-paging-script/#findComment-494461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.