ccutla Posted May 2, 2006 Share Posted May 2, 2006 I am very new to this whole programming biz so bare with me if I am missing something very obvious. I have gone to and tried just about all of the tutorials I could find on php mysql pagination. I cannot seem to get it all together at once. Here is what I have for just a general query of my DB all I want to do is to get a simple paging system in place....php:<center><table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000"><tr><td width="60"><b>DT_STRING</b></td><td width="100"><b>ACCOUNT</b></td><td width="30"><b>ACCOUNT_TYPE</b></td><td width="150"><b>CLIENT_ID</b></td><td width="150"><b>USER_ID</b></td></tr><tr><td><?php // Database Connection mysql_connect(mysql, root, rootroot) or die("ERROR--CAN'T CONNECT TO SERVER"); mysql_select_db("AUDITMED") or die("ERROR--CAN'T CONNECT TO DB"); $rowsPerPage = 20;$pageNum = 1;if(isset($_GET['page'])){ $pageNum = $_GET['page'];}$offset = ($pageNum - 1) * $rowsPerPage;$query = "SELECT * FROM AUDIT LIMIT $offset, $rowsPerPage";$result = mysql_query($query) or die('Error, query failed');while(list($val) = mysql_fetch_array($result)) { $variable1=$row["DT_STRING"]; $variable2=$row["ACCOUNT"]; $variable3=$row["ACCOUNT_TYPE"]; $variable4=$row["CLIENT_ID"]; $variable5=$row["USER_ID"]; //table layout for results echo ("<tr>"); echo ("<td>$variable1</td>"); echo ("<td>$variable2</td>"); echo ("<td>$variable3</td>"); echo ("<td>$variable4</td>"); echo ("<td>$variable5</td>"); echo ("</tr>"); }echo '<br>';$query = "SELECT COUNT(val) AS numrows FROM AUDIT";$result = mysql_query($query) or die('Error, query failed');$row = mysql_fetch_array($result, MYSQL_ASSOC);$numrows = $row['numrows'];$maxPage = ceil($numrows/$rowsPerPage);$self = $_SERVER['PHP_SELF'];if ($pageNum > 1){ $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> ";} else{ $prev = ' [Prev] '; $first = ' [First Page] '; }if ($pageNum < $maxPage){ $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";} else{ $next = ' [Next] '; $last = ' [Last Page] '; }$pagelinks = '';for(i=1; i<maxPage; i++){$pagelinks .= " <a href=\"$self?page=$i\">[$i]</a> ";}// print the page navigation linkecho $first . $prev . $pagelinks . $next . $last;?></table></center>I get no results, period, not even the table will show up when I try to run this script, but as far as the tutorials that I've read it should work. I know there is something quite obvious that I'm missing, any suggestions would be greatly appreciated. Thanks a lot!Boof Boof Duff Duff Quote Link to comment Share on other sites More sharing options...
lead2gold Posted May 2, 2006 Share Posted May 2, 2006 [code]mysql_connect(mysql, root, rootroot)[/code]this might be your first problem..if these are arguments, then add a $ infront of them.$mysql = "databasename";$root = "login";$rootroot = "password";[code]$conn=mysql_connect($mysql, $root, $rootroot)[/code]Otherwise, if the values you type are the strings you wnat to use, enclose them in quotes (")[code]$conn=mysql_connect("mysql", "root", "rootroot")[/code]You need to store the connection once it is established ($conn)then you make future calls referencing your new connection id. Quote Link to comment Share on other sites More sharing options...
ccutla Posted May 2, 2006 Author Share Posted May 2, 2006 Alright, that is very true, I changed that so that it would connect and echoed it out to make sure it was connecting, but I still get no results back, let alone the basic table headers that I know works on other scripts. Any other suggestions?? Quote Link to comment Share on other sites More sharing options...
sasa Posted May 2, 2006 Share Posted May 2, 2006 [!--quoteo(post=370590:date=May 2 2006, 05:44 PM:name=BoofBoof)--][div class=\'quotetop\']QUOTE(BoofBoof @ May 2 2006, 05:44 PM) [snapback]370590[/snapback][/div][div class=\'quotemain\'][!--quotec--]Alright, that is very true, I changed that so that it would connect and echoed it out to make sure it was connecting, but I still get no results back, let alone the basic table headers that I know works on other scripts. Any other suggestions??[/quote]line[code]while(list($val) = mysql_fetch_array($result))[/code]must be[code]while($row = mysql_fetch_array($result))[/code] 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.