Jump to content

Recommended Posts

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 link
echo $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
Link to comment
https://forums.phpfreaks.com/topic/8898-help/
Share on other sites

[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.

Link to comment
https://forums.phpfreaks.com/topic/8898-help/#findComment-32641
Share on other sites

[!--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]
Link to comment
https://forums.phpfreaks.com/topic/8898-help/#findComment-32703
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.