Note that there are some explanatory texts on larger screens.

plurals
  1. POusing php to fill in an existing table
    text
    copied!<p>I have a blank html table (column) on my page. I have a csv file with last years info for that column available, but I don't want to initially write those values into the table cells (because there might be new info which needs to be manually entered). I would like to make a button which would populate this column. What would be the best way of going about this? Since I want the info entered dynamically I would obviously need to use an ajax call, and I would call a php file because that has a useful function fgetcsv(), but can I use this function to enter info into a existing table? I was able to use php to CREATE a table with this info, but as far as I understand, php has no knowledge of the DOM... I would have to somehow package the entire column info and have javascript do the job but I'm a little confused as to how...</p> <p>Below is a snippet of how I used php to CREATE my table.</p> <pre><code>$file = fopen("SGS_Fall_Booklist.csv", "r"); $entry= fgetcsv($file); echo $entry[0] . $_GET["program"] . $entry[1] . $GET["school"] . $entry[2] . $GET["term"]; echo "&lt;br&gt;AutoFill (last years ISBN's)&lt;br&gt;&lt;input id='checkall' type='checkbox' &lt;/input&gt;"; echo "&lt;table&gt;&lt;tr&gt; &lt;th&gt;Edit&lt;/th&gt; &lt;th class='coursename'&gt;" . $entry[6] . "&lt;/th&gt; &lt;th class='startdate'&gt;" . $entry[7] . "&lt;/th&gt; &lt;th class='booktitle'&gt;" . $entry[17]. "&lt;/th&gt; &lt;th class='author'&gt;" . $entry[18]. "&lt;/th&gt; &lt;th class='isbn'&gt;" . $entry[16]. "&lt;/th&gt; &lt;/tr&gt;"; while(! feof($file)) { $entry = fgetcsv($file); echo "&lt;tr&gt; &lt;td&gt;&lt;input type='checkbox'&gt;&lt;/input&gt;&lt;/td&gt; &lt;td class='coursename'&gt;" . $entry[6] . "&lt;/td&gt; &lt;td class='startdate'&gt;" . $entry[7] . "&lt;/td&gt; &lt;td class='booktitle'&gt;" . $entry[17]. "&lt;/td&gt; &lt;td class='author'&gt;" . $entry[18]. "&lt;/td&gt; &lt;td class='isbn'&gt;&lt;/td&gt; &lt;/tr&gt;"; } echo "&lt;/table&gt;"; fclose($file); </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