Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>&lt;html&gt; &lt;head&gt; ... &lt;script src="jquery.js"&gt;&lt;/script&gt; ... &lt;head&gt; &lt;body&gt; .... &lt;table id="clickable"&gt;&lt;tr&gt;&lt;td&gt;Hello&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; &lt;script&gt; $('#clickable td').on('click', function(e){ $.ajax({ type: 'POST', url: 'yourphppage.php', data: {sendCellValue: $(this).text()} }); }); &lt;/script&gt; .... &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The table can be as large as you like, and the above script will send to your PHP page any cell that is clicked in the table that has the id "clickable". Note that if you want more than one clickable table, you should change it from an id to a class.</p> <p>Then in yourphppage.php, (which given the above code must be in the same directory:</p> <pre><code>&lt;?php session_start(); $_SESSION['cellValue'] = $_POST['sendCellValue']; ?&gt; </code></pre> <p>Saving the information to a database is very different to a session. Do you need to differentiate who clicked what? Or just record what was clicked on, regardless of who clicked it? </p> <p>If so, use the following instead of the second snippet above:</p> <pre><code>&lt;?php $connection = mysql_connect("localhost","my_db_username","pass1234"); mysql_select_db("my_db_name", $connection); mysql_query('INSERT INTO TheTable (CellValue) VALUES ("'.mysql_real_escape_string($_POST['sendCellValue']).'")'); ?&gt; </code></pre> <p>For that you will want a table (called TheTable). It will need two columns. The first could be called "ID" or something similar. It will need to be set as "auto-incrementing", and its type must be "Integer". The second column must be called "CellValue", and its type can be set to "varchar" with 255 characters. </p> <p>To output the information, so it can be printed, you should ask a new question on how to output a database table to HTML. In all likelihood you will probably not want to print the table as-is, so you should be specific about what it is people will be clicking on, i.e. is it text? Or a nummber? And if it's a number, what kind of number? Do you want to group the numbers and show a total number of clicks for each group? Etc, please be specific. You may need to change some of the above depending on what post-processing you want to do on the information in the table before you print it out. For example, you may need to change the second column's type from varchar to integer or float (and in that case you would need to change the PHP file as well).</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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