Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting an array key as a field value - mysql/php
    primarykey
    data
    text
    <p>I have multiple named keys and each gets assigned a value between 0 and 5.</p> <p>I have created an array and array filter to keep only the key that has been assigned a value > 0. Dropping any 0 value pairs from the array.</p> <p>What I need is a way to insert the key name and the value assigned as separate fields in the same table.</p> <p>The column names are skill_name and value.</p> <p>The array after submit:</p> <p><code>Array ( [Academics] =&gt; 2 [Animal_Ken] =&gt; 3 [Athletics] =&gt; 2 [Awareness] =&gt; 0 [Blood_Sense] =&gt; 0 [Brawl] =&gt; 0 [Craft] =&gt; 0 [Dodge] =&gt; 0 [Empathy] =&gt; 0 [Enigma] =&gt; 0 [Etiquette] =&gt; 0 [Expression] =&gt; 0 [Finance] =&gt; 0 [Firearms] =&gt; 0 [Intimidation] =&gt; 0 [Investigation] =&gt; 0 [Larceny] =&gt; 0 [Law] =&gt; 0 [Leadership] =&gt; 0 [Linguistics] =&gt; 0 [Malkavian_Time] =&gt; 0 [Medicine] =&gt; 0 [Melee] =&gt; 0 [Occult] =&gt; 0 [Performance] =&gt; 0 [Politics] =&gt; 0 [Science] =&gt; 0 [Scrounge] =&gt; 0 [Security] =&gt; 0 [Stealth] =&gt; 0 [Streetwise] =&gt; 0 [Subterfuge] =&gt; 0 [Survival] =&gt; 0 [submit_skills] =&gt; Add Skills )</code></p> <p>The array after filter:</p> <p><code>Array ( [Academics] =&gt; 2 [Animal_Ken] =&gt; 3 [Athletics] =&gt; 2 )</code></p> <p>Now I need to insert into skill_name = key, value = value for each array index.</p> <p>Any ideas?</p> <p><strong>EDIT</strong></p> <p>After taking the advice I was given everything seems to be working correctly-ish.</p> <p>Now I'm having the problem that any key that had a space in the name is now given an underscore by default.</p> <p>e.g : Animal Ken --> Animal_Ken .. the database is rejecting the insert because of that.</p> <p>Any way to strip out the underscore and leave it as a space again?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload