andy_b_1502 Posted July 3, 2012 Share Posted July 3, 2012 I was advised to make a new thread, the problem is i have a few error messages with this code: <?PHP include ('php only scripts/db.php'); error_reporting(E_ALL); ?> <?php $row = mysql_fetch_array($result); $what_services = "R"; $approved = $row['approved']; $query = "SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC"; $result = mysql_query($query); if(isset($_GET['pn'])){ $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); }else{ $pn = 1; } $itemsPerPage = 10; $lastPage = ceil($nr / $itemsPerPage); if($pn < 1){ $pn = 1; }else if($pn > $lastPage){ $pn = $lastPage; } // This creates the numbers to click in between the next and back buttons $centerPages = ""; // Initialize this variable $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } // This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; // Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax // $sql2 is what we will use to fuel our while loop statement below $sql2 = mysql_query("SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC $limit"); //////////////////////////////// END Adam's Pagination Logic /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $paginationDisplay = ""; // Initialize the pagination output variable // This code runs only if the last page variable is not equal to 1, if it is only 1 page we require no paginated links to display if ($lastPage != "1"){ // This shows the user what page they are on, and the total number of pages $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '<img src="images/clearImage.gif" width="48" height="1" alt="Spacer" />'; // If we are not on page 1 we can place the Back button if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; } // Lay in the clickable numbers display here between the Back and Next links $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; // If we are not on the very last page we can place the Next button if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; } } ///////////////////////////////////// END Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// while ( $row = mysql_fetch_array($result)) { $approved = $row['approved']; $what_services = $what_services; $result = mysql_query($sql2); SWITCH ($approved) { case 0: break; case 1: ?> <?PHP echo $row['company_name']; ?> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> <?PHP echo $row['company_name']; ?> <?PHP break; case 2: ?> <?PHP echo $row['company_name']; ?> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> <img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/> <?PHP break; case 3: ?> <a href="view00.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $row['company_name']; ?></a> <a href="view00.php?id=<?PHP echo $row['id']; ?>"> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] . "<br>mobile/other: " . $row['phone'] ?> </a> <a href="view00.php?id=<?PHP echo $row['id']; ?>"><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></a> <?PHP break; } } ?> the errors are: " Notice: Undefined variable: result in /hermes/bosoraweb023/b109/ipg.removalspacecom/test.php on line 138 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosoraweb023/b109/ipg.removalspacecom/test.php on line 138 Notice: Undefined variable: nr in /hermes/bosoraweb023/b109/ipg.removalspacecom/test.php on line 152 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosoraweb023/b109/ipg.removalspacecom/test.php on line 209" Can someone help please? Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 3, 2012 Share Posted July 3, 2012 That is not the entire code producing those errors. The code you posted above has only 134 lines, yet the very first error reported shows an error on line 138. So, I'm guessing you are including that fine in another or something. Anyway, look at the very top of your code <?php include ('php only scripts/db.php'); error_reporting(E_ALL); ?> <?php $row = mysql_fetch_array($result); See that last line? No where in the previous lines is $result ever defined. So, that explains the first couple of errors. Then the first place I see the variable $nr is here $lastPage = ceil($nr / $itemsPerPage); Again, nowhere before that line do I see it defined. As for the last request in your other post of about the page numbers. Yes you do force the $pn variable to be between 1 and $lastPage using this if($pn < 1){ $pn = 1; }else if($pn > $lastPage){ $pn = $lastPage; } But you were asking why you were seeing -1 and 0. And, I stated there that you were likely using completely different variables in your output. Well look here: $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; So, if the page was "1", $sub1 and $sub2 would have values of -1 and 0, respectively Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 3, 2012 Author Share Posted July 3, 2012 Yeah i just selected out the php to show you lot on here and left the html... so... i define result like this: $result = mysql_query($query); query is this: $query = "SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC"; so the full snippet looks like this now: <?php $result = mysql_query($query); $row = mysql_fetch_array($result); $what_services = "R"; $approved = $row['approved']; $query = "SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC"; what have i done wrong? it's not sinking in, sorry. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 3, 2012 Share Posted July 3, 2012 I'm not sure what to tell you. If all you left out was the HTML then you never define $result before the FIRST TIME that you use it. LATER int he code you define it and use it. But, on the 8th line of code you posted at the top you have the line $row = mysql_fetch_array($result); and $result had never been defined. I am going to offer the following advice/critiques: Your code is a mess. If it was structured in a more logical format the issues you face would be easier to find/fix You need to put more thought into your logic and the code you are creating. Remember YOU are the one who wrote the code and yet you can't seem to find/fix errors that PHP is providing you with line numbers. Quote Link to comment Share on other sites More sharing options...
haku Posted July 4, 2012 Share Posted July 4, 2012 You need to put more thought into your logic and the code you are creating. This isn't particularly constructive criticism. Telling him how he could do this would be helpful. I'd be amazed to find a programmer who didn't go through some confusion as to how to lay out code when starting out, and if we had been told to 'do better' at that time, it wouldn't have really helped at all. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 4, 2012 Share Posted July 4, 2012 You need to put more thought into your logic and the code you are creating. This isn't particularly constructive criticism. Telling him how he could do this would be helpful. I'd be amazed to find a programmer who didn't go through some confusion as to how to lay out code when starting out, and if we had been told to 'do better' at that time, it wouldn't have really helped at all. Well, your response wasn't particularly helpful to this problem at all. And, I believe it is constructive criticism. New programmers try to do too much without really thinking through what they are doing. Taking a few moments to jot down the logic of what needs to be built and doing one thing at a time would be much more productive. As to the OP, the errors he is getting are exceptionally informative compared to many PHP errors and I provided an explanation of why he was getting the errors he received. In fact, int he last post he completely changed the subject of the post to which I responded if the original question was resolved he should open a new thread. He then opens this thread with the exact same problem he opened the first one for. And, when a response is given it is completely ignored. I very clearly explained that the first two errors were due to the variable $result not being defined before it was attempted to be use. To which he replies so... i define result like this: $result = mysql_query($query); Which was after the line causing the error. This was also the problem that was pointed out in his previous thread. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 4, 2012 Author Share Posted July 4, 2012 Both of you are right, i didn't quite understand the define function and had to ask for help, yes i ignored the answers before because of this... I think it was constructive... In light of this, i have broken it down and read about define, I have made the first querie(s) error's correct and am getting it, however using the same way for query 2 ($sql2) i still have one error left to solve, this i don't understand how? it is a Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in error. This is the code with the error my fetch_array: $result = ('result'); $result = mysql_query("SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC $limit"); while ( $row = mysql_fetch_array($result)) { $approved = $row['approved']; $what_services = $what_services; The result resource is the query which is defined above it. Can you please explain why one works and the other doesn't? Just for reference the first query: $result = ('result'); $result = mysql_query("SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC"); $what_services = "R"; $row = mysql_fetch_array($result); $approved = $row['approved']; Thank you in advance Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 4, 2012 Share Posted July 4, 2012 Stop embedding the query string in the query execution function. Store it in a variable so you can echo or log it when it fails. Make sure the query executed successfully after calling the query execution function. Did it execute? Yes: make sure it returned a result, and if so act on the results set accordingly. If not, act accordingly No: log, or during development, display the error $query = "SELECT field FROM table WHERE somefield = somevalue"; if( $result = mysql_query($query) ) { if( mysql_num_rows($result) > 0 ) { while( $array = mysql_fetch_assoc($result) ) { // loop if multiple records are possible/expected //display the results } } else { // no results, may want to display a note to the user to that effect } } else { // The query failed to execute. This format is best for logging errors, but is OK for displaying them, too. trigger_error( "Failed DB query in " . __FILE__ . " reported at " . __LINE__ . PHP_EOL . $query . PHP_EOL . mysql_error() ); } Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 5, 2012 Author Share Posted July 5, 2012 Okay thanks, changed that but it displayed ALL my results not 10 per page? doesn't $limit do that? Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 Post the exact code (in full) that you have now. This thread needs clarification on what we are working with currently. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 5, 2012 Author Share Posted July 5, 2012 everyone goes mental when i do this but here goes: <?PHP include ('php only scripts/db.php'); error_reporting(E_ALL); ?> <!DOCTYPE html> <head> <title>Removals | Removalspace.com</title> <style type="text/css"> <!-- body { background-image: url(styles/downloaded%20styles/todo/todo/images/bg.png); } --> </style> <link href="styles/downloaded styles/todo/todo/css/style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="styles/downloaded styles/todo/todo/css/style9.css" /> <link rel="stylesheet" type="text/css" href="styles/downloaded styles/todo/todo/css/demo.css" /> <link href='http://fonts.googleapis.com/css?family=Terminal+Dosis' rel='stylesheet' type='text/css' /> <style type="text/css"> <!-- .Stile1 {color: #333333} .aa { font-size: 13px; } #container header nav #logo p .cursive { font-size: 9px; } #apDiv1 { position:absolute; width:466px; height:24px; z-index:1; left: 585px; top: 191px; } --> </style> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-31656176-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <style type="text/css"> <!-- .pagNumActive { color: #000; border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px; } .paginationNumbers a:link { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } .paginationNumbers a:visited { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } .paginationNumbers a:hover { color: #000; text-decoration: none; border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px; } .paginationNumbers a:active { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } #apDiv2 { position:absolute; width:587px; height:40px; z-index:1; left: 261px; top: 541px; } --> </style> </head> <body> <!--start container --> <div id="container"> <header> <nav> <div id="apDiv1"><span class="cursive">Upagrade Now For Your Logo Here!</span></div> <div id="logo"> <p><a href="index.php"><img src="images/header2.png" alt="Logo here" width="219" height="161" /></a></p> <p><span class="cursive">Company Logo's/Upgraded UK Listings Shown Below (enter your postcode for your area)</span></p> <p> </p> <p>click <a href="register00.php">here</a> to add your company</p> </div> <div id="search-top"><img src="styles/downloaded styles/todo/todo/images/quote-right.png" alt="images" /><span class="cursive">Enter your postcode here</span><img src="styles/downloaded styles/todo/todo/images/quote-left.png" alt="images" /> <form method="post" action="search.php"> <input type="text" name="strSearch" onFocus="if(this.value=='Search Area')this.value='';" onBlur="if(this.value=='')this.value='Search Area';" value="Search Area" id="search-field"/> <input type="submit" value="" id="search-btn"/> </form> </div> <div id="nav_social"><a href="http://www.facebook.com/pages/Removalspace/181434181939226"><img src="styles/downloaded styles/todo/todo/images/facebook_32.png" alt="Become a fan" width="32" height="32" /></a><a href="#"><img src="styles/downloaded styles/todo/todo/images/twitter_32.png" alt="Follows on Twitter" /></a><a href="id=183427956&trk=tab_pro"><img src="styles/downloaded styles/todo/todo/images/linkedin_32.png" alt="Linked in" /></a><a href="contact.php"><img src="styles/downloaded styles/todo/todo/images/email_32.png" alt="Contact" width="32" height="32" /></a><!-- Place this tag where you want the +1 button to render --> <g:plusone size="small" annotation="inline"></g:plusone> <!-- Place this render call where appropriate --> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script></div> </nav> </header> <p><figure><a href="removals.php">Search Removals</a></figure> |</p> <p><figure><a href="storage.php">Search Storage</a></figure> |</p> <p><figure><a href="register00.php">Add Listing</a></figure> |</p> <p><figure><a href="about.php">About</a></figure> |</p> <p><figure><a href="contact.php">Contact</a></figure> |</p> <p><figure><a href="login00.php">Login</a></figure></p> <div class="content"> <!--star main --> <main> <?php $query = "SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC"; if ($result = mysql_query($query)); $what_services = "R"; $row = mysql_fetch_array($result); $approved = $row['approved']; if(isset($_GET['pn'])){ $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); }else{ $pn = 1; } $itemsPerPage = 10; $nr = ('nr'); $lastPage = ceil($nr / $itemsPerPage); if($pn < 1){ $pn = 1; }else if($pn > $lastPage){ $pn = $lastPage; } // This creates the numbers to click in between the next and back buttons $centerPages = ""; // Initialize this variable $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } // This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; // Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax // $sql2 is what we will use to fuel our while loop statement below $sql2 = mysql_query("SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC $limit"); //////////////////////////////// END Adam's Pagination Logic /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $paginationDisplay = ""; // Initialize the pagination output variable // This code runs only if the last page variable is not equal to 1, if it is only 1 page we require no paginated links to display if ($lastPage != "1"){ // This shows the user what page they are on, and the total number of pages $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '<img src="images/clearImage.gif" width="48" height="1" alt="Spacer" />'; // If we are not on page 1 we can place the Back button if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; } // Lay in the clickable numbers display here between the Back and Next links $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; // If we are not on the very last page we can place the Next button if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; } } ///////////////////////////////////// END Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $sql2 = "SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC $limit"; if( $result = mysql_query($query)); while ( $row = mysql_fetch_array($result)) { $approved = $row['approved']; $what_services = $what_services; SWITCH ($approved) { case 0: break; case 1: ?> <div class="abox"> <figure> <fcapion> <p> </p> <p><?PHP echo $row['company_name']; ?></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> </fcaption> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <h1><?PHP echo $row['company_name']; ?></h1> <p> </p> </figure> </div> <p> <?PHP break; case 2: ?> </p> <div class="abox"> <figure> <fcapion> <p> </p> <p><?PHP echo $row['company_name']; ?> </p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> </fcaption> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <h1><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></h1> <p> </p> </figure> </div> <?PHP break; case 3: ?> <div class="abox"> <figure> <fcapion> <p> </p> <p><a href="view00.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $row['company_name']; ?></a></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <p><a href="view00.php?id=<?PHP echo $row['id']; ?>"> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] . "<br>mobile/other: " . $row['phone'] ?> </a></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> <h1>click logo to read more...<a href="view00.php?id=<?PHP echo $row['id']; ?>"><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></a></h1> </figure> </div> <p> </p> <p> <?PHP break; } } ?> </p> </main> <!--end main --> <!--start middle --> </div> <!--end middle --> <!--start footer --> <footer> <div style="margin-left 58px, margin-right 58px, padding 6px border #999, 1px solid"><?php echo $paginationDisplay;?></div> <div id="footer"> <div id="footerleft"> <h2>removalspace</h2> <ul> <li><a href="contact.php">Contact</a></li> <li><a href="about.php">About Us</a></li> <li><a href="other-info.php">Other</a></li> <li></li> </ul> </div> <div id="footermiddle"> <h2>User Comments</h2> <ul> <li><a href="#">Read Reviews</a></li> <li><a href="contact.php">Leave A Comment</a></li> <li><a href="#">Read Blogs</a></li> <li></li> </ul> </div> <div id="footerright"> <h2>our mission</h2> <ul> <li><a href="about.php">Who Are We?</a></li> <li><a href="about.php">What We Do</a></li> <li><a href="about.php">Our Mission</a></li> <li></li> </ul> </div> <details> <summary> <p><a href="http://www.imediacreatives.it" target="_blank">Imediacreatives.it</a><a href="http://freehtml5templates.com">Designers</a> Copyright © removalspace.com -2012.</p></summary><p></p> </details> </div> </footer> <!--end footer --> </div> <!--end container --> </body> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> </html> Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 6, 2012 Share Posted July 6, 2012 Try these changes, I commented up what I changed and why. <?PHP include ('php only scripts/db.php'); error_reporting(E_ALL); ?> <!DOCTYPE html> <head> <title>Removals | Removalspace.com</title> <style type="text/css"> <!-- body { background-image: url(styles/downloaded%20styles/todo/todo/images/bg.png); } --> </style> <link href="styles/downloaded styles/todo/todo/css/style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="styles/downloaded styles/todo/todo/css/style9.css" /> <link rel="stylesheet" type="text/css" href="styles/downloaded styles/todo/todo/css/demo.css" /> <link href='http://fonts.googleapis.com/css?family=Terminal+Dosis' rel='stylesheet' type='text/css' /> <style type="text/css"> <!-- .Stile1 {color: #333333} .aa { font-size: 13px; } #container header nav #logo p .cursive { font-size: 9px; } #apDiv1 { position:absolute; width:466px; height:24px; z-index:1; left: 585px; top: 191px; } --> </style> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-31656176-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <style type="text/css"> <!-- .pagNumActive { color: #000; border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px; } .paginationNumbers a:link { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } .paginationNumbers a:visited { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } .paginationNumbers a:hover { color: #000; text-decoration: none; border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px; } .paginationNumbers a:active { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } #apDiv2 { position:absolute; width:587px; height:40px; z-index:1; left: 261px; top: 541px; } --> </style> </head> <body> <!--start container --> <div id="container"> <header> <nav> <div id="apDiv1"><span class="cursive">Upagrade Now For Your Logo Here!</span></div> <div id="logo"> <p><a href="index.php"><img src="images/header2.png" alt="Logo here" width="219" height="161" /></a></p> <p><span class="cursive">Company Logo's/Upgraded UK Listings Shown Below (enter your postcode for your area)</span></p> <p> </p> <p>click <a href="register00.php">here</a> to add your company</p> </div> <div id="search-top"><img src="styles/downloaded styles/todo/todo/images/quote-right.png" alt="images" /><span class="cursive">Enter your postcode here</span><img src="styles/downloaded styles/todo/todo/images/quote-left.png" alt="images" /> <form method="post" action="search.php"> <input type="text" name="strSearch" onFocus="if(this.value=='Search Area')this.value='';" onBlur="if(this.value=='')this.value='Search Area';" value="Search Area" id="search-field"/> <input type="submit" value="" id="search-btn"/> </form> </div> <div id="nav_social"><a href="http://www.facebook.com/pages/Removalspace/181434181939226"><img src="styles/downloaded styles/todo/todo/images/facebook_32.png" alt="Become a fan" width="32" height="32" /></a><a href="#"><img src="styles/downloaded styles/todo/todo/images/twitter_32.png" alt="Follows on Twitter" /></a><a href="id=183427956&trk=tab_pro"><img src="styles/downloaded styles/todo/todo/images/linkedin_32.png" alt="Linked in" /></a><a href="contact.php"><img src="styles/downloaded styles/todo/todo/images/email_32.png" alt="Contact" width="32" height="32" /></a><!-- Place this tag where you want the +1 button to render --> <g:plusone size="small" annotation="inline"></g:plusone> <!-- Place this render call where appropriate --> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script></div> </nav> </header> <p><figure><a href="removals.php">Search Removals</a></figure> |</p> <p><figure><a href="storage.php">Search Storage</a></figure> |</p> <p><figure><a href="register00.php">Add Listing</a></figure> |</p> <p><figure><a href="about.php">About</a></figure> |</p> <p><figure><a href="contact.php">Contact</a></figure> |</p> <p><figure><a href="login00.php">Login</a></figure></p> <div class="content"> <!--star main --> <main> <?php /************************************CHANGES IN THIS BLOCK ********************************************************/ $nr = 0; //default for number of rows. $query = "SELECT COUNT(*) FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC"; //changed to a count query. if ($result = mysql_query($query)) { //added brackets, as the fetch row resided outside of the if clause, making no sense. $what_services = "R"; //No idea what this is, as it isn't used anywhere, accept to reference itself on line 215, and in an empty switch on line 220. $row = mysql_fetch_row($result); //changed to a fetch row (faster). $nr = $row[0]; //changed $nr to get the number of rows. } if(isset($_GET['pn'])){ $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); //you could simply typecast by using (int)$_GET['pn']; but isn't a problem the way you are doing. }else{ $pn = 1; } $itemsPerPage = 10; //$nr = ('nr'); //I have no Idea why you are passing a string to $nr, as you are using it in the ceil function which requires NUMERICAL data. $lastPage = ceil($nr / $itemsPerPage); /********************************CHANGES IN THE BLOCK ABOVE************************************************/ if($pn < 1){ $pn = 1; }else if($pn > $lastPage){ $pn = $lastPage; } // This creates the numbers to click in between the next and back buttons $centerPages = ""; // Initialize this variable $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } // This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; // Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax // $sql2 is what we will use to fuel our while loop statement below $sql2 = mysql_query("SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC $limit"); //////////////////////////////// END Adam's Pagination Logic /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $paginationDisplay = ""; // Initialize the pagination output variable // This code runs only if the last page variable is not equal to 1, if it is only 1 page we require no paginated links to display if ($lastPage != "1"){ // This shows the user what page they are on, and the total number of pages $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '<img src="images/clearImage.gif" width="48" height="1" alt="Spacer" />'; // If we are not on page 1 we can place the Back button if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; } // Lay in the clickable numbers display here between the Back and Next links $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; // If we are not on the very last page we can place the Next button if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; } } ///////////////////////////////////// END Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $sql2 = "SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC $limit"; if( $result = mysql_query($query)); while ( $row = mysql_fetch_array($result)) { $approved = $row['approved']; $what_services = $what_services; SWITCH ($approved) { case 0: break; case 1: ?> <div class="abox"> <figure> <fcapion> <p> </p> <p><?PHP echo $row['company_name']; ?></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> </fcaption> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <h1><?PHP echo $row['company_name']; ?></h1> <p> </p> </figure> </div> <p> <?PHP break; case 2: ?> </p> <div class="abox"> <figure> <fcapion> <p> </p> <p><?PHP echo $row['company_name']; ?> </p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> </fcaption> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <h1><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></h1> <p> </p> </figure> </div> <?PHP break; case 3: ?> <div class="abox"> <figure> <fcapion> <p> </p> <p><a href="view00.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $row['company_name']; ?></a></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <p><a href="view00.php?id=<?PHP echo $row['id']; ?>"> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] . "<br>mobile/other: " . $row['phone'] ?> </a></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> <h1>click logo to read more...<a href="view00.php?id=<?PHP echo $row['id']; ?>"><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></a></h1> </figure> </div> <p> </p> <p> <?PHP break; } } ?> </p> </main> <!--end main --> <!--start middle --> </div> <!--end middle --> <!--start footer --> <footer> <div style="margin-left 58px, margin-right 58px, padding 6px border #999, 1px solid"><?php echo $paginationDisplay;?></div> <div id="footer"> <div id="footerleft"> <h2>removalspace</h2> <ul> <li><a href="contact.php">Contact</a></li> <li><a href="about.php">About Us</a></li> <li><a href="other-info.php">Other</a></li> <li></li> </ul> </div> <div id="footermiddle"> <h2>User Comments</h2> <ul> <li><a href="#">Read Reviews</a></li> <li><a href="contact.php">Leave A Comment</a></li> <li><a href="#">Read Blogs</a></li> <li></li> </ul> </div> <div id="footerright"> <h2>our mission</h2> <ul> <li><a href="about.php">Who Are We?</a></li> <li><a href="about.php">What We Do</a></li> <li><a href="about.php">Our Mission</a></li> <li></li> </ul> </div> <details> <summary> <p><a href="http://www.imediacreatives.it" target="_blank">Imediacreatives.it</a><a href="http://freehtml5templates.com">Designers</a> Copyright © removalspace.com -2012.</p></summary><p></p> </details> </div> </footer> <!--end footer --> </div> <!--end container --> </body> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> </html> Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted July 6, 2012 Share Posted July 6, 2012 To get back to Psycho's comments about design, you're making the classic beginner mistake of embedding PHP code within your HTML. Well-formed scripts do all of the PHP processing upfront, which separates the brains of the script from its output, much like how CSS and HTML should also be separate. By keeping each component separate, you make it far easier to debug, edit, and maintain your code. A rough sketch of how you should write scripts: Pure PHP to handle requests, form submissions, db queries, etc. Results are stored in variables. l l l V About 90%-95% pure HTML, with just enough PHP to to display the values you stored in the variables in step 1. You should limit yourself to echo, if/else, and simple loops. Nothing else. Output should always be fairly brainless. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 6, 2012 Author Share Posted July 6, 2012 Thanks jcbones... I noticed the page numbers are correct in the browser, i have this error: Notice: Undefined index: approved in /hermes/bosoraweb023/b109/ipg.removalspacecom/test.php on line 215 which is referring to this line: $approved = $row['approved']; I need the approved, as it only shows user's that have been approved by admin and the "what services" splits the results of the table to display only certain things again? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2012 Share Posted July 6, 2012 ^^^ That error is because the mysql_query() statement ISN'T executing the correct sql query statement. The sql statement is in $sql2, but the mysql_query() statement isn't using that particular variable. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 6, 2012 Author Share Posted July 6, 2012 ahh i see, thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.