Jump to content

SQL for online Survey


dylan.bathurst

Recommended Posts

I am working with online surveys that have roughly 50 fields for the users to fill out. I have done smaller INSERT INTO's before. Such as the tutorial on this site, but never on a large scale. I was just wondering what would be a way to simplify this process. Instead of having:

$sql = "INSERT INTO table (column1, ..., column 52) VALUE ('$_POST[ id1]','...','$POST[ id53]')";

Thanks in advance.

Link to comment
Share on other sites

That's the statement you need. You can build it in a loop if you don't want to write the whole thing out yourself, but the SQL statement that you send to the server will be the same, there's only one way to insert data.

Link to comment
Share on other sites

If you know how many you have (i.e. 1 to 52), you can do this:

$sql = "INSERT INTO table (";for (i = 1; i <= 52; i++)  $sql .= "column{$i},";$sql = substr($sql, 0, strlen($sql) - 1);$sql .= ") VALUES (";for (i = 1; i <= 52; i++)   $sql .= "'" . mysql_real_escape_string($_POST['id' . $i]) . "',";$sql = substr($sql, 0, strlen($sql) - 1);$sql .= ")";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...