Note that there are some explanatory texts on larger screens.

plurals
  1. POFind if variable is set in an array?
    text
    copied!<p>Can anyone point me to right direction? Im really confused (im a beginner :D). Example:</p> <pre><code>&lt;form action="&lt;?php $_server['php_self'] ?&gt;" method=post&gt; &lt;table width="50%" style="border: 1px solid #999;" cellspacing="0" cellpadding="0"&gt; &lt;tr&gt; &lt;td width="35%"&gt; &lt;input type="button" value="Add Subitem"&gt; &lt;input type="button" value="Add Category"&gt; &lt;/td&gt; &lt;td width="65%"&gt; &lt;input type="hidden" name="row[]" value="1"&gt; &lt;input type="text" name="categ[]" value="Sample Category" &gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="button" value="Add Subitem"&gt; &lt;input type="button" value="Add Category"&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="hidden" name="row[]" value="2"&gt; &lt;input type="text" name="sub[]" value="Sample Subitem" &gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="button" value="Add Subitem"&gt; &lt;input type="button" value="Add Category"&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="hidden" name="row[]" value="3"&gt; &lt;input type="text" name="categ[]" value="Sample Category" &gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" name="insBut" value="Save"&gt; &lt;/form&gt; </code></pre> <p>how can i iterate in row[]? and find if that row has categ or sub? i tried this</p> <pre><code>$row = $_post['row']; $categ = $_post['categ']; $sub = $_post['sub']; for ($i=0;$i&lt;count($row);$ii){ if (isset($categ[$i])){ $insQuery = pg_query("insert into rptdata_categ (blah blah) values (blah blah)"); }elseif (isset($sub[$i])) { $insQuery = pg_query("insert into rptdata_sub (blah blah) values (blah blah)"); } } </code></pre> <p>but the values are wrong, i tried to echo it with</p> <pre><code>echo $row[$i]."=".$categ[$i]; </code></pre> <p>and it gives</p> <pre><code>1=Sample Category 2=Sample Category 3= </code></pre> <p>i know its just right if you think about it, but how can i make it like</p> <pre><code>1=Sample Category 2= 3=Sample Category </code></pre> <p>oh and before i forget the user can add category or subitem on their own with button Add Category or Subitem.</p>
 

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