imatt Posted February 22, 2015 Share Posted February 22, 2015 (edited) I am working on a database site with a search facility. At the moment all of our courses are listed in alphabetical order on this page (code shown below) with search facility at the top. However when we put in a criteria and click search it just returns a page with no courses listed....please help! I have pasted the code for the page we get redirected to below the first code. <?php include("admin/inc/db.php"); session_start(); include("header.php"); $q=$_SESSION['user_id']; $user_type= $_SESSION['user_type']; $sql1 = "SELECT * FROM `wp_provider_cource` where status='1'"; $query1= mysql_query($sql1); $count1= mysql_num_rows($query1); ?> <?php ////////////// QUERY THE MEMBER DATA INITIALLY LIKE YOU NORMALLY WOULD $sql = mysql_query("SELECT id, course_img, cource_name, sub_sector, cource_level, skill_sector, username FROM wp_provider_cource ORDER BY cource_name, cource_level"); //////////////////////////////////// Adam's Pagination Logic //////////////////////////////////////////////////////////////////////// $nr = mysql_num_rows($sql); // Get total of Num rows from the database query if (isset($_GET['pn'])) { // Get pn from URL vars if it is present $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new) //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated) } else { // If the pn URL variable is not present force it to be value of page number 1 $pn = 1; } //This is where we set how many database items to show on each page $itemsPerPage = 6; // Get the value of the last page in the pagination result set $lastPage = ceil($nr / $itemsPerPage); // Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage if ($pn < 1) { // If it is less than 1 $pn = 1; // force if to be 1 } else if ($pn > $lastPage) { // if it is greater than $lastpage $pn = $lastPage; // force it to be $lastpage's value } // This creates the numbers to click in between the next and back buttons // This section is explained well in the video that accompanies this script $centerPages = ""; $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 `id`, `course_img`, `cource_name`, `sub_sector`, `cource_level`,`skill_sector`, `username` FROM `wp_provider_cource` where `status`='1' ORDER BY cource_name, cource_level $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 ot 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. ' '; // 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 /////////////////////////////////////////////////////////////////////////// // Build the Output Section Here ?> <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; } .courseheaderdatabase { font-size: 21px; font-weight: bold; color: #FFF; margin-left: 28px; float: left; width: 250px; margin-top: 10px; } --> </style> <div class="wrapper_contaoner"> <section class='stripe'> <div class='container'> <!-- Begin Stripe stripe_container fullwidth --> <section class='main'> <div id="buddypress"> <div style="width:100%; float:left; height:40px;"></div> <div class="col-md-9 col-sm-8"> <form action="cource_search.php" method="post" id="course-directory-form" class="dir-form" name"searchform"> <div class="item-list-tabs" role="navigation"> <ul> <li class="selected" id="course-all"><a href="#">Total Courses Available: <span><?php echo $count1;?></span></a></li> <div class="courseheaderdatabase">Our Course Database: </div> </ul> </div> <div class="item-list-tabs" id="subnav" role="navigation"> <ul> <li> <div id="group-dir-search" class="dir-search" role="search"> <label> <input name="s" id="groups_search" placeholder="Search ..." type="text"> </label> <input id="course_search_submit" name="course_search_submit" value="Search" type="submit"> </div> </li> </ul> </div> </form> <div id="course-dir-list" class="course dir-list"> <!--<div id="pag-top" class="pagination"> <div class="pag-count" id="course-dir-count-top"> Viewing page 1 of 3</div> <div class="pagination-links" id="course-dir-pag-top"> <span class="page-numbers current">1</span> <a class="page-numbers" href="#">2</a> <a class="page-numbers" href="#">3</a> <a class="next page-numbers" href="#">→</a></div> </div>--> <ul id="course-list" class="item-list" role="main"> <?php while($row = mysql_fetch_array($sql2)){ $skill_sector = $row["skill_sector"]; $cource_name = $row["cource_name"]; $sub_sector = $row["sub_sector"]; $cource_level = $row["cource_level"]; $id = $row["id"]; $username = $row["username"]; ?> <li itemscope="" itemtype="http://data-vocabulary.org/Review-aggregate"> <div class="item"> <div class="item-title" itemprop="itemreviewed"><a href="view_cource_details.php?id=<?php echo $id; ?>"><?php echo $cource_name; ?></a></div> <div class="item-desc"> <p><b>Skill Sector:</b> <?php echo $skill_sector; ?></p> <p><b>Sub Sector:</b> <?php echo $sub_sector; ?></p> <?php echo $cource_level; ?></p> </div> <div class="item-credits"><a href="view_cource_details.php?id=<?php echo $id; ?>"><input type="button" value="Find Out More Information" /></a> <?php if($user_type==1) { ?> <a href="pdf.php?id=<?php echo $id; ?>"><input type="button" value="Download" /></a> <a href="edit_coures.php?id=<?php echo $id; ?>&type=edit"><input type="button" value="Edit" /></a> <?php } ?> </div> <div class="item-action"></div> </div> </li> <?php } ?> <div style="margin-left:58px; float:right; padding:6px; background-color:#FFF; "><?php echo $paginationDisplay; ?></div> </ul> </div> </div> <div class="col-md-3 col-sm-4"> <div class="widget"> <h4 class="widget_title">Recent Courses:</h4> <ul class="slides"> <?php $upcome_cources="SELECT * FROM `wp_provider_cource` where status='1' ORDER BY `wp_provider_cource`.`id` DESC limit 0,4"; $upcome_query= mysql_query($upcome_cources); while($upcome_fetch= mysql_fetch_array($upcome_query)) { ?> <li style="width: 263px; float: left; display: block;" class="clone"> <div class="block courseitem"> <div class="block_content"> <h4 class="block_title"><a href="view_cource_details.php?id=<?php echo $upcome_fetch['id'];?>" title="Basic of Nature Photography"><?php echo $upcome_fetch['cource_name'];?></a></h4> <div class="item-desc"> <?php echo $upcome_fetch['skill_sector'];?><br/> <?php echo $upcome_fetch['sub_sector'];?><br/> <?php echo $upcome_fetch['cource_level'];?><br/> <a href="view_cource_details.php?id=<?php echo $upcome_fetch['id'];?>"><input type="button" value="More Info..." /></a> </div> <span class="clear"></span> </div> </div> </li> <?php } ?> </ul> </div> </div> </div> </section> <!-- End Stripestripe_container fullwidth --> </div> </section> <div class="clr"></div> </div> <?php include("footer.php");?> _____________________________________________________________________________________________________ <?php include("admin/inc/db.php"); session_start(); include("header.php"); $q=$_SESSION['user_id']; $user_type= $_SESSION['user_type']; $sql1 = "SELECT * FROM `wp_provider_cource` where status='1'"; $query1= mysql_query($sql1); $count1= mysql_num_rows($query1); $search=$_REQUEST['s']; ?> <?php ////////////// QUERY THE MEMBER DATA INITIALLY LIKE YOU NORMALLY WOULD //////////////////////////////////// Adam's Pagination Logic //////////////////////////////////////////////////////////////////////// $nr = mysql_num_rows($sql); // Get total of Num rows from the database query if (isset($_GET['pn'])) { // Get pn from URL vars if it is present $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new) //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated) } else { // If the pn URL variable is not present force it to be value of page number 1 $pn = 1; } //This is where we set how many database items to show on each page $itemsPerPage = 5; // Get the value of the last page in the pagination result set $lastPage = ceil($nr / $itemsPerPage); // Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage if ($pn < 1) { // If it is less than 1 $pn = 1; // force if to be 1 } else if ($pn > $lastPage) { // if it is greater than $lastpage $pn = $lastPage; // force it to be $lastpage's value } // This creates the numbers to click in between the next and back buttons // This section is explained well in the video that accompanies this script $centerPages = ""; $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 `id`, `cource_name`, `username` FROM `wp_provider_cource` WHERE `status`='1' AND (`cource_name` LIKE '%".$query."%') ORDER BY cource_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 ot 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. ' '; // 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 /////////////////////////////////////////////////////////////////////////// // Build the Output Section Here ?> <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; } --> </style> <div class="wrapper_contaoner"> <section class='stripe'> <div class='container'> <!-- Begin Stripe stripe_container fullwidth --> <section class='main'> <div id="buddypress"> <div style="width:100%; float:left; height:40px;"></div> <div class="col-md-9 col-sm-8"> <form action="" method="post" id="course-directory-form" class="dir-form"> <div class="item-list-tabs" role="navigation"> <ul> <li class="selected" id="course-all"><a href="#">All Courses <span><?php echo $count1;?></span></a></li> </ul> </div> <div class="item-list-tabs" id="subnav" role="navigation"> <ul> <li> <div id="group-dir-search" class="dir-search" role="search"> <label> <input name="s" id="groups_search" placeholder="Search ..." type="text"> </label> <input id="course_search_submit" name="course_search_submit" value="Search" type="submit"> </div> </li> </ul> </div> </form> <div id="course-dir-list" class="course dir-list"> <!--<div id="pag-top" class="pagination"> <div class="pag-count" id="course-dir-count-top"> Viewing page 1 of 3</div> <div class="pagination-links" id="course-dir-pag-top"> <span class="page-numbers current">1</span> <a class="page-numbers" href="#">2</a> <a class="page-numbers" href="#">3</a> <a class="next page-numbers" href="#">→</a></div> </div>--> <ul id="course-list" class="item-list" role="main"> <?php while($row = mysql_fetch_array($sql2)){ $cource_name = $row["cource_name"]; $cource_level = $row["cource_level"]; $skill_sector = $row["skill_sector"]; $sub_sector = $row["sub_sector"]; $id = $row["id"]; $username = $row["username"]; ;?> <div class="item"> <div class="item-title" itemprop="itemreviewed"><a href="view_cource_details.php?id=<?php echo $id; ?>"><?php echo $cource_name; ?></a></div> <div class="item-desc"> <p><?php echo $cource_name; ?></p> <p><?php echo $cource_level; ?></p> <p><?php echo $skill_sector; ?></p> <p><?php echo $sub_sector; ?></p> </div> <div class="item-credits"><a href="view_cource_details.php?id=<?php echo $id; ?>"><input type="button" value="Read More" /></a> <?php if($user_type==1) { ?> <a href="edit_coures.php?id=<?php echo $id; ?>&type=edit"><input type="button" value="Edit" /></a> <?php } ?> </div> <div class="item-instructor"> <div class="instructor_course"> </div> </div> <div class="item-action"></div> </div> <div class="clear"></div> </li> <?php } ?> <div style="margin-left:58px; float:right; padding:6px; background-color:#FFF; "><?php echo $paginationDisplay; ?></div> </ul> </div> </div> <div class="col-md-3 col-sm-4"> <div class="widget"> <h4 class="widget_title">Latest Course</h4> <ul class="slides"> <?php $upcome_cources="SELECT * FROM `wp_provider_cource` where status='1' ORDER BY `wp_provider_cource`.`id` DESC limit 0,3"; $upcome_query= mysql_query($upcome_cources); while($upcome_fetch= mysql_fetch_array($upcome_query)) { ?> <li style="width: 263px; float: left; display: block;" class="clone"> <div class="block courseitem"> <div class="block_media"><a href="#"></a><a href="#/"><img width="263" height="157" draggable="false" src="images/course_img/<?php echo $upcome_fetch['course_img'];?>" class="attachment-medium wp-post-image" alt="photography3" height="179" width="300"></a></div> <div class="block_content"> <h4 class="block_title"><a href="view_cource_details.php?id=<?php echo $upcome_fetch['id'];?>" title="Basic of Nature Photography"><?php echo $upcome_fetch['cource_name'];?></a></h4> <span class="clear"></span> </div> </div> </li> <?php } ?> </ul> </div> </div> </div> </section> <!-- End Stripestripe_container fullwidth --> </div> </section> <div class="clr"></div> </div> <?php include("footer.php");?> Edited February 22, 2015 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 23, 2015 Share Posted February 23, 2015 A completely blank page returned many times indicates a php failure. In development mode you should ALWAYS have php error checking turned on so you can monitor errors in your code and fix them. Try that. (see my signature) Quote Link to comment Share on other sites More sharing options...
maxxd Posted February 23, 2015 Share Posted February 23, 2015 It looks like you're using $query in your SELECT query without actually initializing the variable or setting any value to it. Turning on error reporting as ginerjm suggests will tell you if that's the issue. 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.