Jump to content

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']);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.