开发者

Php Insert Lots of data to mysql

Hi I have an evaluation form with more than 300 fields, where there are several parts. i don't want to make 300 rows in mytable.Can someone give me a method how to save my data as it need to be easy to retrive to make some stats.

Thanks.

Edit: Something like that with lots of differnt parts

<form action="" method="post" id="OKF" name="OKF" autocomplete="off">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="25%" class="tableft"><strong>Date </strong></td>
          <td width="25%"><input name="controldate" type="number" id="controldate" /></td>
          <td width="25%"><strong>Start Time</strong></td>
          <td><input type="text" name="startime" id="startime" class="required"/></td>
        </tr>
        <tr>
          <td class="tableft"><strong>Controller</strong></td>
          <td><input type="text" name="controller" id="controller" /></td>
          <td><strong>End Time</strong></td>
          <开发者_如何转开发td><input type="text" name="endtime" id="endtime" class="required"/></td>
        </tr>
        <tr>
          <td class="tableft"><strong>Hotel Name</strong></td>
          <td><input type="text" name="otelname" id="otelname" class="required"/></td>
          <td><strong>Company Name</strong></td>
          <td><input type="text" name="compres" id="compres" class="required"/></td>
        </tr>
        <tr>
          <td class="tableft"><strong>No Stars</strong></td>
          <td><input type="text" name="stars" id="stars" class="required"/></td>
          <td><strong>No Room</strong></td>
          <td><input type="text" name="roomnum" id="roomnum" class="required"/></td>
        </tr>
      </table>
      <br>
      <h1>Part 1</h1>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="40%" class="tabtopmid">Question</td>
    <td width="4%" class="tabtopmid"></td>
    <td width="17%" class="tabtopmid"><strong>Point</strong></td>
    <td width="37%" class="tabtopmid"><strong>Comment</strong></td>
  </tr>
  <tr>
    <td>Question 1</td>
    <td>20</td>
    <td><input name="puan_1" id="puan_1" type="text"></td>
    <td><textarea name="cmt_1" id="cmt_1"></textarea></td>
  </tr>
  <tr>
    <td>Question 2</td>
    <td>20</td>
    <td><input name="puan_2" id="puan_2" type="text"/></td>
    <td><textarea name="cmt_2" id="cmt_2"></textarea></td>
  </tr>
  <tr>
    <td>Question 3</td>
    <td>20</td>
    <td><input name="puan_3" id="puan_3" type="text"/></td>
    <td><textarea name="cmt_3" id="cmt_3"></textarea></td>
  </tr>
  <tr>
    <td>Question 4</td>
    <td>20</td>
    <td><input name="puan_4" id="puan_4" type="text"/></td>
    <td><textarea name="cmt_4" id="cmt_4"></textarea></td>
  </tr>
  <tr>
    <td>Question 5</td>
    <td>20</td>
    <td><input name="puan_5" id="puan_5" type="text"/></td>
    <td><textarea name="cmt_5" id="cmt_5"></textarea></td>
  </tr>
</table>
      <input name="submit" type="submit" id="submit" value="Submit" alt="Submit" title="Submit">


depending on your fields would recommend you to make more than one table

form - id 1

n questions - id - type - value - label - form_id

and then you could store the answer of the users in a third table

easier to you would be names like formname[foobar], formname[foobar_1] and so on

then you are able to do something like:

$sql = "INSERT INTO answers (name, value) VALUES ";
foreach ($_POST['formname'] as $key => $value) {
  $sql .= "('".$key."', '".$value."'),";
}
$sql = substr($sql, 0, -1).";";
mysql_query($sql);

please note, this is only an example.. no security, no valiation, nothing


So this is a hotel registration form , i take it.

Well, the Questions should definitely be a separate table. Then, i guess, there should be a table for Reservations ( containing hotel_id, room_id, customer_id, date, additional info about reservation ) .. then a Customers table and Hotels table, and Rooms table ... and maybe few more.

It's impossible to tell, without knowing the the entire list of fields.


I never worked with 300 columns in one table. My suggestion is use JSON or someother serialized data technic for columns. Grouping related fields can save time in any case.

Recently used;

column = value (variable1:value1-variable2:value2-var3:val3)

adv_room_numbers(text) = "Room:2-Bedroom:3-Kitchen:1-Dining Room:1,etc..room:1,etc..room:1,etc..room:1" // I can use explode() to extract fields
adv_online(enum) = "active"
adv_contact(text) = "Name:Name Surname-Tel:65465-City:Cityname-Address:address details"


Is it all coming from one big form? If so, it might just make sense to put all the data into one array, serialise it, and log it to a file. Then analyse the data after with a more specialist tool.

If you do want to put it into a database, you need to spend some time breaking out the schema - I'm sure people would help but at the moment, the definition is too vague to say anything meaningful.

It might help you to use a framework to map between the front end form and the database. Symfony is excellent at form generation - you just write the files into a YAML file and run a command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜