2 buttons with php

  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

is it possible to have 2 buttons: 1 that is able to be NEXT and the other to be PREVIOUS. if you keep pressing the NEXT button it adds 1 to the id so you display the next id number and the same but opposite for the PREVIOUS button, it take 1 away from the id. also with a stipulation that if id = < 1 { id = 1 or something like that. i hope you are able to understand this crude pseudo.

this way i can display all the form entrees in the same html form that the user fills in rather than a long lifeless table
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Yes you can.
Do something like this:
PHP Code: [ Select ]
$result = mysql_query("SELECT * FROM `table` WHERE `id` = '$_GET[id]'");
 
$q = mysql_fetch_object($result);
 
echo "Item Title:$q->title<br>
 
Date Added: $q->date<br>
 
Item Number: $q->id<br>
 
<p align=\"right\">";
 
$check1= mysql_query("SELECT MIN(id) as id FROM `table`");
 
$check1 = mysql_fetch_object($check1);
 
if($check1->id != $_GET['id']) {
 
     $newid = $_GET['id']-1;
 
     echo "<a href=\"$PHP_SELF?id=$newid\"><-Previous</a> ";
 
}
 
$check2 = mysql_query("SELECT MAX(id) as id FROM `table`");
 
$check2 = mysql_fetch_object($check2);
 
if($check2->id != $_GET['id']) {
 
     $newid = $_GET['id']+1;
 
     echo " <a href=\"$PHP_SELF?id=$newid\">Next-></a>";
 
}
 
echo "</p>";
  1. $result = mysql_query("SELECT * FROM `table` WHERE `id` = '$_GET[id]'");
  2.  
  3. $q = mysql_fetch_object($result);
  4.  
  5. echo "Item Title:$q->title<br>
  6.  
  7. Date Added: $q->date<br>
  8.  
  9. Item Number: $q->id<br>
  10.  
  11. <p align=\"right\">";
  12.  
  13. $check1= mysql_query("SELECT MIN(id) as id FROM `table`");
  14.  
  15. $check1 = mysql_fetch_object($check1);
  16.  
  17. if($check1->id != $_GET['id']) {
  18.  
  19.      $newid = $_GET['id']-1;
  20.  
  21.      echo "<a href=\"$PHP_SELF?id=$newid\"><-Previous</a> ";
  22.  
  23. }
  24.  
  25. $check2 = mysql_query("SELECT MAX(id) as id FROM `table`");
  26.  
  27. $check2 = mysql_fetch_object($check2);
  28.  
  29. if($check2->id != $_GET['id']) {
  30.  
  31.      $newid = $_GET['id']+1;
  32.  
  33.      echo " <a href=\"$PHP_SELF?id=$newid\">Next-></a>";
  34.  
  35. }
  36.  
  37. echo "</p>";

This is assuming that your id field is called id and that your variable would also be id.
You should be able to figure out how to change it if you need to.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i would like to display row 1 info then press the NEXT button to display row 2 info. and vice versa for the PREVIOUS button. i already am selecting from a database all the variables that were read into the database. basically i want to adapt the buttons to display the next/prev record from the table. does this example above still hold true in all counts?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i have tried the code. i think i need some help with it. all it is doing is going to the next id but displaying nothing. this is what i have so far
PHP Code: [ Select ]
<?php
 
$user="";
 
$host="";
 
$password="";
 
$database="";
 
$connection=mysql_connect($host,$user,$password) or die ("could not connect to server");
 
$db=mysql_select_db($database,$connection);
 
$result = mysql_query("select * from gstrialforma where id = '$_GET[id]'",$connection);
 
$q = mysql_fetch_object($result);
 
$check1= mysql_query("select min(id) as id from gstrialforma");
 
$check1 = mysql_fetch_object($check1);
 
$check2 = mysql_query("select max(id) as id from gstrialforma");
 
$check2 = mysql_fetch_object($check2);  
 
?>
  1. <?php
  2.  
  3. $user="";
  4.  
  5. $host="";
  6.  
  7. $password="";
  8.  
  9. $database="";
  10.  
  11. $connection=mysql_connect($host,$user,$password) or die ("could not connect to server");
  12.  
  13. $db=mysql_select_db($database,$connection);
  14.  
  15. $result = mysql_query("select * from gstrialforma where id = '$_GET[id]'",$connection);
  16.  
  17. $q = mysql_fetch_object($result);
  18.  
  19. $check1= mysql_query("select min(id) as id from gstrialforma");
  20.  
  21. $check1 = mysql_fetch_object($check1);
  22.  
  23. $check2 = mysql_query("select max(id) as id from gstrialforma");
  24.  
  25. $check2 = mysql_fetch_object($check2);  
  26.  
  27. ?>


i have this code on the text button at the bottom
previous
PHP Code: [ Select ]
<?php if($check1->id != $_GET['id']) { $newid = $_GET['id']-1; echo "<a href=\"formview.php?id=$newid\"><- Previous</a>"; }?>


next
PHP Code: [ Select ]
<?php if($check2->id != $_GET['id']) { $newid = $_GET['id']+1; echo "<a href=\"formview.php?id=$newid\">Next -></a>"; }?>


i am not sure whether to you this:
PHP Code: [ Select ]
<? echo $_GET['name']?>
or this
PHP Code: [ Select ]
<? echo $_POST['email']?>
neither is returning anything.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

this is the script i am using to increment the id and therefore display the next row of information but its not working. take a look for me plase and help me spot why it isnt running properly. the incremental id works but the records are not showing. plus there is something happenin with the id itself. there needs to be a condition that makes it start at id=1 and no lower.

PHP Code: [ Select ]
$result = mysql_query("select * from gstrialforma",$connection);
 
$check1= mysql_query("select MIN(id) as '{$_GET['id']}' from gstrialforma");
 
$check1 = mysql_fetch_object($check1);
 
$check2 = mysql_query("select MAX(id) as '{$_GET['id']}' from gstrialforma");
 
$check2 = mysql_fetch_object($check2);
 
echo "<table border=1 cellpadding=2 cellspacing=2 class=biggertext>";
 
echo "all table headers";
 
if ($myrow = mysql_fetch_array($result))
 
{
 
echo "all row information"
 
}
 
echo "</table>";
 
echo "<table><tr><td>";//below is my increment script to show the next row of information
 
if($check1->id != $_GET['id'])
 
{
 
$newid = $_GET['id']-1;
 
echo "<a href=\"tableview4.php?id=$newid\" class=\"biggertext\"><- Previous</a>";
 
}
 
if($check2->id != $_GET['id'])
 
{
 
$newid = $_GET['id']+1;
 
echo "<a href=\"tableview4.php?id=$newid\" class=\"biggertext\">Next -></a>";
 
}
 
echo "</td></tr></table>";
 
?>
  1. $result = mysql_query("select * from gstrialforma",$connection);
  2.  
  3. $check1= mysql_query("select MIN(id) as '{$_GET['id']}' from gstrialforma");
  4.  
  5. $check1 = mysql_fetch_object($check1);
  6.  
  7. $check2 = mysql_query("select MAX(id) as '{$_GET['id']}' from gstrialforma");
  8.  
  9. $check2 = mysql_fetch_object($check2);
  10.  
  11. echo "<table border=1 cellpadding=2 cellspacing=2 class=biggertext>";
  12.  
  13. echo "all table headers";
  14.  
  15. if ($myrow = mysql_fetch_array($result))
  16.  
  17. {
  18.  
  19. echo "all row information"
  20.  
  21. }
  22.  
  23. echo "</table>";
  24.  
  25. echo "<table><tr><td>";//below is my increment script to show the next row of information
  26.  
  27. if($check1->id != $_GET['id'])
  28.  
  29. {
  30.  
  31. $newid = $_GET['id']-1;
  32.  
  33. echo "<a href=\"tableview4.php?id=$newid\" class=\"biggertext\"><- Previous</a>";
  34.  
  35. }
  36.  
  37. if($check2->id != $_GET['id'])
  38.  
  39. {
  40.  
  41. $newid = $_GET['id']+1;
  42.  
  43. echo "<a href=\"tableview4.php?id=$newid\" class=\"biggertext\">Next -></a>";
  44.  
  45. }
  46.  
  47. echo "</td></tr></table>";
  48.  
  49. ?>

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 65 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.