close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

concat firstname and lastname in child table

Thread began 9/26/2009 5:18 pm by jenkolaka19379118 | Last modified 1/27/2010 1:26 pm by jenkolaka19379118 | 9628 views | 14 replies

barbara224891

similar problem with concatenating names for Dynamic Dropdown menues

I was studying this string because I have a similar problem. I tried Eric's suggestion of redefining the recordset with the more complex query (with the concatenation) after the array definition server behavior. I found that this does permit the passing of the concatenated names, however, the array is no longer selected by the other variable. In other words, it lists all possible names, not those names that correspond to the selection of the parent field.

Here's the relevant php before the html page:
mysql_select_db($database_db, $db);
$query_contacts = sprintf("SELECT * FROM contacts ORDER BY contactID ASC");
$contacts = mysql_query($query_contacts, $db) or die(mysql_error());
$row_contacts = mysql_fetch_assoc($contacts);
$totalRows_contacts = mysql_num_rows($contacts);
?>
<?php
if ($row_contacts) {
echo "<SC" . "RIPT>\n";
echo "var WAJA = new Array();\n";

$oldmainid = 0;
$newmainid = $row_contacts["orgID"];
if ($oldmainid == $newmainid) {
$oldmainid = "";
}
$n = 0;
while ($row_contacts) {
if ($oldmainid != $newmainid) {
echo "WAJA[".$n."] = new Array();\n";
echo "WAJA[".$n."][0] = '".WA_DD_Replace($newmainid)."';\n";
$m = 1;
}

echo "WAJA[".$n."][".$m."] = new Array();\n";
echo "WAJA[".$n."][".$m."][0] = "."'".WA_DD_Replace($row_contacts["contactID"])."'".";\n";
echo "WAJA[".$n."][".$m."][1] = "."'".WA_DD_Replace($row_contacts["fullname"])."'".";\n";

$m++;
if ($oldmainid == 0) {
$oldmainid = $newmainid;
}
$oldmainid = $newmainid;
$row_contacts = mysql_fetch_assoc($contacts);
if ($row_contacts) {
$newmainid = $row_contacts["orgID"];
}
if ($oldmainid != $newmainid) {
$n++;
}
}

echo "var contacts_WAJA = WAJA;\n";
echo "WAJA = null;\n";
echo "</SC" . "RIPT>\n";
}
function WA_DD_Replace($startStr) {
$startStr = str_replace("'", "|WA|", $startStr);
$startStr = str_replace("\\", "\\\\", $startStr);
$startStr = preg_replace("/[\r\n]{1,}/", " ", $startStr);
return $startStr;
}
mysql_select_db($database_db, $db);
$query_contacts = "SELECT contactID, CONCAT(firstname, ' ',middlename,' ' ,lastname) AS fullname, orgID FROM contacts";
$contacts = mysql_query($query_contacts, $db) or die(mysql_error());
$row_contacts = mysql_fetch_assoc($contacts);
$totalRows_contacts = mysql_num_rows($contacts);
?>

here's the javascript code in the head of the html document:

function WA_ClientSideReplace(theval,findvar,repvar) {
var retval = "";
while (theval.indexOf(findvar) >= 0) {
retval += theval.substring(0,theval.indexOf(findvar));
retval += repvar;
theval = theval.substring(theval.indexOf(findvar) + String(findvar).length);
}
retval += theval;
if (retval == "" && theval.indexOf(findvar) < 0) {
retval = theval;
}
return retval;
}

function WA_UnloadList(thelist,leavevals,bottomnum) {
while (thelist.options.length > leavevals+bottomnum) {
if (thelist.options[leavevals]) {
thelist.options[leavevals] = null;
}
}
return leavevals;
}
function WA_FilterAndPopulateSubList(thearray,sourceselect,targetselect,leaveval,bottomleave,usesource,delimiter) {
if (bottomleave > 0) {
leaveArray = new Array(bottomleave);
if (targetselect.options.length >= bottomleave) {
for (var m=0; m<bottomleave; m++) {
leavetext = targetselect.options[(targetselect.options.length - bottomleave + m)].text;
leavevalue = targetselect.options[(targetselect.options.length - bottomleave + m)].value;
leaveArray[m] = new Array(leavevalue,leavetext);
}
}
else {
for (var m=0; m<bottomleave; m++) {
leavetext = "";
leavevalue = "";
leaveArray[m] = new Array(leavevalue,leavetext);
}
}
}
startid = WA_UnloadList(targetselect,leaveval,0);
mainids = new Array();
if (usesource) maintext = new Array();
for (var j=0; j<sourceselect.options.length; j++) {
if (sourceselect.options[j].selected) {
mainids[mainids.length] = sourceselect.options[j].value;
if (usesource) maintext[maintext.length] = sourceselect.options[j].text + delimiter;
}
}
for (var i=0; i<thearray.length; i++) {
goodid = false;
for (var h=0; h<mainids.length; h++) {
if (thearray[i][0] == mainids[h]) {
goodid = true;
break;
}
}
if (goodid) {
theBox = targetselect;
theLength = parseInt(theBox.options.length);
theServices = thearray[i].length + startid;
var l=1;
for (var k=startid; k<theServices; k++) {
if (l == thearray[i].length) break;
theBox.options[k] = new Option();
theBox.options[k].value = thearray[i][l][0];
if (usesource) theBox.options[k].text = maintext[h] + WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");
else theBox.options[k].text = WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");
l++;
}
startid = k;
}
}
if (bottomleave > 0) {
for (var n=0; n<leaveArray.length; n++) {
targetselect.options[startid+n] = new Option();
targetselect.options[startid+n].value = leaveArray[n][0];
targetselect.options[startid+n].text = leaveArray[n][1];
}
}
for (var l=0; l < targetselect.options.length; l++) {
targetselect.options[l].selected = false;
}
if (targetselect.options.length > 0) {
targetselect.options[0].selected = true;
}
}

and finally, here's the child list in the body of the document

<select name="contact" onchange="WA_FilterAndPopulateSubList(contacts_WAJA,MM_findObj('orgID'),MM_findObj('contact'),1,0,false,': ')">
<option value="" <?php if (!(strcmp("", $row_project['contact']))) {echo "selected=\"selected\"";} ?>>-- select --</option>
<?php
do {
?>
<option value="<?php echo $row_contacts['contactID']?>"<?php if (!(strcmp($row_contacts['contactID'], $row_project['contact']))) {echo "selected=\"selected\"";} ?>><?php echo $row_contacts['fullname'] ;?></option>
<?php
} while ($row_contacts = mysql_fetch_assoc($contacts));

?>
</select>


In case it's helpful, I'm also attaching the whole page. Oops, it won't let me attach a php file, scratch that.

Thanks for any help you can give me.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...