nezbo Posted January 4, 2008 Share Posted January 4, 2008 Hi all I have a from that i want to repeat over an over again. i have setup a page where it sets up a table, with a link for the id number what you click on to activate it, and a drop for the diffrent options. the way i have got it to work is to refresh the fpage and keep the drop down. but then it all the items become a same. Hope this makes sense. here is the code <?php $details = mysql_query("SELECT * FROM users WHERE validateUser = 0 ORDER BY surname") or mysql_error(); while ($getUserDetails = mysql_fetch_array($details)) { $userGroupe = mysql_query("SELECT * FROM usergroups " . NEW_WHERE . "") or die(mysql_error()); $area = mysql_query("SELECT * FROM area WHERE valid = 0 and areaID = '$getUserDetails[area]'") or mysql_error(); while ($getArea = mysql_fetch_array($area)) { $theArea = $getArea['areaName']; } echo "<tr class=bTable>"; echo "<td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?g=" . $_POST['userGroups'] . "&selectedNewUser=" . $getUserDetails['userID'] . "&o=1>Yes</a></span></td><td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?selectedNewUser=" . $getUserDetails['userID'] . "&o=2>No</a></span></td><td><span class=\"small\"> $getUserDetails[userName]</span></td><td><span class=\"small\">$getUserDetails[forename] $getUserDetails[surname]</span></td><td><span class=\"small\">$theArea</span></td><td><span class=\"small\">$getUserDetails[resion]</span></td>"; echo "<td><select name='userGroups' onchange=form1.submit()><option value=''>" . F_SELECT_ONE . "</option>"; while($noticia = mysql_fetch_array($userGroupe)) { echo "<form action=" . $_SERVER['PHP_SELF'] . " name=\"form1\" method=\"post\">"; if ($_POST['userGroups'] == $noticia['groupID']) { echo "<option selected=\"selected\" value='$noticia[groupID]'>$noticia[groupName]</option>"; } else { echo "<option value='$noticia[groupID]'>$noticia[groupName]</option>"; } echo "</form>"; } echo "</td>"; echo "</tr>"; } ?> is there any other way of doing this? Neil Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/ Share on other sites More sharing options...
nezbo Posted January 4, 2008 Author Share Posted January 4, 2008 i guess the main thing i want to do is update a link i have the link : $_SERVER['php_self'] . "g= ***** the ***** is the point i want to get a dropdown to input the number of the group (the group is in the drop down) Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430155 Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 2 things I can come up with: 1. AJAX 2. Refresh page with a URL that has the selected item appended onto it so you can GET the value and do something. Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430166 Share on other sites More sharing options...
rajivgonsalves Posted January 4, 2008 Share Posted January 4, 2008 your whole syntax is wrong you are having the form tag in the select tag ????.... isn't it supposed to be the other way round... this would never give you proper results.. you see your form tag will keep repeating for each iteration what exactly are you trying to achieve ?? Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430173 Share on other sites More sharing options...
nezbo Posted January 4, 2008 Author Share Posted January 4, 2008 i have no idea how to use Ajax, unless any one has any idea how to do this? and i am also not to sure how to do this with the for refresh either. i have updated my code so it refreshes, but it doesnt work. <?php $form = array(); $details = mysql_query("SELECT * FROM users WHERE validateUser = 0 ORDER BY surname") or mysql_error(); echo "<form action=" . $_SERVER['PHP_SELF'] . " name=\"form1\" method=\"post\">"; while ($getUserDetails = mysql_fetch_array($details)) { $userGroupe = mysql_query("SELECT * FROM usergroups " . NEW_WHERE . "") or die(mysql_error()); $area = mysql_query("SELECT * FROM area WHERE valid = 0 and areaID = '$getUserDetails[area]'") or mysql_error(); while ($getArea = mysql_fetch_array($area)) { $theArea = $getArea['areaName']; } echo "<tr class=bTable>"; echo "<td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?g=" . $_POST['userGroups'] . "&selectedNewUser=" . $getUserDetails['userID'] . "&o=1>Yes</a></span></td><td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?selectedNewUser=" . $getUserDetails['userID'] . "&o=2>No</a></span></td><td><span class=\"small\"> $getUserDetails[userName]</span></td><td><span class=\"small\">$getUserDetails[forename] $getUserDetails[surname]</span></td><td><span class=\"small\">$theArea</span></td><td><span class=\"small\">$getUserDetails[resion]</span></td>"; echo "<td><select name='userGroups' onchange=form1.submit()><option value=''>" . F_SELECT_ONE . "</option>"; while($noticia = mysql_fetch_array($userGroupe)) { if ($_POST['userGroups'] == $noticia['groupID']) { echo "<option selected=\"selected\" value='$noticia[groupID]'>$noticia[groupName]</option>"; } else { echo "<option value='$noticia[groupID]'>$noticia[groupName]</option>"; } } echo "</td>"; echo "</tr>"; } echo "</form>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430178 Share on other sites More sharing options...
nezbo Posted January 4, 2008 Author Share Posted January 4, 2008 I have attached an image to try an make it easyer to understand. i need to update the yes link with the dropdown. (in the image, the dropdown) [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430183 Share on other sites More sharing options...
rajivgonsalves Posted January 4, 2008 Share Posted January 4, 2008 here you go hope its helpfull.. change quite a lot of things <?php $form = array(); $details = mysql_query("SELECT * FROM users WHERE validateUser = 0 ORDER BY surname") or mysql_error(); while ($getUserDetails = mysql_fetch_array($details)) { $userGroupe = mysql_query("SELECT * FROM usergroups " . NEW_WHERE . "") or die(mysql_error()); $area = mysql_query("SELECT * FROM area WHERE valid = 0 and areaID = '$getUserDetails[area]'") or mysql_error(); while ($getArea = mysql_fetch_array($area)) { $theArea = $getArea['areaName']; } echo "<form action=" . $_SERVER['PHP_SELF'] . " method=\"post\">"; echo "<tr class=bTable>"; echo "<td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?g=" . $_POST['userGroups'] . "&selectedNewUser=" . $getUserDetails['userID'] . "&o=1>Yes</a></span></td><td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?selectedNewUser=" . $getUserDetails['userID'] . "&o=2>No</a></span></td><td><span class=\"small\"> $getUserDetails[userName]</span></td><td><span class=\"small\">$getUserDetails[forename] $getUserDetails[surname]</span></td><td><span class=\"small\">$theArea</span></td><td><span class=\"small\">$getUserDetails[resion]</span></td>"; echo "<td><select name='userGroups' onchange=\"this.form.submit()\"><option value=''>" . F_SELECT_ONE . "</option>"; while($noticia = mysql_fetch_array($userGroupe)) { if ($_POST['userGroups'] == $noticia['groupID']) { echo "<option selected=\"selected\" value='$noticia[groupID]'>$noticia[groupName]</option>"; } else { echo "<option value='$noticia[groupID]'>$noticia[groupName]</option>"; } } echo "</select>"; echo "</td>"; echo "</tr>"; echo "</form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430187 Share on other sites More sharing options...
nezbo Posted January 4, 2008 Author Share Posted January 4, 2008 Cheers, this dose help, i think this is more or less what i have, but the problem is that it then updates all the forms with the same dropdown. if i select the 'mediator', 'user' or the 'administrator' it also sets the rest of the dropdowns to the same one? any ideas ? Cheers for you help so far. here you go hope its helpfull.. change quite a lot of things <?php $form = array(); $details = mysql_query("SELECT * FROM users WHERE validateUser = 0 ORDER BY surname") or mysql_error(); while ($getUserDetails = mysql_fetch_array($details)) { $userGroupe = mysql_query("SELECT * FROM usergroups " . NEW_WHERE . "") or die(mysql_error()); $area = mysql_query("SELECT * FROM area WHERE valid = 0 and areaID = '$getUserDetails[area]'") or mysql_error(); while ($getArea = mysql_fetch_array($area)) { $theArea = $getArea['areaName']; } echo "<form action=" . $_SERVER['PHP_SELF'] . " method=\"post\">"; echo "<tr class=bTable>"; echo "<td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?g=" . $_POST['userGroups'] . "&selectedNewUser=" . $getUserDetails['userID'] . "&o=1>Yes</a></span></td><td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?selectedNewUser=" . $getUserDetails['userID'] . "&o=2>No</a></span></td><td><span class=\"small\"> $getUserDetails[userName]</span></td><td><span class=\"small\">$getUserDetails[forename] $getUserDetails[surname]</span></td><td><span class=\"small\">$theArea</span></td><td><span class=\"small\">$getUserDetails[resion]</span></td>"; echo "<td><select name='userGroups' onchange=\"this.form.submit()\"><option value=''>" . F_SELECT_ONE . "</option>"; while($noticia = mysql_fetch_array($userGroupe)) { if ($_POST['userGroups'] == $noticia['groupID']) { echo "<option selected=\"selected\" value='$noticia[groupID]'>$noticia[groupName]</option>"; } else { echo "<option value='$noticia[groupID]'>$noticia[groupName]</option>"; } } echo "</select>"; echo "</td>"; echo "</tr>"; echo "</form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430196 Share on other sites More sharing options...
rajivgonsalves Posted January 4, 2008 Share Posted January 4, 2008 well the selection of the group should be pulled from the table your saving your data too... Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430204 Share on other sites More sharing options...
nezbo Posted January 4, 2008 Author Share Posted January 4, 2008 should i be using a difrent from for each row e.g. renaming the from with a postfix of the userID ? like this or something? this.form.submit($userID) Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430209 Share on other sites More sharing options...
rajivgonsalves Posted January 4, 2008 Share Posted January 4, 2008 no I meant your selection should come from the table your storing the details of which group the user belongs too... which table is that ? Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430218 Share on other sites More sharing options...
nezbo Posted January 4, 2008 Author Share Posted January 4, 2008 sorry. The info is stored in the user table, but i am geting the info for the drop down from the groups table. no I meant your selection should come from the table your storing the details of which group the user belongs too... which table is that ? Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430252 Share on other sites More sharing options...
rajivgonsalves Posted January 4, 2008 Share Posted January 4, 2008 assuming the groupID in the user table is group ID this if ($_POST['userGroups'] == $noticia['groupID']) should be if ($getUserDetails['groupID'] == $noticia['groupID']) Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430258 Share on other sites More sharing options...
nezbo Posted January 4, 2008 Author Share Posted January 4, 2008 i see what you are saying, but i have not yet entered the group in to the user table. and i dont want to untill i have clicked the yes button on from that record. Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430262 Share on other sites More sharing options...
rajivgonsalves Posted January 4, 2008 Share Posted January 4, 2008 well in which table do you plan to store it ? Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430263 Share on other sites More sharing options...
nezbo Posted January 4, 2008 Author Share Posted January 4, 2008 Cheers for all you help. i think i might have found a way round it, i have added : $userID = $getUserDetails['userID']; $tec = "userGroups" . $userID . ""; here is the full code. <?php $details = mysql_query("SELECT * FROM users WHERE validateUser = 0 ORDER BY surname") or mysql_error(); while ($getUserDetails = mysql_fetch_array($details)) { $userID = $getUserDetails['userID']; $tec = "userGroups" . $userID . ""; $userGroupe = mysql_query("SELECT * FROM usergroups " . NEW_WHERE . "") or die(mysql_error()); $area = mysql_query("SELECT * FROM area WHERE valid = 0 and areaID = '$getUserDetails[area]'") or mysql_error(); while ($getArea = mysql_fetch_array($area)) { $theArea = $getArea['areaName']; } echo "<form action=" . $_SERVER['PHP_SELF'] . " method=\"post\">"; echo "<tr class=bTable>"; echo "<td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?g=" . $_POST[$tec] . "&selectedNewUser=" . $getUserDetails['userID'] . "&o=1>Yes</a></span></td><td><span class=small><a href=" . $_SERVER['PHP_SELF'] ."?selectedNewUser=" . $getUserDetails['userID'] . "&o=2>No</a></span></td><td><span class=\"small\"> $getUserDetails[userName]</span></td><td><span class=\"small\">$getUserDetails[forename] $getUserDetails[surname]</span></td><td><span class=\"small\">$theArea</span></td><td><span class=\"small\">$getUserDetails[resion]</span></td>"; echo "<td><select name='userGroups" . $userID . "' onchange=\"this.form.submit()\"><option value=''>" . F_SELECT_ONE . "</option>"; while($noticia = mysql_fetch_array($userGroupe)) { if ($_POST[$tec] == $noticia['groupID']) { echo "<option selected=\"selected\" value='$noticia[groupID]'>$noticia[groupName]</option>"; } else { echo "<option value='$noticia[groupID]'>$noticia[groupName]</option>"; } } echo "</select>"; echo "</td>"; echo "</tr>"; echo "</form>"; } ?> hope it makes sence to what i was trying to do. cheers rajivgonsalves for all your help. Neil well in which table do you plan to store it ? Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430276 Share on other sites More sharing options...
rajivgonsalves Posted January 4, 2008 Share Posted January 4, 2008 Yes if your doing that please move your form tags outside the first loop... Quote Link to comment https://forums.phpfreaks.com/topic/84445-solved-from-help-in-php/#findComment-430277 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.