By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,436 Members | 2,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,436 IT Pros & Developers. It's quick & easy.

Dynamically enabling / disabling a row's elements using PHP

P: 14

I have just started coding in PHP. I have coded a web page using HTML, JS, and PHP. An HTML table has to be populated dynamically using the data from the backend.

Presently I have 5 records in the backend table so I get 5 HTML-table rows. I have created a session object starting from the login page. The requirement is that as soon as I log in and my request gets forwarded to the foll PHP page I should be seeing the foll. dynamically generated table. This portion has been done.

The next part is that the very first time my request gets forwarded to the foll PHP page, only the first row's [i.e. Job Attribute Hierarchy (see pic)] Go-button and textbox should be enabled, the remaining rows' textboxes and buttons should be disabled.

When I enter the data in the first row's textbox and hit 'Go'.. I come to another PHP page where in I fill some more data and hit 'OK' thereby coming back to the foll. PHP page. At this time the first row should have its textbox and Go-buttons disabled and there should be a tickmark on the first cell of the row. At this time only the second row's textbox and Go-button should be enabled and 1,3,4,5 row's elements should be disabled. Again the same procedure repeats... I hit the Go button on second row [Job Rewards/Culture Hierarchy (see pic)].. and my request gets forwarded to some other page where I hit OK and come back to the foll PHP page. This time there is a tickmark on the second row's first cell and it's textbox and Go-button are disabled alongwith those of row's 1,2,4,5 and only row 3's elements are enabled... and so on..

I believe I should be setting a flag variable as a session attribute to achieve this, but I am not getting a clear idea as to how I should use this flag to dynamically enable-disable the textboxes and Go-buttons. Any suggestions?



$flag = 0;

if(!isset ($_SESSION['flag']))
$flag = 1;
$_SESSION['flag'] = $flag;
$flag++ ;
$_SESSION['flag'] = $flag;

<table align = "center" id = "TID" border = "1" cellpadding = "3" cellspacing = "3">
$selectMasterAttributes = "select * from MasterAttributes ;" ; // select all columns(Name,NameId,Active)
$selectMasterAttributes_result = mysql_query($selectMasterAttributes) or die("Error with $selectMasterAttributes ");

if(mysql_num_rows($selectMasterAttributes_result) > 0)// proceed with the dynamic attribute-row-creation only if backend attribute table contains any attributes

while($row = mysql_fetch_array($selectMasterAttributes_result))
$MAttrName = $row['Name'];
//echo $MAttrName . '<br>' ;
$MAttrNameId = $row['NameId'];
//echo $MAttrNameId . '<br>';
$MAttrActive = $row['Active'];
//echo $MAttrActive . '<br>' ;

echo '<tr id = "' . $MAttrNameId . '">';
echo '<td bgcolor = "orange">' . $MAttrNameId . '</td>';
echo '<td>' . $MAttrName . '</td>';
echo '<td ><input type = "text" size = "5" id = "Attr'. $MAttrNameId .'" name = "Attr'. $MAttrNameId .'"></td>';
echo '<td><input type = "submit" name = "go' . $MAttrNameId . '" value = "Go" onclick = "set_attr_name("></input></td>';
echo '</tr>';


}// (mysql_num_rows($selectMasterAttributes_result) > 0) over
echo '<tr><td colspan = "4"> No Attributes Present in backend</td></tr>' ;

Attached Files
File Type: zip (42.8 KB, 165 views)
Dec 13 '07 #1
Share this Question
Share on Google+
1 Reply

P: 14
Hi again,

The problem is resolved now, thanks anyway.

Dec 13 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.