davinci Posted March 12, 2006 Share Posted March 12, 2006 Hi guys,I have an index.php page and I'm including the following script (called showplugs.php) that I put together for my news postings . I've including paging but I think I've messed up somewhere because I am getting the following error on my frontpage right over where the news articles start:Notice: Undefined index: id in .../public_html/showplugs.php on line 6The articles are there but so is the error. Here is the script:[code]<?phpinclude 'library/config.php';include 'library/opendb.php';$id = $_GET['id'];if ($id == "") {$rowsPerPage = 6;$pageNum = 1; if(isset($_GET['page'])){ $pageNum = $_GET['page'];}$offset = ($pageNum - 1) * $rowsPerPage; $query = "SELECT id, title, url, description, thumbnail, DATE_FORMAT(entry_date, '%M %D %Y') AS date FROM plugs ORDER BY id DESC LIMIT $offset, $rowsPerPage";$result = mysql_query($query) or die('Error, query failed');?><div class="title">Must Visit</div><p><?phpwhile($row = mysql_fetch_array($result)) { ?>.......more code here[/code]Thanks, and any help or comments appreciated!Addition:Also noticed that it is paging my index.php to page=1 but I don't want this. I want it to page within the index is that possible? Link to comment https://forums.phpfreaks.com/topic/4721-error-with-my-script-paging-related/ Share on other sites More sharing options...
wildteen88 Posted March 12, 2006 Share Posted March 12, 2006 The message you are recieving isn't an error but a just a message PHP throughs out when something isn't set. No the message is refering to the following:[code]$id = $_GET['id'];if ($id == "") {[/code]Notice where it says [i]$id = $_GET['id'][/i] this is ok but when you run your script and the id variable isn't passed over the url (index.php?id=1) then PHP will through a Notice message as $_GET['id'] isn't set! To get arround this simply change the two lines of code I posted above to the following:[code]$id = (isset($_GET['id']) ? $_GET['id'] : "");if (empty($id)) {[/code]The new code first checks whether $_GET['id'] is actually set. If it is then it'll assign $id the value of $_GET['id'] otherwise it'll set $id to nothing! The next line of code just checks whether the value of $id is empty Link to comment https://forums.phpfreaks.com/topic/4721-error-with-my-script-paging-related/#findComment-16697 Share on other sites More sharing options...
davinci Posted March 12, 2006 Author Share Posted March 12, 2006 [!--quoteo(post=354211:date=Mar 12 2006, 11:18 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Mar 12 2006, 11:18 AM) [snapback]354211[/snapback][/div][div class=\'quotemain\'][!--quotec--]The message you are recieving isn't an error but a just a message PHP throughs out when something isn't set. No the message is refering to the following:[code]$id = $_GET['id'];if ($id == "") {[/code]Notice where it says [i]$id = $_GET['id'][/i] this is ok but when you run your script and the id variable isn't passed over the url (index.php?id=1) then PHP will through a Notice message as $_GET['id'] isn't set! To get arround this simply change the two lines of code I posted above to the following:[code]$id = (isset($_GET['id']) ? $_GET['id'] : "");if (empty($id)) {[/code]The new code first checks whether $_GET['id'] is actually set. If it is then it'll assign $id the value of $_GET['id'] otherwise it'll set $id to nothing! The next line of code just checks whether the value of $id is empty[/quote]Ok, I'm going to try this. UPDATE: Works perfectly, thank you! Link to comment https://forums.phpfreaks.com/topic/4721-error-with-my-script-paging-related/#findComment-16717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.