close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Multiple Select List

Thread began 9/25/2010 7:23 am by Cologne | Last modified 9/27/2010 11:55 am by Dave Buchholz | 2087 views | 18 replies |

Cologne

Multiple Select List

Hello,

I created a SelectList but how do I store the values with DA in my table?

When I do it like that only the first selection is stored in the table :-(

<?php require_once('database/IchBinMusiker.php'); ?>
<?php require_once("WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_IchBinMusiker, $IchBinMusiker);
$query_genre = "SELECT * FROM genre ORDER BY genre ASC";
$genre = mysql_query($query_genre, $IchBinMusiker) or die(mysql_error());
$row_genre = mysql_fetch_assoc($genre);
$totalRows_genre = mysql_num_rows($genre);

mysql_select_db($database_IchBinMusiker, $IchBinMusiker);
$query_profil = "SELECT profileid, genre FROM profile WHERE profileid = 5";
$profil = mysql_query($query_profil, $IchBinMusiker) or die(mysql_error());
$row_profil = mysql_fetch_assoc($profil);
$totalRows_profil = mysql_num_rows($profil);?>
<?php
// WA Application Builder Update
if (isset($_POST["button"])) // Trigger
{
$WA_connection = $IchBinMusiker;
$WA_table = "profile";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "profileid";
$WA_fieldNamesStr = "genre";
$WA_fieldValuesStr = "".((isset($_POST["liste"]))?$_POST["liste"]:"") ."";
$WA_columnTypesStr = "',none,''";
$WA_comparisonStr = "=";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);

$WA_where_fieldValuesStr = "5";
$WA_where_columnTypesStr = "none,none,NULL";
$WA_where_comparisonStr = "=";
$WA_where_fieldNames = explode("|", $WA_indexField);
$WA_where_fieldValues = explode("|", $WA_where_fieldValuesStr);
$WA_where_columns = explode("|", $WA_where_columnTypesStr);
$WA_where_comparisons = explode("|", $WA_where_comparisonStr);

$WA_connectionDB = $database_IchBinMusiker;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues, $WA_where_comparisons );
$WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unbenanntes Dokument</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<p>Liste
<select name="liste" size="<?php echo $totalRows_genre; ?>" multiple="multiple" id="liste">
<?php
do {
?>
<option value="<?php echo $row_genre['genreid']?>"<?php if (!(strcmp($row_genre['genreid'], $row_profil['genre']))) {echo "selected=\"selected\"";} ?>><?php echo $row_genre['genre']?></option>
<?php
} while ($row_genre = mysql_fetch_assoc($genre));
$rows = mysql_num_rows($genre);
if($rows > 0) {
mysql_data_seek($genre, 0);
$row_genre = mysql_fetch_assoc($genre);
}
?>
</select>
</p>
<p>
<input type="submit" name="button" id="button" value="Senden" />
</p>
</form>
</body>
</html>
<?php
mysql_free_result($genre);

mysql_free_result($profil);
?>
Sign in to reply to this post

Dave BuchholzBeta Tester

You need to use the DataAssist -> Update -> Multiple Record Updates Server Behaviour at the moment you are using the Single Record Update according to the code you posted.

Sign in to reply to this post

Cologne

Hi Dave,

I dont know how to do taht. I set the name of the select box to an array like, instruments[]

and I store the value with serialize() in my table.

but I cant get it back into the select box. I tried it with unserialize() but it does not work :-(

Denis

Sign in to reply to this post

Dave BuchholzBeta Tester

you can find the server behaviour I am referring to here:



There is also a Insert and Delete equivalent.

Sign in to reply to this post

Cologne

hi dave,

thats not what i need, i dont have a repeat selection and i dont need one. its like that:

<select name="instrumente[]" size="4" multiple="multiple" >
<?php
do {
?><option value="<?php echo $row_instr['instrumentid']?>"<?php if (!(strcmp($row_instr['instrumentid'], implode(',', unserialize($row_profil['instrument']))))) {echo "selected=\"selected\"";} ?>><?php echo $row_instr['instrument']?></option>
<?php
} while ($row_instr = mysql_fetch_assoc($instr));
$rows = mysql_num_rows($instr);
if($rows > 0) {
mysql_data_seek($instr, 0);
$row_instr = mysql_fetch_assoc($instr);
}
?>
</select>



its just a list where you can choose more than 1 thing.

i already know how to store, but dont know how to give it back to the list :-(

Denis

Sign in to reply to this post

Dave BuchholzBeta Tester

I use this server behaviour to do multiple selections exactly as you are looking for all the time in my admin sections e.g.



and within the Update Server Behaviour there is the facility to populate the form with the existing entries.

Sign in to reply to this post

Cologne

where do you put the repeat selection? do I need one?

and the problem is, I got 2 diffrent lists in 1 form.

Sign in to reply to this post

Dave BuchholzBeta Tester

the update server behaviour handles all that for you, you can have both a multiple update and a normal data assist update on the same page if you need, just make sure the 2nd one in terms of code order does the redirect

Sign in to reply to this post

Cologne

hi dave,

now i am a little bit confused.

so, i can have 2 multiselect lists in my page. just add a multi update for each list?

and, i need to put a repeat region around every list?

Sign in to reply to this post

Dave BuchholzBeta Tester

here is an excerpt from a form in the admin section of one of my sites that has two multi select lists in it:

php:
<div>

    <label class="required" for="categories">Associated Categories<em title="Required">*</em></label>
    <select name="categories[]" size="10" multiple id="categories">
        <?php
do {  
?>
        <option value="<?php echo $row_rsCategories['id']?>"<?php if (!(strcmp($row_rsCategories['id'], WA_AB_returnPreSelectValue($WA_PreSelect_RelationalTable_1$row_rsCategories['id'])))) {echo " selected=\"selected\"";} ?>><?php echo $row_rsCategories['title']?></option>
        <?php
} while ($row_rsCategories mysql_fetch_assoc($rsCategories));
$rows mysql_num_rows($rsCategories);
if(
$rows 0) {
mysql_data_seek($rsCategories0);
$row_rsCategories mysql_fetch_assoc($rsCategories);
}
?>
    </select>
</div>
<div>
    <label class="required"  for="prodtypes">Associated Product Types<em title="Required">*</em></label>
    <select name="prodtypes[]" size="10" multiple id="prodtypes">
        <?php
do {  
?>
        <option value="<?php echo $row_rsProdTypes['id']?>"<?php if (!(strcmp($row_rsProdTypes['id'], WA_AB_returnPreSelectValue($WA_PreSelect_RelationalTable_2$row_rsProdTypes['id'])))) {echo " selected=\"selected\"";} ?>><?php echo $row_rsProdTypes['title']?></option>
        <?php
} while ($row_rsProdTypes mysql_fetch_assoc($rsProdTypes));
$rows mysql_num_rows($rsCategories);
if(
$rows 0) {
mysql_data_seek($rsProdTypes0);
$row_rsProdTypes mysql_fetch_assoc($rsProdTypes);
}
?>
    </select>
</div>



does that make things clearer ?

Sign in to reply to this post
loading

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...