Hello,
I realise there are a lot of topics related to this problem but many of what I have found has run cold or unresolved. What I have is an addressbook clone where there are groups which have members. I have this formatted in a way where the groups are in a drop down box. Once a group is selected, the two selection boxes below are refreshed with those who are members or non members of the selected group. The user has the ability to transfer those contacts from the members box to the non members box, and vice versa. PHP, html and MySQL are being used.
I also have three tables:
contacts: containing account details including contactID as its PK
groups: containing the group description including groupID as its PK
groupmembers: containing the previous two PKs as FKs
After searching for resources, I've managed to get a javascript function that allows the transfer of contacts from one selection box to the other
[HTML]function move(nonMemBox, memBox)
{
var arrNonMemBox = new Array();
var arrMemBox = new Array();
var arrLookup = new Array();
var i;
// This for loop gets the length from the destination field
for (i = 0; i < memBox.options. length; i++)
{
arrLookup[memBox.options[i].text] = memBox.options[i].value;
arrMemBox[i] = memBox.options[i].text;
}
var nonMemLength = 0;
var memLength = arrMemBox.lengt h;
// This for loop gets the length of the source field
for(i = 0; i < nonMemBox.optio ns.length; i++)
{
arrLookup[nonMemBox.optio ns[i].text] = nonMemBox.optio ns[i].value;
// If if the item is selected and not empty
if (nonMemBox.opti ons[i].selected && nonMemBox.optio ns[i].value != "")
{
arrMemBox[memLength] = nonMemBox.optio ns[i].text;
memLength++;
}
else
{
arrNonMemBox[nonMemLength] = nonMemBox.optio ns[i].text;
nonMemLength++;
}
}
// This alphabetically sorts the array of the items
//arrFbox.sort();
//arrTbox.sort();
nonMemBox.lengt h = 0;
memBox.length = 0;
var c;
// now transfer the items stored in the arrFbox[] array
for(c = 0; c < arrNonMemBox.le ngth; c++)
{
var no = new Option();
no.value = arrLookup[arrNonMemBox[c]];
no.text = arrNonMemBox[c];
nonMemBox[c] = no;
}
// now send all the items to the destination field
for(c = 0; c < arrMemBox.lengt h; c++)
{
var no = new Option();
no.value = arrLookup[arrMemBox[c]];
no.text = arrMemBox[c];
memBox[c] = no;
}
}
function addMe()
{
theValues = document.combo_ box.member;
for(i = 0; i < theValues.lengt h; i++)
{
alert(theValues[i].value);
if(document.com bo_box.theNumbe rs.value == "" )
{
document.combo_ box.theNumbers. value = theValues[i].value;
}
else
{
document.combo_ box.theNumbers. value += "," + theValues[i].value;
}
}
return true;
}[/HTML]
The function responsible for refreshing the page with the drop down box are as follows:
[HTML]function reload(form)
{
var val=form.Group. options[memberAssignmen tForm.Group.opt ions.selectedIn dex].value;
self.location=' groupContacts.p hp?Group=' + val ;
}[/HTML]
The above function uses $Group = $_GET['Group'] to get the selected groupID. That is then used for the following code
[HTML]<form name="memberAss ignmentForm" method="post" action="groupCo ntacts.php" onsubmit="retur n addMe();">
<input id="theNumbers " name="theNumber s" type="hidden" />
<table>
<tr>
<td><b>Group: </b><select name="Group" onchange="retur n reload(this.for m);">
<option value="select"> Select one</option>
<?
// Retrieves and displays groups from db
$query="select * from groups order by Name";
$result=$db->query($query );
$num_results=$r esult->num_rows;
for($i=0; $i<$num_results ; $i++)
{
$row=$result->fetch_assoc( );
echo '<option value=';
echo $row['groupID'];
echo '>';
echo $row['Name'];
echo '</option>';
}
$result->free();
?>
</select></td>
</tr><tr></tr>
<tr>
<td align="center"> <b>Non-members</b></td>
<td><p> </p></td>
<td align="center"> <b>Members</b></td>
</tr>
<tr>
<td><select name="nonMember " size="10" multiple style="width: 150px;" ondblclick="mov e(this.form.non Member,this.for m.member)">
<?
// Retrieves contact names that belong to selected group and displays in the right selection box
$query = "select * from contacts where contactID not in (select contactID from groupcontact where groupID = '".$Group."' )";
$result=$db->query($query );
$num_results=$r esult->num_rows;
for($i=0; $i<$num_results ; $i++)
{
$row=$result->fetch_assoc( );
echo '<option value=';
echo $row['contactID'];
echo '>';
echo $row['Surname'],', ', $row['Firstname'];
echo '</option>';
}
$result->free();
?>
</select></td>
<td><input type="button" name="Disable" value="> " style="width: 20px;" onClick="move(t his.form.nonMem ber,this.form.m ember)"><br>
<br>
<input type="button" name="Enable" value="<" style="width: 20px;" onClick="move(t his.form.member ,this.form.nonM ember)"><br></td>
<br>
<td><select name="member" size="10" multiple style="width: 150px;" ondblclick="mov e(this.form.mem ber,this.form.n onMember)">
<?php
// Retrieves contact names that are don't belong to selected group and displays in the left selection box
$query = "select * from contacts where contactID in (select contactID from groupcontact where groupID = '".$Group."' )";
$result=$db->query($query );
$num_results=$r esult->num_rows;
for($i=0; $i<$num_results ; $i++)
{
$row=$result->fetch_assoc( );
echo '<option value=';
echo $row['contactID'];
echo '>';
echo $row['Surname'], ', ', $row['Firstname'];
echo '</option>';
}
$result->free();
?>
</select></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Save"></td>
</tr>
</table>
</form>
</body>
</html>[/HTML]
Now what I am trying to resolve is to submit the form where the contacts in their respective boxes and insert them into the database - specifically the groupmembers table, which would end up looking like...
groupID contactID
12 44
12 45
12 46
13 22
Another problem I'm having difficulty understanding is that when I select a group from the drop down box, it obviously refreshes. However, once it does the correct contacts are displayed but the drop down box reverts back to its original state eg. Select one
What am I missing that ensures the selected group is displayed once refreshed?
I have tried working with arrays on the selection box inputs but it breaks the move function. An answer to these two questions would be greatly appreciated. Apologies for the length of this question but I figured giving this much information would provide a better answer. Of course I'll be happy to clarify anything that is vague.
Thank you
4 2558 dlite922 1,584
Recognized Expert Top Contributor
to quickly select the value that was selected before the page refresh, simple follow this logic:
[PHP]
for ($i = 0; $i < count($someArra y); $i++)
{
if($someArray[$i] == $someID)
echo "<option value=$someArra y[$i] selected='selec ted'>$someArray[$i]";
else
echo "<option value=$someArra y[$i]>$someArray[$i]";
}
[/PHP]
I'll see if i have time to cover your other issues, anybody else feel free to jump in.
[PHP]
for ($i = 0; $i < count($someArra y); $i++)
{
if($someArray[$i] == $someID)
echo "<option value=$someArra y[$i] selected='selec ted'>$someArray[$i]";
else
echo "<option value=$someArra y[$i]>$someArray[$i]";
}
[/PHP]
Thank you for the response. Regarding your suggestion. I am not using arrays to access the drop down box whatsoever so I'm confused as to how I would apply that logic. It's just querying the database to retrieve the results.
[PHP]$query="select * from groups order by Name";
$result=$db->query($query );
$num_results=$r esult->num_rows;
for($i=0; $i<$num_results ; $i++)
{
$row=$result->fetch_assoc( );
echo '<option value=';
echo $row['groupID'];
echo '>';
echo $row['Name'];
echo '</option>';
}[/PHP]
I have solved my refresh problem. It was so simple, it's criminal. I just needed to echo the inputs as selected in a loop. Thanks dlite922 for kickstarting the idea.
[PHP]
$query="select * from groups order by Name";
$result=$db->query($query );
$num_results=$r esult->num_rows;
for($i=0; $i<$num_results ; $i++)
{
$row=$result->fetch_assoc( );
if($row['groupID'] == $Group)
{
echo '<option selected value=';
echo $row['groupID'];
echo '>';
echo $row['Name'];
echo '</option>';
}
else
{
echo '<option value=';
echo $row['groupID'];
echo '>';
echo $row['Name'];
echo '</option>';
}
}[/PHP]
One problem solved. Another one to go.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: pmud |
last post by:
I have an ASP.NET web application using C# code. I am trying to insert values
from a web form into an SQL database. I am using SQL COMMAND object for this.
I need to know HOW TO INSERT THE RADIO BUTTON LIST SELECTION entered by the
user in the web form into tha database. for eg. for inserting values from a
text box into the database we write code ::
sqlCommand1.Parameters.Value =TextBox1.Text
& for inserting integer values we write::...
|
by: lawrence |
last post by:
Is this the correct way to test for a method before I use it?
createRange() is, I believe, an IE only method.
function wrapSelectionInTag(selection, tag) {
if (document.selection.createRange) {
var range = document.selection.createRange();
if (range.parentElement() == element) range.text = '<' + tag +
'>' + range.text + '<\/' + tag + '>';
}
|
by: ajk |
last post by:
.
Hi, All:
I know how to insert files into a Word doc using C#. However, the program
I've written to do this runs much too slowly. The
"myObj".Application.Selection.InsertFile method executes at a snails pace.
Here are the detais:
I wrote a C# program that creates a new Word doc and then loops through a
|
by: Clark Stevens |
last post by:
Hi. This should be so easy, but I don't get it. Let say I have
RichTextbox1 and I want to insert some text at the current insertion point,
or at the beginning of selected text (if there is any). How is this done?
Also, how do I delete the current selection? Thanks.
|
by: Andy C Matthews |
last post by:
Hi there,
I'm building an Access database and using VBA to generate Microsoft Word
mailings for customers. It's all going fine so far. However, a variables
named ParcelID, a ten-digit string such as TQ03409954, needs to be split into
SHEET ID (the first six characters) and PARCEL ID (the last 4) e.g. TQ0340
9954. Can anyone help me? I'm messing around using For loops and the Split()
function, but to no avail.
Many thanks,
Andy
Reading,...
| |
by: subashini Thiyagarajan |
last post by:
Hi ,
In ASP how to deactivate few fields while inserting a record to the database(access).
i want to insert a record.e.g having 5 fields.it is not reqired to fill all the fields in a form as per my condition.upon first filed selection(drop down) remaining field should show or deactivate how to dooooooooooooooooooo?
As per the dropdown selection we shoud control the text boxes in the form.same time which ever text box in visible those...
|
by: gruvin |
last post by:
Hi.
I need to insert an image element into text in an iframe in design mode. That part I can do:
var sel = oEditor.eFrameDoc.selection;
var range = sel.createRange();
range.pasteHTML('<img src="'+imagePath+'" border="0" />');
But I need a reference to that new IMG tag to do other stuff with it.
|
by: santuvssantu |
last post by:
Hi Friends,
I have tried inserting an excel file to a word document.But the following code is inserting the junk information. So can you please help me out?
Dim m_WordApp As New Word.Application
Dim m_WordDoc As Word.Document
m_WordDoc = m_WordApp.Documents.Open(CObj("C:\Documents and Settings\santu\My Documents\New Microsoft Word Document.doc"), CObj(False), CObj(False), CObj(False))
|
by: javediq143 |
last post by:
Hi All,
This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description:
1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |