[HELP] Table Help

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
MannyG
Forum Newbie
Posts: 4
Joined: Thu Mar 25, 2010 11:09 am

[HELP] Table Help

Post by MannyG »

Hello I have joined this forum for the sole purpose of trying to get this problem resolved so if you would please take a few minutes of your day to help out I would appreciate it very much.

I am a working on a dynamic table that communicates with a database (MySQL) where I can query results and such. In this table it works as a sort of "progress page" that shows test-results for certain test-cases on some products. However I am a co-op student and this is my first time working with PHP (and Javascript but I need help with the PHP part of things I guess?..) and in the table I created I have each row that is displayed to automatically have a button created beside it so that I can use that button to edit that particular row. The tricky part is I do not know how to make that button to be individual to a specific row and not end up changing the entire tables results (instead of being independent to that row it is with). I am not even sure I am explaining it correctly but I hope so. Basically this button works as an "edit" button so that it prompts an edit screen where you can change a row's results (and it will take your new added information and query it into the database).

Now I will provide a sort of scenario that will give you a better idea of how I want this to work...
So let us assume that there is 4 rows of data in the database and the table outputs these 4 rows, well if I add 40 more rows of data into the database the table will now output (upon a refresh of the html page) 44 rows. So I need the "edit" button to be dynamic so that it has a single relationship with the row it is in
Here is the code of my creation of the button.

Code: Select all

<?php 
         ## Display Table and database results
    while($results = mysql_fetch_array($build_device_test)){
        
        echo"<tr>";
        echo    "<td class='side' >".$results['version']."</td>";
        echo    "<td class='CBundle' >" .$results['bundle']."</td>";
        echo    "<td class='CDevice' >".$results['devicename']."</td>";
        echo    "<td class='CJava' ></td>";
        echo    "<td class='CMMS' ></td>";
        echo    "<td class='CBranch' ></td>";
        echo    "<td class='CJC' ></td>";
        echo    "<td class='selection' ><button type='button' onclick='disp_prompt()'>Edit</button></td>"; 
     /* I am creating   the button for each row that is displayed on the table, and the disp_prompt is a basic login javascript thing I did based on alert box for the sake of seeing how to make it work. */
        echo"</tr>";
        }
 
echo"</tbody>";
echo"</table>";
?>
I have thought of using grid control, and so I used the slgrid open source which can be found here however I cannot use their edit screen nor can I use massive joins (as I have set up in my code).

I cannot disclose any specific information as these test cases are sensitive upon release (for the companies...and my job's sake) and I apologize for the length of this post or the difficulty of this problem.

Thank you,

Manny
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: [HELP] Table Help

Post by mikosiko »

well... you are close...

you basically need:

- Modify your script to be able to call another php script (recordedit.php per example) (like you are doing here onclick='disp_prompt()'>Edit) but you must pass as parameter to the scrip the record ID (the one that you have defined as the primary key in your table).

- Create the "recordedit.php" able to:
* Receive the "record ID" parameter (using $_GET)
* Query your database for that specific "record ID"
* Display the record as a form, accept and validate data entry and finally update your database

Note: Look in the forum for the post "PHP MYSQL Update & Delete problems" (under PHP-Code section) and on it for the "edit.php" code... you can use that as an example

hope this help
Post Reply