first of all , let me apologize for the top post, second let me apologize for not giving more detail. The main problem is basically "pagination" , i have failed to add pagination code to my own code simply because it is not as simple as i thought. Considering i am a begginer in PHP , i must give myself some credit for reaching where i am , as for code snippet here goes,
...
pagination is fairly simple once you have done it a few times, It took me ages to get my head round too.
$link = mysql_connect("localhost", "me","me2"); mysql_select_db("ip", $link); $qry = mysql_query("SELECT * FROM IP_Addresses where free like '%". $_GET['q']."%'", $link);
I think you should use the $trimmed var here iso $_GET['q'], also you should make sure that any single quotes in this string are escaped properly (otherwise they will break your query).
to do pagination you have to combine pagination links (that are used to propigate the 'page number' and current query parameter) by adding:
"LIMIT $i, 50"
to the end of your query, where $i is a multiple of 50 (lets assume you wish to show 50 rows per page) - $i would be equal to zero for the first page. the value of $i has to be propigated through the pagination links - the function I sent to you offlist has a parameter to handle this.
BTW the function I sent you returns HTML (links!) which you need to include with your output to allow users to select different pages. Also note that the second argument to the function is not actually used - its merely there so that the function is also usable as a Smarty plugin.
other than using the output from the function I sent you and making use of LIMIT clause the rest of you code does not need to change.
TIP: try to seperate processing logic from your output, i.e. breaking in and out of PHP the whole time (using <?php ?>) makes you code hard to read/maintain. to start with you could create all ness. vars containing dynamic content at the top of your script and then at the bottom output the HTML (maybe even by including a file, that file would contain just the HTML and enough PHP to output the dynamic data, the file would assume all ness. data vars are set).
?> <table border="1" width="100%"><tr><?php
if (mysql_num_rows($qry)==0 ) {
print " Oops No records found ";
?>
<br>
<a href="http://localhost/ipsearch2.html">Back</a>
</br>
<?
exit();
}
if (mysql_num_rows($qry) > 0) {
for ($i = 0; $i<mysql_num_fields($qry); $i++) {
echo "<td align=center><strong>" . mysql_field_name($qry, $i) . "</td>";
}
}
good for you for taking the generic route rather than hard coding you fieldnames!
?>
</tr><?php
if (mysql_num_rows($qry) > 0) { for ($j = 0; $j<mysql_num_rows($qry); $j++) {
?><tr><?php
for ($k = 0; $k<mysql_num_fields($qry); $k++) { echo "<td align=center>" . mysql_result($qry,$j, $k) . "</td>"; }
?></tr><?php
} }
?> </table> <br> <br> <a href="http://localhost/index.html">Main Page</a> <br> <br> <a href="http://localhost/ipsearch2.html">IP Address Search</a></br></br> </br> </br> </body> </html>
[/snip]
i had posted some time back that i have problems with pagination and got alot of help , but the problem is i have never known how to put the code together with what i have .. any help is appreciated...
cheers
...
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php