Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not too sure why you need to have so many columns inside your table. A better solution might to have $tableName only have two columns, one for the slot, and the other that defines how many slots the table will have.</p> <p>The <code>slot</code> column will then be set as <code>auto_increment</code> inside MySQL, which means each time a row is added to the database, the number increments.</p> <p>The next table, will include all of the data that was originally in the the other columns. It would have three columns, the <code>slot</code> column, the <code>position</code> column (which would replace the B$x columns from the original table) and the <code>value</code> column, where the TEXT data is placed.</p> <p>This makes your database relational (see <a href="http://en.wikipedia.org/wiki/Relational_model" rel="nofollow">http://en.wikipedia.org/wiki/Relational_model</a>)</p> <p>You can then do a LEFT JOIN on the two tables to retrieve all of the data (<a href="http://www.w3schools.com/sql/sql_join.asp" rel="nofollow">http://www.w3schools.com/sql/sql_join.asp</a>)</p> <hr> <p>That being said, for your current solution, you would simply need to change some of your code.</p> <pre><code>if(isset($_GET["slot"])){ $tableName = $_GET["slot"]; $db = $_GET["db"]; } //getting the slot count if (isset($_GET['slots'])) { $slots = (int)$_GET['slots']; } if (!isset($slots) or !isset($tableName)) { echo "Please first provide the right data to this script!"; exit; } // Create the table $_columns = array(); for ($i = 1; $i &lt;= $slots; $i++) { $_columns[] = "B$i TEXT NOT NULL "; } $sql = "CREATE TABLE $tableName ( Slot int NOT NULL, PRIMARY KEY(Slot), " . implode( ', ', $_columns) . " )"; </code></pre>
    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. 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