Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is that you so called arrays are strings!</p> <pre><code>global $field1; global $field2; var_dump($feild1,$feild2); //Will tell you that there strings </code></pre> <p>Read the error properly !</p> <p><strong>[]</strong> operator not supported for <strong>strings</strong></p> <p>And the only place your using the <code>[]</code> is withing the <code>$feild</code> <em>- X</em> values</p> <p>GLOBAL must work because the error is telling you a data-type, i.e string so they must have been imported into scope.</p> <hr> <p>another thing, why you selecting all columns when your only using 2 of them, change your query to so:</p> <pre><code>$sql = mysql_query("SELECT feild1,feild2 FROM table WHERE field_name = '$input'"); </code></pre> <p>another thing is that your using <code>mysql_fetch_array</code> witch returns an integer indexed array, where as you want <code>mysql_fetch_assoc</code> to get the keys.</p> <pre><code>while($row = mysql_fetch_assoc($sql)) : $field1[] = $row['field1']; $field2[] = $row['field2']; endwhile; </code></pre> <hr> <h2><strong>What I would do</strong></h2> <pre><code>function SomeFunction($variable,&amp;$array_a,&amp;$array_b) { $sql = mysql_query("SELECT field1,field2 FROM table WHERE field_name = '$variable'"); while($row = mysql_fetch_assoc($sql)) { $array_a[] = $row['field1']; $array_b[] = $row['field2']; } mysql_free_result($sql); } </code></pre> <p>Then use like so.</p> <pre><code>$a = array(); $b = array(); SomeFunction('Hello World',&amp;$a,&amp;$b); </code></pre>
 

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