PDA

View Full Version : easy script


0810
12-05-2002, 09:15 PM
hi how are you doing? What I am doing is taht Guest book's page link. Let's say I have 30 datas in my database. First page it comes only "next" link. Then, when I click next link, it goes 2 page(11-20). 2page has 2 links next page and previous page. 3page has only previous link to go back to 2page.

it works, but when I go back to from3page to 2page, 2page has not previous link. 2page only shows up next link. It is something wrong. I couldn't find that mistake.

could you check my script?

Thanks



<?php



$dc = mysql_pconnect("localhost","********","**********");
$dt=mysql_select_db("itohideo_guestbook",$dc) or die("can't select your database");




$sql = "SELECT count(*) as cnt FROM guestbook ";
$result = mysql_query($sql);
$row=mysql_fetch_array($result);
$dtcnt=$row["cnt"];


$lim=5;

$p = intval($_GET["p"]);
if($p<1){

$p=1;

}

$st = ($p - 1) * $lim;

$prev = $p - 1;

if($prev<1){

$prev=1;

}

$next=$p + 1;




$msgtime="date_format(msgtime,\"%Y/%m%d %H:%i:%s\")as mtime";
$i=0; //counter thingy for checkbox array
if($submit){

while(list($key,$val) = each($message_id)) {
$sql="delete from guestbook where message_id='$val'";
if (mysql_query($sql)) {
header("Location:GB.html");
}
}

}else{

$sql="select message_id, name,location,url,comments,date_format(msgtime, \"%Y/%m/%d %H:%i:%s\") as mtime from guestbook order by msgtime desc limit $st, $lim;";


$result=mysql_query("$sql") or die(mysql_error());
while($row=mysql_fetch_array($result)){
echo"<table border=0 cellpadding=1 cellspacing=1 width=70% align=center>";
echo"<tr align=left>";
echo"<td width=30%><font color=Navy face=arial>Name:</font></td>";
echo "<td>".$row["name"]."</td>";
echo"</tr>";
echo"<tr align=left>";
echo"<td width=30%><font color=Navy face=arial>Locatioin:</font></td>";
echo "<td>".$row["location"]."</td>";
echo"</tr>";
echo"<tr align=left>";
echo"<td width=30%><font color=Navy face=arial>URL:</font></td>";
echo"<td>";
echo"<a href=\"$row[url]\">$row[url]</a>";
echo"</td>";
echo"</tr>";
echo"<tr align=left>";
echo"<td width=30%><font color=Navy face=arial>Time:</font></td>";
echo "<td>".$row["mtime"]."</td>";
echo"</tr>";
echo"<tr align=left>";
echo"<td width=30% valign=top><font color=Navy face=arial>Comments:</font></td>";
echo "<td>".$row["comments"]."</td>";
echo"</tr>";

echo"<tr align=left>";
echo"<td width=30%><form action=\"guestbookview.php\" method=\"post\"><font color=red face=arial>Delete Record for user</td>";
echo "<td><input type=\"checkbox\" name=\"message_id['$i']\" value=\"{$row['message_id']}\"></td>";
echo"</tr>";
$i++;
echo"<tr>";
echo "<td colspan=2><hr color=silver width=100%></td>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
mysql_free_result($result);


if($p>1){

echo "<a href=\"".$_SERVER["PHP_SELF"]."?=$prev\" >Previous Page</a>\t\t\t\t\t\t\r\r\r";

}


if(($next - 1)*$lim<$dtcnt){


echo "<a href=\"".$_SERVER["PHP_SELF"]."?p=$next\" >Next Page</a>";


}
mysql_close($dc);



?>

<html>

<head>
<style type="text/css">
<!--
body{background-image:url('image/bk.gif');background-repeat:repeat-y;}
a {text-align:right;}
//-->
</style>
</head>
<body>
<center><input type="submit" name="submit" value="Submit to delete"></center>
</form>
</html>
<?php
}
?>

Spookster
12-05-2002, 11:19 PM
0810,

I am only going to say this once so consider this your only warning.

You keep creating new threads concerning the same script. Here are 4 other instances:

http://codingforums.com/showthread.php?s=&threadid=10689

http://codingforums.com/showthread.php?s=&threadid=10943

http://codingforums.com/showthread.php?s=&threadid=10826

http://codingforums.com/showthread.php?s=&threadid=10296

First of all stick with one thread. In that way people would be able to follow the progress and be in a better position to help you. Stop creating new threads.

Second of all as per my Must Read sticky thread that states questions involving MySQL or SQL should be posted in the MySQL forum. I had already moved one of your instances of this thread to that forum.

Third of all as per our forum posting guidelines. "Easy Script" and "Simple Script" and the other variations of your thread titles are not proper thread titles. Read the Posting Guidelines before you make another post.

I am now going to close this thread. Stick with the thread I moved to the MySQL forum the other day.