spertuit Posted April 13, 2009 Share Posted April 13, 2009 I'm fighting with this code right now but I'm getting this error Notice: Undefined variable: PHP_SELF in C:\wamp\www\search.php on line 115 Any Ideas? Here is some of the code echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; If you want I can put the entire page up, but I'd figure I'd try this first Link to comment https://forums.phpfreaks.com/topic/153919-php-search-wpagination/ Share on other sites More sharing options...
spertuit Posted April 13, 2009 Author Share Posted April 13, 2009 Okay I have gotten closer, but I'm still messed up. When I do a search instead of loading my results into my tables it makes another table underneath. So, if I have to results I get two tables. Anyway here is all the code, if someone can help me organize it and structure it properly I might be able to figure it out. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Job History Database</title> <script type="text/javascript" src="swfobject1-5/swfobject.js"></script> <style type="text/css"> #apDiv1 { position:absolute; left:98px; top:99px; width:831px; height:318px; z-index:1; } .style83 { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; color: #000000; font-size: 14px; } #apDiv2 { position:absolute; left:53px; top:417px; width:864px; height:118px; z-index:2; } #apDiv3 { position:absolute; left:56px; top:54px; width:552px; height:35px; z-index:3; } a:link { } a:visited { } a:hover { } a:active { } body { background-color: #000000; } #apDiv4 { position:absolute; left:98px; top:568px; width:153px; height:153px; z-index:4; } #apDiv5 { position:absolute; left:107px; top:568px; width:144px; height:152px; z-index:4; } #apDiv6 { position:absolute; left:104px; top:568px; width:149px; height:152px; z-index:4; } #apDiv7 { position:absolute; left:101px; top:568px; width:153px; height:154px; z-index:4; } #apDiv8 { position:absolute; left:155px; top:3px; width:454px; height:36px; z-index:4; } --> </style> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> </head> <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // database connection info $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('blackhawk',$conn) or trigger_error("SQL", E_USER_ERROR); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM jobdatabase"; $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 = 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 * from jobdatabase where jobNum like \"%$trimmed%\" order by jobNum"; // EDIT HERE and specify your table and field names for the SQL query $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"ID"); $f2=mysql_result($result,$i,"jobNum"); $f3=mysql_result($result,$i,"runNum"); $f4=mysql_result($result,$i,"date"); $f5=mysql_result($result,$i,"headSN"); $f6=mysql_result($result,$i,"launchSub"); $f7=mysql_result($result,$i,"customer"); $f8=mysql_result($result,$i,"operator"); $f9=mysql_result($result,$i,"companyMan"); $f10=mysql_result($result,$i,"rig"); $f11=mysql_result($result,$i,"field"); $f12=mysql_result($result,$i,"lease"); $f13=mysql_result($result,$i,"wellNum"); $f14=mysql_result($result,$i,"fieldCon"); $f15=mysql_result($result,$i,"fluid1Type"); $f16=mysql_result($result,$i,"fluid1Weight"); $f17=mysql_result($result,$i,"fluid1BBLS"); $f18=mysql_result($result,$i,"fluid1Rate"); $f19=mysql_result($result,$i,"fluid2Type"); $f20=mysql_result($result,$i,"fluid2Weight"); $f21=mysql_result($result,$i,"fluid2BBLS"); $f22=mysql_result($result,$i,"fluid2Rate"); $f23=mysql_result($result,$i,"fluid3Type"); $f24=mysql_result($result,$i,"fluid3Weight"); $f25=mysql_result($result,$i,"fluid3BBLS"); $f26=mysql_result($result,$i,"fluid3Rate"); $f27=mysql_result($result,$i,"fluid4Type"); $f28=mysql_result($result,$i,"fluid4Weight"); $f29=mysql_result($result,$i,"fluid4BBLS"); $f30=mysql_result($result,$i,"fluid4Rate"); $f31=mysql_result($result,$i,"totalVolume"); $f32=mysql_result($result,$i,"maxPressure"); $f33=mysql_result($result,$i,"makeTorque"); $f34=mysql_result($result,$i,"breakTorque"); $f35=mysql_result($result,$i,"jobType"); $f36=mysql_result($result,$i,"ballSize"); $f37=mysql_result($result,$i,"ballType"); $f38=mysql_result($result,$i,"dartSize"); $f39=mysql_result($result,$i,"dartComp"); $f40=mysql_result($result,$i,"dartLand"); $f41=mysql_result($result,$i,"hookLoad"); $f42=mysql_result($result,$i,"flagTrip"); $f43=mysql_result($result,$i,"measuredDepth"); $f44=mysql_result($result,$i,"tvd"); $f45=mysql_result($result,$i,"swivelRPM"); $f46=mysql_result($result,$i,"durationOfRot"); $f47=mysql_result($result,$i,"maxTorque"); $f48=mysql_result($result,$i,"comments"); ?> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <!-- ImageReady Slices (Interface.psd) --> <div id="apDiv1"> <table width="823" height="296" border="0" cellpadding="0" cellspacing="0"> <tr> <th width="118" height="35" scope="row"> </th> <td width="156"><span class="style83"><?php echo $f7; ?></span></td> <td width="119"> </td> <td width="157"><span class="style83"><?php echo $f7; ?></span></td> <td width="117"> </td> <td width="156"><span class="style83"><?php echo $f8; ?></span></td> </tr> <tr> <th height="20" scope="row"> </th> <td><span class="style83"><?php echo $f14; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f7; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f5; ?></span></td> </tr> <tr> <th height="36" scope="row"> </th> <td><span class="style83"><?php echo $f11; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f12; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f13; ?></span></td> </tr> <tr> <th height="19" scope="row"> </th> <td><span class="style83"><?php echo $f43; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f44; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f6; ?></span></td> </tr> <tr> <th height="36" scope="row"> </th> <td><span class="style83"><?php echo $f32; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f33; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f34; ?></span></td> </tr> <tr> <th height="21" scope="row"> </th> <td><span class="style83"><?php echo $f31; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f41; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f10; ?></span></td> </tr> <tr> <th height="32" scope="row"> </th> <td><span class="style83"><?php echo $f35; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f38; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f37; ?></span></td> </tr> <tr> <th height="21" scope="row"> </th> <td><span class="style83"><?php echo $f39; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f38; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f40; ?></span></td> </tr> <tr> <th height="34" scope="row"> </th> <td><span class="style83"><?php echo $f46; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f45; ?></span></td> <td> </td> <td><span class="style83"><?php echo $f47; ?></span></td> </tr> <tr> <th scope="row"> </th> <td colspan="5"><span class="style83"><?php echo $f48; ?></span></td> </tr> </table> </div> <div id="apDiv2"> <table width="864" height="123" border="0" cellpadding="0" cellspacing="0"> <tr> <th width="118" height="19" scope="row"> </th> <td width="126"><?php echo $f15; ?></td> <td width="77"> </td> <td width="133"><?php echo $f16; ?></td> <td width="75"> </td> <td width="133"><?php echo $f17; ?></td> <td width="74"> </td> <td width="128"><?php echo $f18; ?></td> </tr> <tr> <th height="19" scope="row"> </th> <td><?php echo $f19; ?></td> <td> </td> <td><?php echo $f20; ?></td> <td> </td> <td><?php echo $f21; ?></td> <td> </td> <td><?php echo $f22; ?></td> </tr> <tr> <th height="19" scope="row"> </th> <td><?php echo $f23; ?></td> <td> </td> <td><?php echo $f24; ?></td> <td> </td> <td><?php echo $f25; ?></td> <td> </td> <td><?php echo $f26; ?></td> </tr> <tr> <th scope="row"> </th> <td><?php echo $f27; ?></td> <td> </td> <td><?php echo $f28; ?></td> <td> </td> <td><?php echo $f29; ?></td> <td> </td> <td><?php echo $f30; ?></td> </tr> </table> </div> <div id="apDiv3"> <table width="553" height="35" border="0" cellpadding="0" cellspacing="0"> <tr> <th width="52" scope="row"> </th> <td width="121"><?php echo $f4; ?></td> <td width="57"> </td> <td width="123"><?php echo $f2; ?></td> <td width="55"> </td> <td width="128"><?php echo $f3; ?></td> </tr> </table> </div> <div id="apDiv8"><form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form></div> <div> <table id="Table_01" width="1025" height="769" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="9"> <img src="images/Job_History_01.jpg" width="632" height="92" alt=""></td> <td colspan="6"> <img src="images/Job_History_02.jpg" width="392" height="92" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="92" alt=""></td> </tr> <tr> <td rowspan="2"> <img src="images/Job_History_03.jpg" width="102" height="323" alt=""></td> <td colspan="12"> <img src="images/Job_History_04.jpg" width="823" height="322" alt=""></td> <td colspan="2" rowspan="3"> <img src="images/Job_History_05.jpg" width="99" height="477" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="322" alt=""></td> </tr> <tr> <td colspan="12" rowspan="2"> <img src="images/Job_History_06.jpg" width="823" height="155" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="1" alt=""></td> </tr> <tr> <td> <img src="images/Job_History_07.jpg" width="102" height="154" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="154" alt=""></td> </tr> <tr> <td rowspan="2"> <img src="images/Job_History_08.jpg" width="102" height="199" alt=""></td> <td colspan="2"><div id="pgauge"></div></td> <td colspan="2"><?php echo $f41; ?></td> <td colspan="2"><?php echo $f45; ?></td> <td colspan="4"><?php echo $f46; ?></td> <td> <img src="images/Job_History_13.jpg" width="48" height="152" alt=""></td> <td colspan="2"> <img src="images/Job_History_14.jpg" width="235" height="152" alt=""></td> <td> <img src="images/Job_History_15.jpg" width="66" height="152" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="152" alt=""></td> </tr> <tr> <td> <a href="http://localhost/new_record.php"><img src="images/Job_History_16.jpg" alt="" width="121" height="47" border="0"></a></td> <td colspan="2"> <a href="http://localhost/new_record.php"><img src="images/Job_History_17.jpg" alt="" width="109" height="47" border="0"></a></td> <td colspan="2"> <a href="http://localhost/new_record.php"><img src="images/Job_History_18.jpg" alt="" width="110" height="47" border="0"></a></td> <td colspan="2"> <a href="http://localhost/new_record.php"><img src="images/Job_History_19.jpg" alt="" width="108" height="47" border="0"></a></td> <td colspan="2"><a href="http://localhost/new_record.php"><img src="images/Job_History_20.jpg" alt="" width="86" height="47" border="0" /></a></td> <td colspan="2"><img src="images/Job_History_21.jpg" alt="" width="87" height="47" border="0"></td> <td colspan="3"> <img src="images/Job_History_22.jpg" width="301" height="47" alt=""></td> <td> <img src="images/spacer.gif" width="1" height="47" alt=""></td> </tr> <tr> <td> <img src="images/spacer.gif" width="102" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="121" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="31" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="78" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="62" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="48" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="92" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="16" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="82" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="4" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="39" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="48" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="202" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="33" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="66" height="1" alt=""></td> <td></td> </tr> </table> </div> <!-- End ImageReady Slices --> </body> </html> <?php $i++; } ?> <?php /****** 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 ******/ ?> Link to comment https://forums.phpfreaks.com/topic/153919-php-search-wpagination/#findComment-808965 Share on other sites More sharing options...
shlumph Posted April 13, 2009 Share Posted April 13, 2009 Try $_SERVER['PHP_SELF'] instead of $PHP_SELF Link to comment https://forums.phpfreaks.com/topic/153919-php-search-wpagination/#findComment-809032 Share on other sites More sharing options...
spertuit Posted April 13, 2009 Author Share Posted April 13, 2009 Thanks for a reply. I strip this thing down and now its pretty bare. All I need is help with the sql search. I have a simple form and all I need is to tie in the query. So far I was trying something like "select * from jobdatbase where runNum like \"%$trimmed%\" But thats not working. Any ideas? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="form" action="pagination.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //Include the PS_Pagination class include('ps_pagination.php'); //Connect to mysql db $conn = mysql_connect('localhost','root',''); mysql_select_db('blackhawk',$conn); $sql = 'select runNum from jobdatabase'; //Create a PS_Pagination object $pager = new PS_Pagination($conn,$sql,1,3); //The paginate() function returns a mysql //result set for the current page $rs = $pager->paginate(); //Loop through the result set while($row = mysql_fetch_assoc($rs)) { echo $row['jobNum']; } //Display the navigation echo $pager->renderFullNav(); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/153919-php-search-wpagination/#findComment-809043 Share on other sites More sharing options...
mandred Posted April 14, 2009 Share Posted April 14, 2009 echo " <a href=" . $_SERVER['PHP_SELF'] . "?currentpage=1">«</a> "; "select * from jobdatbase where runNum like '%$trimmed%'" Link to comment https://forums.phpfreaks.com/topic/153919-php-search-wpagination/#findComment-809085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.