0

Okay, so I've literally spent all day trying to achieve this and have gotten nowhere. I am creating a flipbook (using turn.js). I have names and cause of death stored in a MySQL database. I want to print 5 names and their cause of death on each page. To add a page in turn.js, all i have to do is add a in

So i load the name and cause of death values into arrays, and then echo a whole div however with the array variable.

I'm really having trouble getting this into code. At the moment I have managed to get this onto seperate pages, but how would i get it to print only 5 on a page, and then create a new page (untill there are no more names)

Here is what i have so far.

<?php   
$dbc = mysql_connect('localhost', 'xxxx', 'xxxxxxx');
if (!$dbc) {
die('Not Connected: ' . mysql_error());
}

$db_selected = mysql_select_db("xxxxxx", $dbc);
if (!$db_selected)
{
die ("Can't Connect : " . mysql_error);
}
$query = "SELECT * FROM TABLE";
$result = mysql_query($query);

$victim = array();
$cod = array();
$count = 0;
while ($row = mysql_fetch_assoc($result)) {       
    $victim['$count'] = $row['Victim'];
    $cod['$count'] = $row['COD'];               
    $count++;   
}
?>
<div id="deathnote">
<div style="background-image:url(images/coverpage.jpg);"></div>
<div style="background-image:url(images/page1.jpg);"></div>
<div style="background-image:url(images/page2.jpg);"></div>
<div style="background-image:url(images/page3.jpg);"></div>
<div style="background-image:url(images/page4.jpg);"></div>
<div style="background-image:url(images/page5.jpg);"></div> 
<?php
for ($x=0; $x=$count; $x++) {
echo "<div style='background-image:url(images/page5.jpg);'></div><div class='content'><div class='name'>" . $victim['$x'] . "</div><div class='cod'>" . $cod['$x'] . "</div></div></div>";
}
?>  

Any help will be GREATLY appreciated. Thanks in advance, guys :)

Roy D. Porter
  • 159
  • 1
  • 11
  • Use `foreach` to iterate over ALL contents of an array. It's easier than fiddling with `for` and the indexes. – Sven Oct 30 '13 at 08:09
  • @Sven Thnks for the input! I'll quickly google it, sounds convenient. – Roy D. Porter Oct 30 '13 at 08:12
  • Maybe you should get familiar to PHP basics first. The issue that mentioned Harshit is a real beginner's error. – Christian Graf Oct 30 '13 at 08:19
  • [Please, stop using mysql_* functions](http://stackoverflow.com/q/12859942/1238019) in new code, they are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Instead of, have a look on [prepared statements](http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html), and use [Mysqli](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/book.pdo.php). – zessx Oct 30 '13 at 08:22

4 Answers4

0

Take a look at the $_GET variable http://php.net/manual/de/reserved.variables.get.php there you can set variables in the URL like http://lol.de/?form=1&to=5

$from = $_GET['from'];
$to = $_GET['to'];

if(!is_numeric($from) || !is_numeric($to)) die('SQL Injection');

$count = $to - $from;
$query = "SELECT * FROM TABLE LIMIT ".$from-",".$count;

Then you create a dynamic link, where you add 5 to $from and $to.

Not tested, just a Idea.

schnawel007
  • 3,982
  • 3
  • 19
  • 27
0

Check the last two line on your code, e.g.:

for ($x=0; $x=$count; $x++) {
echo "<div style='background-image:url(images/page5.jpg);'></div><div class='content'><div class='name'>" . $victim['$x'] . "</div><div class='cod'>" . $cod['$x'] . "</div></div></div>";

Change them to:

   $onPage = 5;
    $currentPage = 1;

for ($x=0; $x=$count; $x++) {

        if (($x % $onPage) == 0)
        {
            echo "<div style='background-image:url(images/page" . $currentPage . "jpg);'></div>";
            $currentPage++;
        }

            echo "<div class='content'>"
            . "<div class='name'>" . $victim['$x'] . "</div>"
            . "<div class='cod'>" . $cod['$x'] . "</div>"
            . "</div>";

}

You can play around with the "modulus" operator - %, to achieve the result you need.

0

Try below code.

$recordPerPage = 5;
<?php
for ($x=1; $x<=$count; $x++) {
  if($x <= $recordPerPage ) {
echo "<div style='background-image:url(images/page".$x.".jpg);'></div><div class='content'><div class='name'>" . $victim['$x'] . "</div><div class='cod'>" . $cod['$x'] . "</div></div></div>";
     }
$x = $recordPerPage;
$recordPerPage += $recordPerPage;
}
?>  

Hope this will help to you!

Cheers!

Dharmesh Thanki
  • 420
  • 3
  • 9
0

This may help you.

<?php
$recordPerPageCount = 5;
$pageCount = 1;
for ($x=0; $x<$count; $x++) { 
  if($x % $recordPerPageCount == 0) { 
     //This block will execute each time after diplaying five records in a page 
     $pageCount++;
  }

  echo "<div style='background-image:url(images/page".$pageCount.".jpg);'></div><div class='content'><div class='name'>" . $victim['$x'] . "</div><div class='cod'>" . $cod['$x'] . "</div></div></div>";

}
?>  
Dhivya
  • 689
  • 8
  • 14