• 0

MySql Help


Question

hello there

im currently building up a little shoutbox but have come across a lickle problem

at the moment i have this

<?php

ob_start(); 

$host = "localhost"; 
$username = "*****"; 
$password = "*****"; 
$databasename = "*****"; 

$ip = $_SERVER['REMOTE_ADDR'] . NULL; 
$ip = str_replace(".", "-", $ip); 

$c = mysql_connect($host, $username, $password) or die("Cannnot connect"); 
mysql_select_db($databasename, $c); 

$query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 5"; 
$result = mysql_query($query);

while( $r = mysql_fetch_array($result) ) { 
    $name = $r['name']; 
    $mail = $r['email']; 
    $message = $r['message']; 
    $date = $r['date']; 

	echo "<div class=\"coltop\">By: <a href=\"mailto:$mail\">$name</a> on: $date</div><div class=\"message\">$message</div><table width=\"150\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"onepx\" align=\"center\">
<tr>
      <td></td>
    </tr>
  </table>
"; 
} 

function submit() { 
    echo "<div align=\"center\"><form class=\"forminput\" name=\"shoutbox\" method=\"post\" action=\"shoutbox.php\">t;input class=\"forminputmain\" name=\"name\" type=\"text\" id=\"name\" value=\"Name\"> 
<input class=\"forminputmain\" name=\"email\" type=\"text\" id=\"email\" value=\"E-Mail\"> 
<textarea class=\"forminputmain\" name=\"message\" id=\"message\">Message</textarea> 
     <br> 
      <input class=\"forminputmain\" type=\"submit\" name=\"Submit\" value=\"Submit\"></form></div>"; 


    if (isset($_POST['name'])) { 
        mysql_query("INSERT INTO `shoutbox` (`name` , `email` , `message` , `date` , `remote_addr` ) VALUES ( '" . $_POST['name'] . "', '" . $_POST['email'] . "', '" . $_POST['message'] . "', '" . date("d/m/y") . "', '" . $ip . "');"); 
         
        $insertGoTo = "shoutbox.php";
  print "<script language=\"JavaScript\">";
print "window.location = '$insertGoTo' ";
print "</script>";
         
    } 
} 

submit(); 

?>

Now this works fine and everything is ok BUT i would like to add the option of next page previous page which i am having troubles doing.

I want it to show 5 results as it is doing fine but then as i say the option to go next and previous

Any help using the above code would be great!

Thanks in advance

Link to comment
https://www.neowin.net/forum/topic/249250-mysql-help/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

limit lets you set starting record, then how many records from that point on

<?

//z is the starting point, initilize to 0

$z = 0;

//add 5 to this starting point everytime user hit "next page"

if ($_REQUEST['z'])

$z = $_REQUEST['z'] + 5;

$query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT $z, 5";

?>

this is the link

<a href = <?=$PHP_SELF?>?z=<?=$z?>>Next Page</a>

Link to comment
https://www.neowin.net/forum/topic/249250-mysql-help/#findComment-584991463
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Clearly a lot of gamers. And I'm sorry but you are wrong, my 7800x3d (single ccd) offers huge benefits to me as a AAA 1440p gamer. And it's pretty dumb to crap on 1080p gamers as they make up like 90+% of steam gamers. But no, the x3d does not just offer benefits to esport gamers (one of the stupidest things I've seen in a while AND THATS SAYING SOMETHING.) Abd when I built my rig with my 7800x3d, I paired it with a RX7900xt and couldn't be happier.
    • Um, someone needs to tell this author the 7800x3d is a single ccd and shouldn't be affected. If this only effects the dual ccd, 7800x3d owners need not worry
    • Popular File Explorer alternative Files gets signature check, improved dual-pane, and more by Taras Buria A new update has arrived for File Preview, a feature-packed file manager for Windows 10 and 11. Version 3.9.14 introduces a useful new feature for file properties, dual-pane improvements, the ability to resize columns in the Columns View, and more. Starting with the Properties dialog, it now features a "Signatures" tab where you can view digital signatures associated with the file and their properties, such as version, issuer, expiry date, and more. You can also click the "Details" button to open Windows' native dialog. The dual-pane feature has been tweaked for a more intuitive experience. The "Add pane" command is now "Split pane." There is a new quick action for toggling dual-pane mode on or off, and settings now have a dedicated section for dual-pane mode. Finally, columns in the Columns View are now resizable, and search results now have a header with your current query. In addition to releasing the update, developers said the following regarding performance complaints from users: Files Preview is available in the Microsoft Store. You can purchase it there to support developers. Alternatively, you can get the app for free from the official website, and if you want to help developers with contributions or ideas, check out their Discord and GitHub.
    • So the iPhone only has a leading position in a few markets around the world: US, UK, UAE, couple of other smaller ones. As a result of the far more mixed eco-system Whatsapp is a lot more popular outside of the US than I think a lot of American's may realise. It's pretty much the messaging standard in the UK
  • Recent Achievements

    • First Post
      Soeaker4thedead earned a badge
      First Post
    • First Post
      kryptickid earned a badge
      First Post
    • First Post
      Nemesis-IV earned a badge
      First Post
    • First Post
      Aidan Helfrich earned a badge
      First Post
    • Collaborator
      bullgod69 earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      760
    2. 2
      ATLien_0
      187
    3. 3
      +FloatingFatMan
      151
    4. 4
      Xenon
      117
    5. 5
      wakjak
      113
  • Tell a friend

    Love Neowin? Tell a friend!