Avatar billede larsgrau Forsker
02. maj 2018 - 13:59 Der er 5 kommentarer og
2 løsninger

Næste Post

Jeg har følgende kode:
<?php
include "../conf/db-connect.php"
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<link href="Rettelse_til_Billeder.css" rel="stylesheet">
<link href="index.css" rel="stylesheet">
</head>
<body>
<form >
<?php
$res=mysqli_query($conn,"SELECT * FROM `main` WHERE `ribilleder` = 1 and `rtbilleder` = 0");
while($row=mysqli_fetch_array($res))
{
?>   
<div id="wb_Text1" style="position:absolute;left:27px;top:14px;width:662px;height:23px;z-index:1;">
<span style="color:#000000;font-family:Arial;font-size:20px;">Rettelse til Billeder</span></div>
<input type="text" id="Editbox1" style="position:absolute;left:153px;top:51px;width:323px;height:23px;line-height:23px;z-index:2;" name="Editbox1" value="<?php echo $row["dato"]; ?>" spellcheck="false">
<input type="text" id="Editbox2" style="position:absolute;left:153px;top:94px;width:654px;height:23px;line-height:23px;z-index:3;" name="Editbox1" value="<?php echo $row["Emne"]; ?>" spellcheck="false">
<input type="text" id="Editbox3" style="position:absolute;left:153px;top:135px;width:654px;height:281px;line-height:281px;z-index:4;" name="Editbox1" value="<?php echo $row["Rettelse"]; ?>" spellcheck="false">
<input type="text" id="Editbox4" style="position:absolute;left:153px;top:442px;width:654px;height:18px;line-height:18px;z-index:5;" name="Editbox1" value="<?php echo $row["Source"]; ?>" spellcheck="false">
<input type="text" id="Editbox5" style="position:absolute;left:153px;top:481px;width:654px;height:18px;line-height:18px;z-index:6;" name="Editbox1" value="<?php echo $row["country"]; ?>" spellcheck="false">
<input type="text" id="Editbox6" style="position:absolute;left:153px;top:521px;width:654px;height:18px;line-height:18px;z-index:7;" name="Editbox1" value="<?php echo $row["retter"]; ?>" spellcheck="false">

<div id="wb_Checkbox1" style="position:absolute;left:153px;top:560px;width:20px;height:20px;z-index:8;">
<input type="checkbox" id="Checkbox1" name="" value="on" style="position:absolute;left:0;top:0;"><label for="Checkbox1"></label></div>

<label for="" id="Label1" style="position:absolute;left:19px;top:51px;width:126px;height:25px;line-height:25px;z-index:9;">Dato</label>
<label for="" id="Label2" style="position:absolute;left:19px;top:94px;width:126px;height:25px;line-height:25px;z-index:10;">Emne</label>
<label for="" id="Label3" style="position:absolute;left:19px;top:135px;width:126px;height:25px;line-height:25px;z-index:11;">Rettelse</label>
<label for="" id="Label4" style="position:absolute;left:19px;top:440px;width:126px;height:25px;line-height:25px;z-index:12;">Source</label>
<label for="" id="Label5" style="position:absolute;left:19px;top:479px;width:126px;height:25px;line-height:25px;z-index:13;">Land</label>
<label for="" id="Label6" style="position:absolute;left:19px;top:519px;width:126px;height:25px;line-height:25px;z-index:14;">Indtastet af</label>
<label for="" id="Label7" style="position:absolute;left:19px;top:554px;width:59px;height:25px;line-height:25px;z-index:15;">Rettet</label>

<input type="submit" id="Button1" name="nrettelse" value="Næste rettelse" style="position:absolute;left:169px;top:600px;width:155px;height:41px;z-index:16;">


<?php
}
?>


<input type="submit" id="Button2" name="frettelse" value="Forrige rettelse" style="position:absolute;left:349px;top:600px;width:155px;height:41px;z-index:17;">
<input type="submit" id="Button3" name="update1" value="Rettet og Næste" style="position:absolute;left:529px;top:600px;width:155px;height:41px;z-index:18;">

<input type="date" id="Editbox7" style="position:absolute;left:268px;top:557px;width:226px;height:25px;line-height:18px;z-index:19;" name="Editbox1" value="" spellcheck="false">
<select name="Combobox1" size="1" id="Combobox1" style="position:absolute;left:515px;top:557px;width:302px;height:28px;z-index:20;">
<option>-- Vælg retter --</option>
<?php
$res=mysqli_query($conn,"select * from retter");
while($row=mysqli_fetch_array($res))
{
?>
<option><?php echo $row["Navn"]; ?></option>
<?php
}
?>
</select>
</body>
</html>

Det jeg godt kunne tænke mig er at når man trykker på
<input type="submit" id="Button1" name="nrettelse" value="Næste rettelse" style="position:absolute;left:169px;top:600px;width:155px;height:41px;z-index:16;"> så går man til næste post i den
$res=mysqli_query($conn,"SELECT * FROM `main` WHERE `ribilleder` = 1 and `rtbilleder` = 0");
while($row=mysqli_fetch_array($res))

er der nogen som kan hjælpe mig ?
Avatar billede Slettet bruger
02. maj 2018 - 18:40 #1
du skal definere et recordset med de data du henter, og så hedder det vist movenext.
https://www.w3schools.com/asp/met_rs_movefirst.asp
Avatar billede olsensweb.dk Ekspert
03. maj 2018 - 08:57 #2
dit søgeord er paging / pagination, evt kombineret med tut

https://www.google.dk/search?q=php+paging
https://www.google.dk/search?q=php+paging+tut

https://www.google.dk/search?q=php+pagination
https://www.google.dk/search?q=php+pagination+tut
https://www.google.dk/search?q=php+pagination+mysqli+tut

https://www.tutorialspoint.com/php/mysql_paging_php.htm
nb, bruger det gamle mysql API

https://phppot.com/php/ajax-pagination-with-php/
kunne være sjov at kigge på, men den blander AJAX ind også, hvilke komplicerer det yderligere, men er mere effektiv

nb: du vil gøre din code mere læsbar ved ikke at bruge inline CSS
Avatar billede larsgrau Forsker
04. maj 2018 - 21:22 #3
Takker mange gange jeg fandt hvad jeg kigge efter, jeg fandt denne og det er ikke meget tilpasning for at den virker

<?php
// You have to put your mysql connection data and alter the SQL queries(both queries)
mysql_connect("DB_Host_Here","DB_Username_Here","DB_Password_Here") or die (mysql_error());
mysql_select_db("DB_Name_Here") or die (mysql_error());
//////////////  QUERY THE MEMBER DATA INITIALLY LIKE YOU NORMALLY WOULD
$sql = mysql_query("SELECT id, firstname, country FROM myTable ORDER BY id ASC");
//////////////////////////////////// Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////
$nr = mysql_num_rows($sql); // Get total of Num rows from the database query
if (isset($_GET['pn'])) { // Get pn from URL vars if it is present
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new)
    //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated)
} else { // If the pn URL variable is not present force it to be value of page number 1
    $pn = 1;
}
//This is where we set how many database items to show on each page
$itemsPerPage = 10;
// Get the value of the last page in the pagination result set
$lastPage = ceil($nr / $itemsPerPage);
// Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage
if ($pn < 1) { // If it is less than 1
    $pn = 1; // force if to be 1
} else if ($pn > $lastPage) { // if it is greater than $lastpage
    $pn = $lastPage; // force it to be $lastpage's value
}
// This creates the numbers to click in between the next and back buttons
// This section is explained well in the video that accompanies this script
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
} else if ($pn == $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
}
// This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
// Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax
// $sql2 is what we will use to fuel our while loop statement below
$sql2 = mysql_query("SELECT id, firstname, country FROM myTable ORDER BY id ASC $limit");
//////////////////////////////// END Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////
$paginationDisplay = ""; // Initialize the pagination output variable
// This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastPage != "1"){
    // This shows the user what page they are on, and the total number of pages
    $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '&nbsp;  &nbsp;  &nbsp; ';
    // If we are not on page 1 we can place the Back button
    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> ';
    }
    // Lay in the clickable numbers display here between the Back and Next links
    $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
    // If we are not on the very last page we can place the Next button
    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> ';
    }
}
///////////////////////////////////// END Adam's Pagination Display Setup ///////////////////////////////////////////////////////////////////////////
// Build the Output Section Here
$outputList = '';
while($row = mysql_fetch_array($sql2)){

    $id = $row["id"];
    $firstname = $row["firstname"];
    $country = $row["country"];

    $outputList .= '<h1>' . $firstname . '</h1><h2>' . $country . ' </h2><hr />';

} // close while loop
?>
<html>
<head>
<title>Adam's Pagination</title>
<style type="text/css">
<!--
.pagNumActive {
    color: #000;
    border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:link {
    color: #000;
    text-decoration: none;
    border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:visited {
    color: #000;
    text-decoration: none;
    border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:hover {
    color: #000;
    text-decoration: none;
    border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:active {
    color: #000;
    text-decoration: none;
    border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
-->
</style>
</head>
<body>
  <div style="margin-left:64px; margin-right:64px;">
    <h2>Total Items: <?php echo $nr; ?></h2>
  </div>
      <div style="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
      <div style="margin-left:64px; margin-right:64px;"><?php print "$outputList"; ?></div>
      <div style="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
</body>
</html>
Avatar billede olsensweb.dk Ekspert
05. maj 2018 - 07:49 #4
#3
kom gerne med en referance til hvor du har fundet coden, det kan gavne andre.

husk at opdaterer database api til mysqli eller PDO, da det anvendte API er fjernet i PHP7
Avatar billede larsgrau Forsker
05. maj 2018 - 21:15 #5
Den er fundet her

https://stackoverflow.com/questions/8317216/pagination-in-php-paginate-comments

og ja man skal huske det hedder mysqli nu *S*
Avatar billede Kumar Singh Praktikant
12. juli 2018 - 18:42 #6
Avatar billede Meer Ahtisham Praktikant
05. august 2018 - 03:52 #7
Very nice and interesting
<a href="http://sa.quickharaj.com/room-for-rent/8">room for rent in jeddah</a>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester