Jump to content


Photo

HELP!!!!


  • Please log in to reply
3 replies to this topic

#1 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 02 May 2006 - 03:07 PM

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

#2 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 02 May 2006 - 03:18 PM

mysql_connect(mysql, root, rootroot)

this might be your first problem..

if these are arguments, then add a $ infront of them.

$mysql = "databasename";
$root = "login";
$rootroot = "password";
$conn=mysql_connect($mysql, $root, $rootroot)


Otherwise, if the values you type are the strings you wnat to use, enclose them in quotes (")
$conn=mysql_connect("mysql", "root", "rootroot")

You need to store the connection once it is established ($conn)

then you make future calls referencing your new connection id.



#3 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 02 May 2006 - 03:44 PM

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??

#4 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 02 May 2006 - 06:31 PM

[!--quoteo(post=370590:date=May 2 2006, 05:44 PM:name=BoofBoof)--][div class=\'quotetop\']QUOTE(BoofBoof @ May 2 2006, 05:44 PM) View Post[/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
while(list($val) = mysql_fetch_array($result))
must be
while($row = mysql_fetch_array($result))





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users