ctcp Posted June 24, 2009 Share Posted June 24, 2009 <? $connect = ($dsn); if (!($connect)) // If no connect, error and exit(). { echo("<p>Unable to connect to the database server.</p>"); exit(); } if (!(@mysql_select_db($DBNAME))) // If can't connect to database, error and exit(). { echo("<p>Unable to locate the $db_name database.</p>"); exit(); } if (!($limit)){ $limit = 50;} // Default results per-page. if (!($page)){ $page = 0;} // Default page value. $numresults = mysql_query("select * from crackz where `option` = 'Yes' and type = 'games'and name like '".chr($numbs)."%' order by date DESC"); // the query. $numrows = mysql_num_rows($numresults); // Number of rows returned from above query. $pages = intval($numrows/$limit); // Number of results pages. // $pages now contains int of pages, unless there is a remainder from division. if ($numrows%$limit) { $pages++;} // has remainder so add one page $current = ($page/$limit) + 1; // Current page number. if (($pages < 1) || ($pages == 0)) { $total = 1;} // If $pages is less than one or equal to 0, total pages is 1. else { $total = $pages;} // Else total pages is $pages value. $first = $page + 1; // The first result. if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { $last = $page + $limit;} //If not last results page, last result equals $page plus $limit. else{ $last = $numrows;} // If last results page, last result equals total number of results. //escape from PHP mode. ?> <div class="secondlevel"> <ul> <li> <? for ($id=65; $id < 91; $id++) { ?> <li <? if ($id == $numbs) { echo 'class="current"'; } ?>><a href="?section=<? echo $section; ?>&numbs=<? echo $id; ?>"><? echo chr($id); ?></a></li> <? } ?></ul></div> <html> <head> <title>Search Results for <?=$query?></title> </head> <body> <table width="100%" border="0"> <tr> <td width="50%" align="left"> <?php if ($numrows > 0) { ?> Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b> <? } ?> </td> <td width="50%" align="right"> Page <b><?=$current?></b> of <b><?=$total?></b> </td> </tr> <tr> <td colspan="2" align="left"><span class="sectionhead"> starting from <? echo chr($numbs); ?></span></td> </tr> <tr> <?php if ($numrows > 0) { ?> <td colspan="2" align="right"> Results per-page: <a href="<?=$PHP_SELF?>?section=games&numbs=<?=$numbs?>&page=<?=$page?>&limit=100">100</a> | <a href="<?=$PHP_SELF?>?section=games&numbs=<?=$numbs?>&page=<?=$page?>&limit=50">50</a> </td> <? } ?> </tr> </table> <? //Go back into PHP mode. // Now we can display results. $results = mysql_query("select * from crackz where `option` = 'Yes' and type = 'games' and name like '".chr($numbs)."%' ORDER BY date DESC LIMIT $page, $limit"); while ($data = mysql_fetch_array($results)) { ?> <li>[<?=$data["type"]?>] [<?=$data["date"]?>] <a href="?section=view&id=<?=$data["id"]?>&type=<?=$type?>" title="<?=$data["name"]?>"><?=$data["name"]?></a> </li> <? } ?> <p align="center"> <? if ($page != 0) { // Don't show back link if current page is first page. $back_page = $page - $limit; echo("<a href=\"$PHP_SELF?section=games&numbs=$numbs&page=$back_page&limit=$limit\">back</a> \n");} for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b> \n");} // If current page don't give link, just text. else{ echo("<a href=\"$PHP_SELF?section=games&numbs=$numbs&page=$ppage&limit=$limit\">$i</a> \n");} } if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link. $next_page = $page + $limit; echo(" <a href=\"$PHP_SELF?section=games&numbs=$numbs&page=$next_page&limit=$limit\">next</a>\n");} ?> </p> </body> </html> thanks you for yours help special Thanks to phpfreaks.com how to drop error message if results is 0 but i don't whant see the message in first page only if i search somthink and i find nothink .. Link to comment https://forums.phpfreaks.com/topic/163550-php-search-if-null-drop-error-message-pls-help/ Share on other sites More sharing options...
flyhoney Posted June 24, 2009 Share Posted June 24, 2009 For the love of all that is holy, please work on your style! <?php $connect = $dsn; if (!($connect)) // If no connect, error and exit(). { die("<p>Unable to connect to the database server.</p>"); } if (!(@mysql_select_db($DBNAME))) // If can't connect to database, error and exit(). { die("<p>Unable to locate the $db_name database.</p>"); } // Default results per-page. $limit = ($limit) ? $limit : 50; // Default page value. $page = ($page) ? $page : 0; $query = " SELECT * FROM crackz WHERE `option` = 'Yes' AND type = 'games' AND name LIKE '".chr($numbs)."%' ORDER BY date DESC "; $result = mysql_query($query); $numrows = mysql_num_rows($result); // Number of results pages. $pages = intval($numrows / $limit); // $pages now contains int of pages, unless there is a remainder from division. $pages = ($numrows % $limit) ? $page + 1 : $pages; // Current page number. $current = ($page / $limit) + 1; // If $pages is less than one or equal to 0, total pages is 1. $total = (($pages < 1) || ($pages == 0)) ? 1 : $pages; // The first result. $first = $page + 1; //If not last results page, last result equals $page plus $limit. if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { $last = $page + $limit; } else { // If last results page, last result equals total number of results. $last = $numrows; } ?> <html> <head> <title>Search Results for <?php echo $query ?></title> </head> <body> <div class="secondlevel"> <ul> <?php for ($id = 65; $id < 91; $id++): ?> <li <?php if ($id == $numbs) { echo 'class="current"'; } ?>> <a href="?section=<?php echo $section; ?>&numbs=<?php echo $id; ?>"><?php echo chr($id); ?></a> </li> <?php endfor ?> </ul> </div> <table width="100%" border="0"> <tr> <td width="50%" align="left"> <?php if ($numrows > 0): ?> Results <b><?php echo $first ?></b> - <b><?php echo $last ?></b> of <b><?php echo $numrows ?></b> <?php endif ?> </td> <td width="50%" align="right"> Page <b><?php echo $current ?></b> of <b><?php echo $total ?></b> </td> </tr> <tr> <td colspan="2" align="left"> <span class="sectionhead">starting from <?php echo chr($numbs) ?></span> </td> </tr> <tr> <?php if ($numrows > 0): ?> <td colspan="2" align="right"> Results per-page: <a href="<?php echo $PHP_SELF ?>?section=games&numbs=<?php echo $numbs ?>&page=<?php echo $page ?>&limit=100">100</a> | <a href="<?php echo $PHP_SELF ?>?section=games&numbs=<?php echo $numbs ?>&page=<?php echo $page ?>&limit=50">50</a> </td> <?php endif ?> </tr> </table> <?php // Now we can display results. $query = " SELECT * FROM crackz WHERE `option` = 'Yes' AND type = 'games' AND name LIKE '".chr($numbs)."%' ORDER BY date DESC LIMIT $page, $limit "; $results = mysql_query($query); ?> <ul> <?php while ($data = mysql_fetch_array($results)): ?> <li> [<?php echo $data["type"] ?>] [<?php echo $data["date"] ?>] <a href="?section=view&id=<?php echo $data["id"] ?>&type=<?php echo $type ?>" title="<?php echo $data["name"] ?>"> <?php echo $data["name"] ?> </a> </li> <?php endwhile ?> </ul> <p align="center"> <?php // Don't show back link if current page is first page. if ($page != 0) { $back_page = $page - $limit; echo "<a href=\"$PHP_SELF?section=games&numbs=$numbs&page=$back_page&limit=$limit\">back</a>\n"; } // loop through each page and give link to it. for ($i = 1; $i <= $pages; $i++) { $ppage = $limit * ($i - 1); // If current page don't give link, just text. if ($ppage == $page) { echo "<b>$i</b> \n"; } else { echo "<a href=\"$PHP_SELF?section=games&numbs=$numbs&page=$ppage&limit=$limit\">$i</a>\n"; } } // If last page don't give next link. if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { $next_page = $page + $limit; echo "<a href=\"$PHP_SELF?section=games&numbs=$numbs&page=$next_page&limit=$limit\">next</a>\n"; } ?> </p> </body> </html> FTFY Link to comment https://forums.phpfreaks.com/topic/163550-php-search-if-null-drop-error-message-pls-help/#findComment-862901 Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 how to drop error message if results is 0 but i don't whant see the message in first page only if i search somthink and i find nothink .. if(!empty($numbs)) { // do all that code } if they searched for nothing the page will be blank. Link to comment https://forums.phpfreaks.com/topic/163550-php-search-if-null-drop-error-message-pls-help/#findComment-862913 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.