Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery result to array, then access in external javascript file
    primarykey
    data
    text
    <p>First I want to thank you guys here, because your posts have gotten me as close as I have been in the past week or so to resolve this; but I need help to finish this. I will admit, this process is still not clear in my mind and I am also exhausted to please bear with me</p> <p>The script below has gotten me so close What I need to accomplish: I need to grab some data from my db, stick it into an array and then access/use the values in that array in my external javascript file. I'll be using on the onload event.</p> <pre><code>&lt;s c r i pt language="javascript1.2"&gt; var arr = new array(&lt;?php $result = mysql_query("select account_id, display_name, id from field where account_id = $holdAcctID and required_flag = 1"); $count = mysql_num_rows($result); if($count&gt;0){ for( $i=0;$i&lt;$count-1;$i++) { $row = mysql_fetch_row($result); echo $row[2],','; } $row = mysql_fetch_row($result); echo $row[2],','; } ?&gt;); &lt;/s c r ipt&gt; </code></pre> <p>above script produces this in my view source page:</p> <pre><code>&lt;s c ript language="javascript1.2"&gt; **var arr = new array(2860,2861,2862,2863,2864,3293,3294,3296,3521,3523,);** &lt;/s c ript&gt; </code></pre> <p><strong>Q1</strong> - how can i update the above array, so it holds the data from the same like the example below: as you can see, it currently only holds, displays the id value</p> <pre><code>myReqField[0] [account_id] =&gt; 72 [display_name] =&gt; Client Contact Name [id] =&gt; 2860 myReqField[1] [account_id] =&gt; 72 [display_name] =&gt; Contact Phone [id] =&gt; 2888 myReqField[2] [account_id] =&gt; 72 [display_name] =&gt; Email Address [id] =&gt; 2865 myReqField[3] [account_id] =&gt; 72 [display_name] =&gt; Approval needed [id] =&gt; 2841 </code></pre> <p><strong>Q2</strong> - how easy would it be to do this and place the results into a comma separate list. If fairly easy how would I code that and how can I access the list/value from my external javascript</p> <p><strong>Q3</strong> - If Q2 is not possible/easy to set up, how then do I pull the array in to javascript file. Several have mentioned json, but the other developer doesn't want to use it.</p> <p>Thank you in advance!</p>
    singulars
    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