Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating multidimensional array containing database output
    primarykey
    data
    text
    <p>Im creating a website, where I make a foreach, that echos out some groups, containing checkboxes, with values and names. At the moment that data comes from a multidimensional array, but writing that array when adding new items, is slow, and not very user-friendly.</p> <p>At the moment, my foreach looks like this:</p> <pre><code>echo '&lt;form method="post" action="'.$_SERVER['PHP_SELF'].'"&gt;'; /* NEXT WE CREATE OUR FOREACH LOOPS TO ECHO THE HTML FOR LOOKS AND CHECKBOXES */ $totalID=0; // this is a counter we use to build our check box names foreach ($items as $list){ $totalID++; // add one to the checkbox name counter echo "&lt;h2&gt;{$list['title']}&lt;/h2&gt;\n"; // and echo out our section header foreach ($list['items'] as $cbox){ // now for each item in the list, call it $cbox // $cbox now holds the item name, and point value echo "&lt;label class='checkbox'&gt;&lt;input type='checkbox' name='totals[$totalID][]' value='{$cbox[1]}'&gt; {$cbox[0]}&lt;/label&gt;\n"; } } echo "&lt;/form&gt;"; </code></pre> <p>And my array I write is something like this:</p> <pre><code>$items['computers']['title']='Computer Brand'; $items['computers']['items'][]=array('Apple iMac',1); $items['computers']['items'][]=array('Apple Macbook',.5); $items['phones']['title']='Phone Brand'; $items['phones']['items'][]=array('iPhone',1); $items['phones']['items'][]=array('HTC',1); </code></pre> <p>As said, I can write this, but takes time. I want to get it into a database, that data above, but I'm having problems about echo'ing it out, I really can't see how I should do.</p> <p>My current database looks like this: <a href="http://i.stack.imgur.com/Rj0wQ.png" rel="nofollow">http://i.stack.imgur.com/Rj0wQ.png</a></p> <p>Anyone that have some tips how to do this easy, and also do it user friendly?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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