change hidden value name in foreach() ???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ganza
Forum Newbie
Posts: 19
Joined: Fri Nov 07, 2008 3:56 am

change hidden value name in foreach() ???

Post by ganza »

Code: Select all

 
if(isset($_REQUEST["Submit"]) == true){
    $contactList = "SELECT * FROM contact WHERE client_ID = ('".$_REQUEST["client_ID"]."')";
    $db->sql_query($contactList);
    $list = $db->sql_fetchrowset();
    echo "<form id=\"delContact\" name=\"delContact\" method=\"post\" action=\"\">\r\n";
    echo "<table border=1>\r\n";
    echo "<tr>\r\n";
    echo "  <td>Person in Charge</td>\r\n";
    echo "  <td>Designation</td>\r\n";
    echo "  <td>Department</td>\r\n";
    echo "  <td>Main Line</td>\r\n";
    echo "  <td>Fax Line</td>\r\n";
    echo "  <td>Direct Line</td>\r\n";
    echo "  <td>Mobile</td>\r\n";
    echo "</tr>\r\n";
    foreach($list as $record)
    {
        echo "<tr>\r\n";
        echo "  <td>".$record['personIncharge']."\r\n";
        echo "  <input type='submit' name='EditPIC' value='edit'></td>\r\n";
        echo "  <input type='hidden' value=".$record['contact_ID']." name='uiuaa'>\r\n"; 
        echo "  <td>".$record['designation']."</td>\r\n";
        echo "  <td>".$record['department']."</td>\r\n";
        echo "  <td>".$record['mainLine']."</td>\r\n";
        echo "  <td>".$record['faxLine']."</td>\r\n";
        echo "  <td>".$record['directLine']."</td>\r\n";
        echo "  <td>".$record['mobile']."</td>\r\n";
        echo "  <td><a href='deleteRow.php?id=".$record["contact_ID"]."'>Delete</a></td>\r\n";
        echo "</tr>\r\n"; 
    }
    echo "</table>\r\n";
}
 
function code1 is: when i click submit it will read contact table in database
and it will show into html table using foreach statement
so it will come out like this:
_______________________________________________________________
|Person In charge | designation | department | main line | faxline | mobile|
-------------------------------------------------------------------------
|person1 [edit bttn]| designation1 | dept 1 | 222222 | 222222| 22222|
|person2 [edit bttn]| designation2 | dept 2 | 333333 | 333333|33333 |
| ETC .... (depends on how many i have in mysql table |
--------------------------------------------------------------------------

and if i press the edit button... the text field will be come out liket this:
____________________________________
|___Enter_new_person_in_charge_here ___| [UPDATE BUTTON]

and then i enter new person in charge name and press the update button. so it will update the person in charge name in my database table.

this is the if statement that i've made but its not working .... i dunno how to resolve this problem :banghead: :crazy: :banghead: :crazy:

Code: Select all

 
if(isset($_REQUEST["EditPIC"]) == true){
    echo "<input name='editPIC' id='editPIC' type='text'>\r\n";
    echo "  <input type='hidden' value=".$_REQUEST["uiuaa"]." name='uiuaa2'>\r\n";
    echo "<input name='submitPIC' id='submitPIC' type='submit' value='update!'>\r\n";
    print_r($_REQUEST);
}
 
if(isset($_REQUEST["submitPIC"]) == true) {
    $editPIC = "UPDATE contact SET personIncharge='".$_REQUEST["editPIC"]."' WHERE contact_ID='".$_REQUEST["uiuaa2"]."'"; 
    $db->sql_query($editPIC);
    print_r($_REQUEST);
}
 
i think because every hidden name that show by foreach statement will be the same ("uiuaa")
so example:
foreach statement show there is 5data from my sql table
and each data contain 1hidden value that i've wrote in foreach statement ... and all hidden value name is the same "uiuaa"
is there anyone can give solution for my problem?
im stuck doing this the whole day :banghead:
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: change hidden value name in foreach() ???

Post by novice4eva »

You have few options here:
1st one i think is to create multiple FORMS:

Code: Select all

 
foreach($list as $record)
    {
        echo "<tr>\r\n";
        echo "  <td>".$record['personIncharge']."\r\n";
        echo "<form action="post">
        echo "  <input type='submit' name='EditPIC' value='edit'></td>\r\n";
        echo "  <input type='hidden' value=".$record['contact_ID']." name='uiuaa'>\r\n"; 
        echo "</form>";
.......
 
and this i think won't render cool in IE (it always bloated divs/td in IE)

2nd one is well JAVASCRIPT:
you can create just one

Code: Select all

<input type='hidden' name='uiuaa' id='uiuaa'>
BEFORE your foreach loop
and when you click on submit you can call a javascript function to set the value of this field :

Code: Select all

 
<input type='button' name='EditPIC' value='edit' onClick="document.getElementById('uiuaa').value='<?php echo $record['contact_ID'];?>'; this.form.submit(); "></td>\r\n";
 
Then there is this third one, which is quite tricky and exceptionally COOL and that process my friend is known only by the MODS who have over 10000 of posts here heheeh :mrgreen:

:drunk:
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: change hidden value name in foreach() ???

Post by novice4eva »

CORRECTIONNNN

Code: Select all

 
echo "<form action="post">
 
sorry it should have been

Code: Select all

echo "<form method="post" >
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: change hidden value name in foreach() ???

Post by novice4eva »

May i again, my head is not in place

Code: Select all

 
echo "<form method=\"post\">";
 
:oops: :mrgreen:
Post Reply