Jump to content

Displaying a table using ID number as hyperlink


M8KWR

Recommended Posts

I am new to PHP, i am able to insert and display data to the end user, but i am trying to let the end user edit a row.

 

I am unsure how this is usually done, but i am have the following code to display by data

 


echo "<table border='1'><thead><tr>";
            for($i = 0;$i < mysql_num_fields($sql_result);$i++)
            {
             echo "<th>".mysql_field_name($sql_result,$i).
                  "</th>";
            }
     echo "</tr></thead>
           <tbody>";
     for ($i=0;$i < mysql_num_rows($sql_result);$i++)
     {
        echo "<tr>";
        $row = mysql_fetch_row($sql_result);
        foreach($row as $value)
        {
           echo "<td>".$value."</td>";
        }
        echo "</tr>";
     }
     echo "</tbody></table>";

 

 

The user have a jump menu (combo box) to pick the table they need to show information on, so the columns displayed are going to vary, but i have a column called ID which is the same in each tables which is the index (auto increment) field.

 

I was thinking about using this number comnbined with a hyperlink, so the user can click it to take them to a page to edit that row....

 

But i have no idea how to do this, or if there is an easier way which i just do not know; or how do most people achieve what i require..........

 

any help or advice would be very much appreciated, and thanks in advance....

 

Not sure if you know this but along with what andyB said, you need to create an id colum in your users database.  Then do something like this:

$result = mysql_query( "SELECT * FROM users ORDER BY id" );

while ( $row = mysql_fetch_array( $result ) ) {
$id = $row['id'];
}

 

then for which id the user has it will display in the link:

 

<a href="edit_me.php?id=$id">

On the edit_me page:

$id = intval($_REQUEST['id']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.