bucket 11-03-2009, 12:57 PM This is a pagination script, with a delete function and is in a table. I am getting this error.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-4,4' at line 1
<?php
include("inc/config.php");
if (isset($_POST['del']))
{
for ($count = 0;$count<count($_POST[delchk]);$count++)
{
$delete = $_POST[delchk][$count];
$query = "DELETE FROM accounts WHERE id = '$delete'";
$result = mysql_query($query);
if (!$result)
{
die("Error deleting accounts! Query: $query<br />Error: ".mysql_error());
}
}
}
echo "<table class=\"gridtable\">
<thead>
<tr>
<th align=\"center\" scope=\"col\">Delete?</th>
<th align=\"center\" scope=\"col\">Username</th>
<th align=\"center\" scope=\"col\">Password</th>
<th align=\"center\" scope=\"col\">Highscores</th>
<th align=\"center\" scope=\"col\">Date</th>
<th align=\"center\" scope=\"col\">IP Address</th>
<th align=\"center\" scope=\"col\">Status</th>
</tr>
</thead>
<tbody>";
echo "<form name = 'myform' action='' method='post'>";
$pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1;
$data = mysql_query("SELECT * FROM accounts") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 4;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error());
while($info = mysql_fetch_array( $data_p ))
{
echo "<tr align=\"center\">";
echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';
echo "<td class=\"valid\" >" . $info['username'] . "</td>";
echo "<td class=\"valid\" >" . $info['password'] . "</td>";
echo "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1=". $info['username'] ."'>Check Highscores</a></td>";
echo "<td>" . $info['addeddate'] . "</td>";
echo "<td>" . $info['ip'] . "</td>";
echo "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "<hr>";
echo "<input type='submit' name = 'del' value='Delete Selected'></form>";
echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
echo "<hr>";
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
echo " | ";
echo " ";
$previous = $pagenum-1;
$current = $pagenum;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
echo " | ";
}
echo "$pagenum";
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " | ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
echo " ";
echo " | ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
}
?>
What is the problem? And how can I fix it?
_Aerospace_Eng_ 11-03-2009, 01:06 PM Change this line
$data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error());
to this
$data_p = mysql_query("SELECT * FROM accounts $max") or die("SELECT * FROM accounts $max");
This should print out the query to the screen upon error. From the looks of it your $max string is using -4,4 as the $limit which means $pagenum is probably 0 and not 1.
bucket 11-03-2009, 01:14 PM It is now showing this error:
SELECT * FROM accounts limit -4,4
This is the updated code.
<?php
include("inc/config.php");
if (isset($_POST['del']))
{
for ($count = 0;$count<count($_POST[delchk]);$count++)
{
$delete = $_POST[delchk][$count];
$query = "DELETE FROM accounts WHERE id = '$delete'";
$result = mysql_query($query);
if (!$result)
{
die("Error deleting accounts! Query: $query<br />Error: ".mysql_error());
}
}
}
echo "<table class=\"gridtable\">
<thead>
<tr>
<th align=\"center\" scope=\"col\">Delete?</th>
<th align=\"center\" scope=\"col\">Username</th>
<th align=\"center\" scope=\"col\">Password</th>
<th align=\"center\" scope=\"col\">Highscores</th>
<th align=\"center\" scope=\"col\">Date</th>
<th align=\"center\" scope=\"col\">IP Address</th>
<th align=\"center\" scope=\"col\">Status</th>
</tr>
</thead>
<tbody>";
echo "<form name = 'myform' action='' method='post'>";
$pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1;
$data = mysql_query("SELECT * FROM accounts") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 4;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM accounts $max") or die("SELECT * FROM accounts $max");
while($info = mysql_fetch_array( $data_p ))
{
echo "<tr align=\"center\">";
echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';
echo "<td class=\"valid\" >" . $info['username'] . "</td>";
echo "<td class=\"valid\" >" . $info['password'] . "</td>";
echo "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1=". $info['username'] ."'>Check Highscores</a></td>";
echo "<td>" . $info['addeddate'] . "</td>";
echo "<td>" . $info['ip'] . "</td>";
echo "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "<hr>";
echo "<input type='submit' name = 'del' value='Delete Selected'></form>";
echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
echo "<hr>";
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
echo " | ";
echo " ";
$previous = $pagenum-1;
$current = $pagenum;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
echo " | ";
}
echo "$pagenum";
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " | ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
echo " ";
echo " | ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
}
?>
_Aerospace_Eng_ 11-03-2009, 01:47 PM Do you not see the problem? Look at your limits your first value needs to be 0 or greater. Before you set your $max variable echo out $pagenum. What do you get?
bucket 11-03-2009, 03:08 PM I actually have no idea. :(
I am not very good at php and got this script from other snippets.
Phil Jackson 11-03-2009, 03:56 PM I've made my plugin script if you want it.
bucket 11-03-2009, 04:07 PM Yes please. Pm me it please!
Phil Jackson 11-03-2009, 04:26 PM Yes please. Pm me it please!
http://www.actwebdesigns.co.uk/web-design-mansfield/php-functions/pagination-function.php
bucket 11-03-2009, 04:31 PM Random Quote Function?
That is as the title of the webpage.
Change it :P
'Dedicated to Bucket'
Thats sweet. Il add you in the credits of my admin area.
--
Also when I select the code it also selects the numbers next to it, can you just post it here so I dont have to edit out the numbers one by one?
Picture.
http://i.fhqhosting.com/select.bmp
Phil Jackson 11-03-2009, 04:47 PM index.php
<?php
include("function.paginationMain.php");
include("function.paginationLinks.php");
// This will be the main output
// echo paginationMain (10, "########", "#######", "123456789", "localhost", "pagination-table", "points");
// I've seperated the links so you can put them in where needed
// echo paginationLinks (10, "########", "#######", "123456789", "localhost", "pagination-table", "points");
?>
function.paginationMain.php
<?php
function paginationMain ($perPage, $DBname, $DBuser, $DBpass, $DBhost, $tableName, $row)
{
// connect to database
$con = @mysql_connect($DBhost, $DBuser, $DBpass) or die(mysql_error());
if(!$db = @mysql_select_db($DBname, $con)){die("Could not connect to database");}
// check table
$tableQuery = mysql_query("SELECT * FROM `$tableName`") or die("Could not connect to table. `".$tableName."`". mysql_error());
if(mysql_num_rows($tableQuery)!=0)
{
// get offset position
if(isset($_GET['nd']))
$end = $_GET['nd'];
else
$end = $perPage;
// create main query
$query = "SELECT * FROM `".$tableName."` ORDER BY ".$row." DESC LIMIT ".$perPage." OFFSET ".$end;
// get results
$resultsQuery = mysql_query($query) or die(mysql_error());
while($rows = mysql_fetch_array($resultsQuery))
{
###### EDIT BELOW HERE #####
$name = $rows['name'];
$points = $rows['points'];
echo "name: ".$name." points: ".$points."<br />\n";
###### EDIT END ######
}
}
else
{
// here should be any code for if there currently is no data in table
return "No data available";
}
mysql_close($con);
}
?>
function.paginationLinks.php
<?php
function paginationLinks($perPage, $DBname, $DBuser, $DBpass, $DBhost, $tableName, $row)
{
// connect to database
$con = @mysql_connect($DBhost, $DBuser, $DBpass) or die(mysql_error());
if(!$db = @mysql_select_db($DBname, $con)){die("Could not connect to database");}
// check table
$tableQuery = mysql_query("SELECT * FROM `$tableName`") or die("Could not connect to table. `".$tableName."`". mysql_error());
if(mysql_num_rows($tableQuery)!=0)
{
$numRows = mysql_num_rows($tableQuery);
// get start position
if(isset($_GET['st']))
$start = $_GET['st'];
else
$start = 0;
// get end position
if(isset($_GET['nd']))
$end = $_GET['nd'];
else
$end = $perPage;
// create main query
$numPages = ceil($numRows/$perPage);
echo "<p>";
if($start!=0)
{
if((($end-($perPage*2))+1)==1)
$prevS = 0;
else
$prevS = (($end-($perPage*2))+1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?st=".$prevS."&nd=".($end-$perPage)."\" title=\"previous\">[prev] </a> ";
}
if($numPages>1)
{
for($x=0; $x!=$numPages; $x++)
{
if((($x*$perPage)+1)==1)
$pageS = 0;
else
$pageS = (($x*$perPage)+1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?st=".$pageS."&nd=".(($x*$perPage)+$perPage)."\" title=\"page ".($x+1)."\"> [".($x+1)."]</a> ";
}
}
if($numPages>1 && $end<$numRows)
{
if(($end+1)==1)
$nextS = 0;
else
$nextS = ($end+1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?st=".$nextS."&nd=".($end+$perPage)."\" title=\"next\"> [next]</a> ";
}
echo "</p>\n";
}
mysql_close($con);
}
?>
bucket 11-03-2009, 04:54 PM Its a blank page. What is the Points thing for in index.php?
bucket 11-03-2009, 04:56 PM It seems to not be working... :P
Phil Jackson 11-03-2009, 04:59 PM sorry i haven't had time to write a full tut but;
paginationMain($perPage, $DBname, $DBuser, $DBpass, $DBhost, $tableName, $row)
$per page = amount results per page
$row = the name of the row that the script will order by. e.g. score, points, rank, position...
Just put id or anything if you dont need it
bucket 11-03-2009, 05:05 PM I got a problem with mine.
I got this at the moment:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include("inc/config.php");
echo "
<table class=\"gridtable\">
<thead>
<tr>
<th align=\"center\" scope=\"col\">Username</th>
<th align=\"center\" scope=\"col\">Password</th>
<th align=\"center\" scope=\"col\">Highscores</th>
<th align=\"center\" scope=\"col\">Date</th>
<th align=\"center\" scope=\"col\">IP Address</th>
<th align=\"center\" scope=\"col\">Status</th>
<th align=\"center\" scope=\"col\">Delete?</th>
</tr>
</thead>
<tbody>";
echo "<form name = 'myform' action='' method='post'>";
$pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1;
$data = mysql_query("SELECT * FROM accounts") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 4;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last);
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM accounts $max") or die("");
while($info = mysql_fetch_array( $data_p ))
{
echo "<tr align=\"center\">";
echo "<td class=\"valid\" >" . $info['username'] . "</td>";
echo "<td class=\"valid\" >" . $info['password'] . "</td>";
echo "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1=". $info['username'] ."'>Check Highscores</a></td>";
echo "<td>" . $info['addeddate'] . "</td>";
echo "<td>" . $info['ip'] . "</td>";
echo "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "<hr>";
echo "<input type='submit' name = 'del' value='Delete Selected'></form>";
echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
echo "<hr>";
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
echo " | ";
echo " ";
$previous = $pagenum-1;
$current = $pagenum;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
echo " | ";
}
echo "$pagenum";
if ($pagenum == $last)
{
}
else
{
$next = $pagenum+1;
echo " | ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
echo " ";
echo " | ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
}
?>
Now when there is information it shows the whole page with the footer, when there is no information it cuts of the footer and ends at the form:
With information
<table class="gridtable">
<thead>
<tr>
<th align="center" scope="col">Username</th>
<th align="center" scope="col">Password</th>
<th align="center" scope="col">Highscores</th>
<th align="center" scope="col">Date</th>
<th align="center" scope="col">IP Address</th>
<th align="center" scope="col">Status</th>
<th align="center" scope="col">Delete?</th>
</tr>
</thead>
<tbody><form name = 'myform' action='' method='post'><tr align="center"><td class="valid" ></td><td class="valid" ></td><td><a target=frame2 href='profile/hiscorepersonal.ws?user1='>Check Highscores</a></td><td>November 3 2009</td><td>96.242.128.224</td><td><img src="img/invalid.png" title="Account information: INVALID!"/><img src="img/valid.png" title="Account information: VALID!"/></td><td><input type="checkbox" id="delchk" name="delchk[]" value="157" /></td></tr><tr align="center"><td class="valid" ></td><td class="valid" ></td><td><a target=frame2 href='profile/hiscorepersonal.ws?user1='>Check Highscores</a></td><td>November 3 2009</td><td>96.242.128.224</td><td><img src="img/invalid.png" title="Account information: INVALID!"/><img src="img/valid.png" title="Account information: VALID!"/></td><td><input type="checkbox" id="delchk" name="delchk[]" value="158" /></td></tr><tr align="center"><td class="valid" ></td><td class="valid" ></td><td><a target=frame2 href='profile/hiscorepersonal.ws?user1='>Check Highscores</a></td><td>November 3 2009</td><td>96.242.128.224</td><td><img src="img/invalid.png" title="Account information: INVALID!"/><img src="img/valid.png" title="Account information: VALID!"/></td><td><input type="checkbox" id="delchk" name="delchk[]" value="159" /></td></tr></tbody></table><hr><input type='submit' name = 'del' value='Delete Selected'></form><input type='button' onclick='checkall(document.myform["delchk"]);' value='Select All'><input type='button' onclick='uncheckall(document.myform["delchk"]);' value='Deselect All'><hr>1
</hr>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="contain">
<div class="footerdesc">
</div>
</a>
</div>
</div>
</div>
</body>
</html>
Without information/rows in the database to show it ends:
<table class="gridtable">
<thead>
<tr>
<th align="center" scope="col">Username</th>
<th align="center" scope="col">Password</th>
<th align="center" scope="col">Highscores</th>
<th align="center" scope="col">Date</th>
<th align="center" scope="col">IP Address</th>
<th align="center" scope="col">Status</th>
<th align="center" scope="col">Delete?</th>
</tr>
</thead>
<tbody>
<form name = 'myform' action='' method='post'>
Basicly it cuts off this part:
</form><input type='button' onclick='checkall(document.myform["delchk"]);' value='Select All'><input type='button' onclick='uncheckall(document.myform["delchk"]);' value='Deselect All'><hr>1
</hr>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="contain">
<div class="footerdesc">
</div>
</a>
</div>
</div>
</div>
</body>
</html>
Basicly cutting off the footer of my webpage.
bucket 11-03-2009, 05:12 PM This is what I mean:
With information showing, I blanked it out tho:
http://i.fhqhosting.com/2info.bmp
without information showing:
http://i.fhqhosting.com/noinfo.bmp
It basicly cuts of my footer.
Thats the problem.
bucket 11-03-2009, 06:12 PM Anyone?
tomws 11-03-2009, 06:37 PM Anyone?
Self-bumping after so short a period is discouraged. http://www.codingforums.com/postguide.htm
5) Do not bump your thread repeatedly when you don't get a response. Sometimes when you post for help, you may not get a response in a timely matter, if at all. Forums aren't wishing wells, and some questions will fall through the cracks. That's a fact of life. It's ok to occasionally bump a thread, but only when done after an ample amount of time (ie: 2-3 days) have passed without a response, and never more than once, . Your thread is no more important than another member's when it comes to the amount of attention it should receive.
bucket 11-03-2009, 06:39 PM Okay sorry but this is kinda urgent, instead I made a new thread since this one is getting cluttered.
_Aerospace_Eng_ 11-04-2009, 06:17 AM Okay sorry but this is kinda urgent, instead I made a new thread since this one is getting cluttered.
So you went ahead and double posted. Awesome. I suggest you hire someone then if its really urgent. We are trying to help you but you don't seem to be trying. In your original code you can have a negative number as the starting limit.
|
|