Проблема с (Следующая страница) * (Предыдущая страница)

  • Автор темы Николаев Кирилл
  • 22
  • Обновлено
  • 12, May 2024
  • #1
Всем привет.

Я очень стараюсь добавить в свой сценарий нумерацию страниц, но, похоже, это получается ужасно.

Я пытался несколько часов, и хотя я чувствую, что уже близок, похоже, это не работает, поэтому я решил обратиться за помощью.

Без вставленного мной скрипта пагинации есть список машин.

Когда я добавляю его, весь список исчезает.

Строка, которую я вставил, находится примерно на 3/4 длины вниз, начиная с

//проверяем, была ли передана переменная начальной строки в URL или нет
if (!isset($_GET['startrow']) или !is_numeric($_GET['startrow'])) {
Пожалуйста, помогите мне!
 <?php include"mainmenu.php"; ?>

<?php

if ($_POST['sell'] && $_POST['car']){

$sell = $_POST['car'];

foreach($sell as $checkboxid)

{

$sql="SELECT * from cars WHERE id='$checkboxid'";

$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){ // Start looping table row

$id= $rows['id'];

$cprice= $rows['price'];

$carname= $rows['name'];

}

mysql_query("DELETE FROM cars WHERE id='$checkboxid'");

mysql_query("UPDATE users SET `cash`=`cash`+'$cprice' WHERE username='$username'");

}

echo "You sold your car(s)!";

}

?>

<?php

if ($_POST['rcar'] && $_POST['car']){

$rcar = $_POST['car'];

foreach($rcar as $checkboxid)

{

$sql="SELECT * from cars WHERE id='$checkboxid'";

$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){ // Start looping table row

$id= $rows['id'];

$carname= $rows['name'];

?>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=topleft NOWRAP>

</td>

<td class=leftbar NOWRAP>

</td>

<td class=bar NOWRAP>

</td>

<td class=rightbar NOWRAP>

</td>

<td class=topright NOWRAP>

</td>

</tr>

</tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=left NOWRAP>

</td>

<td class=main>

<div align="left">

<?php echo "This car already has 0% damage!"; ?>

</div>

</td>

<td class=right NOWRAP>

</td>

</tr>

</Tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=bottomleft NOWRAP>

</td>

<td class=bottom NOWRAP>

</td>

<td class=bottomright NOWRAP>

</td>

</tr>

</tbody>

</table>

<?php

}//loop

}//loop

}//if submit

?>

<?php

if ($_POST['drop'] && $_POST['car']){

$dcar = $_POST['car'];

foreach($dcar as $dropcar)

{

mysql_query("DELETE FROM cars WHERE id='$dropcar' AND owner='$username'");

}

echo "<b>Selected cars have been dropped!</b>";

}//if submit

?>

<?php

if ($_POST['rcar'] && $_POST['car']){

$rcar = $_POST['car'];

foreach($rcar as $checkboxid)

{

$sql="SELECT * from cars WHERE id='$checkboxid'";

$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){ // Start looping table row

$id= $rows['id'];

$damage= $rows['damage'];

$type= $rows['type'];

if($type=="1"){$carname = $car_1;}

if($type=="2"){$carname = $car_2;}

if($type=="3"){$carname = $car_3;}

if($type=="4"){$carname = $car_4;}

if($type=="5"){$carname = $car_5;}

if($type=="6"){$carname = $car_6;}

if($type=="7"){$carname = $car_7;}

if($type=="8"){$carname = $car_8;}

if($type=="9"){$carname = $car_9;}

if($type=="10"){$carname = $car_10;}

if($type=="11"){$carname = $car_11;}

if($type=="12"){$carname = $car_12;}

if($type=="13"){$carname = $car_13;}

if ($damage ==0){

?>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=topleft NOWRAP>

</td>

<td class=leftbar NOWRAP>

</td>

<td class=bar NOWRAP>

</td>

<td class=rightbar NOWRAP>

</td>

<td class=topright NOWRAP>

</td>

</tr>

</tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=left NOWRAP>

</td>

<td class=main>

<div align="left">

<?php echo "This car allready has 0% damage!"; ?>

</div>

</td>

<td class=right NOWRAP>

</td>

</tr>

</Tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=bottomleft NOWRAP>

</td>

<td class=bottom NOWRAP>

</td>

<td class=bottomright NOWRAP>

</td>

</tr>

</tbody>

</table>

<?php

}else{

$c = rand(9,110);

if($repaircar>=1){

mysql_query("UPDATE cars SET damage='0' WHERE id='$checkboxid' AND owner='$username'");

?>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=topleft NOWRAP>

</td>

<td class=leftbar NOWRAP>

</td>

<td class=bar NOWRAP>

</td>

<td class=rightbar NOWRAP>

</td>

<td class=topright NOWRAP>

</td>

</tr>

</tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=left NOWRAP>

</td>

<td class=main>

<div align="left">

<?php echo "You successfully fixed your $carname with $damage% damage!"; ?>

</div>

</td>

<td class=right NOWRAP>

</td>

</tr>

</Tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=bottomleft NOWRAP>

</td>

<td class=bottom NOWRAP>

</td>

<td class=bottomright NOWRAP>

</td>

</tr>

</tbody>

</table>

<?php

mysql_query("UPDATE users SET `repaircar`=`repaircar`-'1' WHERE username='$username'");

}else{

if ($c < $damage){

mysql_query("DELETE FROM cars WHERE id='$checkboxid'");

?>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=topleft NOWRAP>

</td>

<td class=leftbar NOWRAP>

</td>

<td class=bar NOWRAP>

</td>

<td class=rightbar NOWRAP>

</td>

<td class=topright NOWRAP>

</td>

</tr>

</tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=left NOWRAP>

</td>

<td class=main>

<div align="left">

<?php echo "You failed to repair your $carname with $damage% damage."; ?>

</div>

</td>

<td class=right NOWRAP>

</td>

</tr>

</Tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=bottomleft NOWRAP>

</td>

<td class=bottom NOWRAP>

</td>

<td class=bottomright NOWRAP>

</td>

</tr>

</tbody>

</table>

<?php

}else{

mysql_query("UPDATE cars SET damage='0' WHERE id='$checkboxid' AND owner='$username'");

?>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=topleft NOWRAP>

</td>

<td class=leftbar NOWRAP>

</td>

<td class=bar NOWRAP>

</td>

<td class=rightbar NOWRAP>

</td>

<td class=topright NOWRAP>

</td>

</tr>

</tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=left NOWRAP>

</td>

<td class=main>

<div align="left">

<?php echo "You successfully fixed your $carname with $damage% damage!"; ?>

</div>

</td>

<td class=right NOWRAP>

</td>

</tr>

</Tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=bottomleft NOWRAP>

</td>

<td class=bottom NOWRAP>

</td>

<td class=bottomright NOWRAP>

</td>

</tr>

</tbody>

</table>

<?php

}//fail else

}//damage not zero

}//repair car successfully

}//loop

}//loop

}//if submit

?>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=topleft NOWRAP>

</td>

<td class=leftbar NOWRAP>

</td>

<td class=bar NOWRAP>

</td>

<td class=rightbar NOWRAP>

</td>

<td class=topright NOWRAP>

</td>

</tr>

</tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=left NOWRAP>

</td>

<td class=main>

<div align="center">

<script language="javascript">

checked = false;

function checkAll () {

if (checked == false){checked = true}else{checked = false}

for (var i = 0; i < document.getElementById('crimes').elements.length; i++) {

document.getElementById('crimes').elements[i].checked = checked;

}

}

</script>

<?php

//check if the starting row variable was passed in the URL or not

if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {

//we give the value of the starting row to 0 because nothing was found in URL

$startrow = 0;

//otherwise we take the value from the URL

} else {

$startrow = (int)$_GET['startrow'];

}

//this part goes after the checking of the $_GET var

$fetch = mysql_query("SELECT * FROM cars WHERE owner='".mysql_real_escape_string($username)."' ORDER BY type ASC LIMIT $startrow, 10")or

die(mysql_error());

while($row = mysql_fetch_array( $result )) {

$id = $row['id'];

$type = $row['type'];

$damage = $row['damage'];

$sale = $row['sale'];

$price = number_format($row['price']);

if($type=="1"){$carname = $car_1;}

if($type=="2"){$carname = $car_2;}

if($type=="3"){$carname = $car_3;}

if($type=="4"){$carname = $car_4;}

if($type=="5"){$carname = $car_5;}

if($type=="6"){$carname = $car_6;}

if($type=="7"){$carname = $car_7;}

if($type=="8"){$carname = $car_8;}

if($type=="9"){$carname = $car_9;}

if($type=="10"){$carname = $car_10;}

if($type=="11"){$carname = $car_11;}

if($type=="12"){$carname = $car_12;}

if($type=="13"){$carname = $car_13;}

$num=Mysql_num_rows($fetch);

if($num>0)

{

echo "<table>";

echo "<tr><td>Car name</td><td>Car damage</div></td><td>Repair chance</td><td>Price</td></tr>";

for($i=0;$i<$num;$i++)

{

$row=mysql_fetch_row($fetch);

?>

<tr>

<td class="header" colspan="4">

<div align="center" class="unnamed1">Cars</div>

</td>

</tr>

<form action='' id=crimes method='post'>

<tr>

<td width="40%" height="6" align="left" bgcolor="<?php echo "$tabcolor"; ?>" class="tabA">

<label for="<?php echo $row['id']; ?>">

<input name="car[]" type="checkbox" value="<? echo $id; ?>">

<a href="viewcar.php?carid=<? echo $id; ?>"><?php echo $carname; ?></a>

</label>

</td>

<td width="20%" height="6" align="left" bgcolor="<?php echo "$tabcolor"; ?>" class="tabA"><label>

<?php echo $row['damage']."%"; ?>

</label>

</td>

<td width="20%" height="6" align="left" bgcolor="<?php echo "$tabcolor"; ?>" class="tabA"><label>

<?php

if ($damage==0){ echo "100"; }else{echo 100-$damage;}

?>

%</label>

</td>

<td width="20%" hight="6" align="left" bgcolor="<?php echo "$tabcolor"; ?>" class="tabA"><label>

$ <?php

echo $price;

?>

</label>

</td>

</tr>

<?php }// while loop ?>

<?PHP

}//for

echo"</table>";

}

//now this is the link..

echo '<div class="pagination"><ul><li class="next"><a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a></li>';

$prev = $startrow - 10;

//only print a "Previous" link if a "Next" was clicked

if ($prev >= 0)

echo '<li class="prev"><a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Previous</a></li></ul></div>';

?>

<input type='submit' name='rcar' class='tbox' value='Repair Cars'>

<input type='submit' name='sell' class='tbox' value='Sell Cars'>

</center>

</form>

</div>

</td>

<td class=right NOWRAP>

</td>

</tr>

</Tbody>

</table>

<table cellSpacing=0 cellPadding=0 style="WIDTH: 100%">

<Tbody>

<tr>

<td class=bottomleft NOWRAP>

</td>

<td class=bottom NOWRAP>

</td>

<td class=bottomright NOWRAP>

</td>

</tr>

</tbody>

</table>

<br>

<br>

<?php include"rightside.php"; ?>
PHP:

Николаев Кирилл


Рег
25 May, 2012

Тем
1

Постов
2

Баллов
12
  • 09, Jun 2024
  • #2
Привет, Проблемы могут быть связаны с этим: 1. $username, где или когда пользователь нажимает следующую ссылку, он будет переходить на другую страницу, и это не считается публикацией на другой странице, если только $username не было фактически сохранено в задней памяти, например, в сеансе или файлах cookie.
 

ku4ka


Рег
01 Jan, 2011

Тем
0

Постов
2

Баллов
2
Тем
49554
Комментарии
57426
Опыт
552966

Интересно