So, if there were 25 pairs of word/definitions, I would just
create a $q
that listed each explicitly?
Wouldn't it make more sense to have the insert in the loop?
--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"Joe Makowiec" <makowiec@invalid.invalid> wrote in
message
news:Xns98E5D9D4A93E3makowiecatnycapdotrE@216.104.212.96...
> On 28 Feb 2007 in macromedia.dreamweaver.appdev, Murray
*ACE* wrote:
>
>> OK - I've beat my head to a pulp.
>>
>> I have an array of paired strings. I want to add the
whole array to
>> a data table, in alternating fields.
>>
>> I have this -
>>
>> mysql_select_db($database_cmaConn, $cmaConn);
>>
>> $fields = "'keyJargon','keyDef'";
>> $values = "'".implode(array_values($toAdd),
"','")."'";
>>
>> function mysql_insert($table,$ToAdd) {
>> $q = 'INSERT INTO `'.$table.'` ('.$fields.') VALUES
>> ('.$values.')'; $res = mysql_query($q)OR
die(mysql_error());
>>
>> return true;
>>
>> } //end function
>>
>> if (isset($_POST['Submit'])) {
>>
>> $jargonArray=explode("\n",$_POST['upload']);
>> // this splits the input data into consecutive
elements of the
>> array, one for each new line.
>>
>> $i=0;
>> foreach($jargonArray as $key => $value) {
>> if (strlen($value) > 0) {
>> $jargon[] = explode("\x09",$value);
>> //this splits the tab-delimited input data into
adjacent array
>> elements.
>>
>> mysql_insert('cma_keywords',$jargon[$i][0][1]);
>> $i++;
>> } // endif
>>
>> }
>>
>> But it's broke. What am I doing wrong?
>
> Don't have a boatload of time at the moment, and I know
what grief we
> went through yesterday getting stuff /into/ that jargon
array, but...
> You don't need it.
>
> Try this:
>
> mysql_select_db($database_cmaConn, $cmaConn);
>
> foreach($jargonArray as $key => $value) {
> if (strlen($value) > 0) {
> $jargon = explode("\x09",$value);
> //this splits the tab-delimited input data into adjacent
array elements.
> $q = 'INSERT INTO `cma_keywords` (keyJargon,keyDef)
VALUES (';
> $q .= $jargon[0];
> $q .= ',';
> $q .= $jargon[1];
> $q .= ');';
> $res = mysql_query($q) OR die(mysql_error());
> // Do something with $res here - check if insert went OK
> } // endif
> }// end foreach
>
> Untested. Yeah, I know - it's case specific. I'm tired.
>
> --
> Joe Makowiec
>
http://makowiec.net/
> Email:
http://makowiec.net/email.php