How to show chosen data row from database in other page?

Discussion in 'PHP' started by Noss, Jul 30, 2009.

  1. #1
    Hello to everyone,

    Could you help me or suggest how to do it: my idea is to show data on other page after clicking the button. Till now i have done is printing a table which has data taken from database. Every row in the end has a button, then this button is pressed i want to take all information in this row and show it in other page. Example: if i choose row number 3, all data from that row has to be printed in other page. Can you suggest or show how to do it?

    This is my code:

    <? session_start();
    include ("db.php");
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untiteled</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    <table width="900" border="0" cellpadding="0" cellspacing="0" class="rem">
      <tr>
        <td>
    	<?php 
     
    if ($_SESSION['username'])
    	echo "Hello, ".$_SESSION['username']."!<br><a href='logout'>Logout</a>";
    else
    	echo "You have to <a href='index.php'>log in</a>";
    
    $result = mysql_query("select * from user");
    
    $myrow = mysql_fetch_array ($result);
    do 
    {
        printf("<table width='900' border='0' cellpadding='0' cellspacing='0' class='rem'>
      <tr>
        <td>
    	
    </td>
      </tr>
      <tr>
        <td>
    	<table class='tam' width='900' border='0' cellspacing='0' cellpadding='0'>
          <tr>
            <td>Number</td>
            <td>Name</td>
            <td>Last Name</td>
            <td>Email</td>
            
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width='900' border='0' cellspacing='0' cellpadding='0'>
          <tr>
            <td width='92'>%s</td>
            <td width='342'>%s</td>
            <td width='157'>%s</td>
            <td width='179'>%s</td>
            
    		<td><input type='submit' value='Send' action='' ></td>
          </tr>
        </table></td>", $myrow['id'],$myrow['name'],$myrow['lname'],$myrow['mail']);
    	}
    	while ($myrow = mysql_fetch_array ($result));
    	?>
      </tr>
    </table>
    </body>
    </html>
    
    Code (markup):
    Thanks for help
     
    Noss, Jul 30, 2009 IP
  2. keaglez

    keaglez Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The easy way is to pass id to the next page, for example, the button can linked to send.php?id=xx where the id is the selected user unique id. Then the page retrieve the id and select the correct user database.
     
    keaglez, Jul 30, 2009 IP
  3. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #3
    <input type="hidden" name="first_name" value="<?php echo $myrow['first_name']; ?>" >

    You'd be putting the values of each row into hidden fields that dont show on HTML page.
    Make your button so that its active as an HTML form, use action="post" on the form's action attribute.

    On your next page convert to variables.
    example:
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];

    etc ..


    You'll be passing the variables in all those rows on your table page .. through hiddden fields because the data will be echoed as those hidden field values in php.
     
    ezprint2008, Jul 31, 2009 IP