How to combine PHP array from user input with MySQL table for calculation (conceptually)? -


i have website, user can enter time series (date; series) text area. data sent server using post method.

i have few tables different time series stored in mysql database. user specified time series , stored in database should combined statistical calculations.

i store user input array using explode , want select time series database using date selector (where date = $datefromuserinput). have 2 problems here:

  • the date format array not match 1 in mysql (iso, o-m-d) after several transformations (e.g. strtotime).
  • also, time series data type in mysql in decimal (15,4) format, 1 in php string (transformed float).

before trying find solutions, know if concept right , best. putting user input mysql table make calculations faster (as understand). however, several users can use form simultaneously result in overwriting entries in new table in mysql, right? should load complete mysql table php array (session necessary)?

i have read many solutions not find these answer. hint highly appreciated.

<?php date_default_timezone_set('utc');  //session_start();  //$datum = [];  if ($_post['usersubmit']) { if ($_post['userinput1'] !=""){          if ($_post['separator'] != ""){         if ($_post['separator'] == comma){         $separatorsign = ",";         }         elseif ($_post['separator'] == semicolon){         $separatorsign = ";";         }         else {         $separatorsign = "\t";         }     }    $userinput1 = $_post['userinput1'];   $zeilen= explode("\n", $userinput1); $daten = array(); foreach($zeilen $zeile) {     list($datum, $zeitreihe) = explode($separatorsign, $zeile,2); $datumkonv = strtotime($datum);   $daten[]['datum'] = date('o-m-d',$datumkonv); $daten[]['zeitreihe'] = $zeitreihe;  }    $con = mysql_connect('localhost','username','pw'); if (!$con) { die('could not connect: ' . mysql_error($con)); }  mysql_select_db("dbname");  $sql = "select series mytimeseries1 date = $daten[0]['datum']"; //[0]         trying working first row  $result = mysql_query($sql);   $row = mysql_fetch_object($result);  echo "$row->series";//["series"].'<br>';  $row = floatval($row);  $ergebnis = $row + 22; echo $ergebnis; // $row 100.5000 $ergebnis returns 100.5023 ??   mysql_free_result($result); mysql_close($con);   echo "<pre>";  //print_r ($result);  print_r ($row); var_dump($row);  var_dump($ergebnis);     } }    ?>  <table width="800">  <tr>   <td width="400"> <form action="test.php" method="post">  <p><textarea style="overflow-y:scroll;resize:none;" name="userinput1"   id="userinput1" cols="28" rows="12"></textarea></p>      <p>separator<br>    <input type="radio" name="separator" value="comma">comma</p>      <p><input type="radio" name="separator" value="tab">tab</p>  <p><input type="radio" name="separator" value="semicolon">semicolon</p>    </td>         <td width="400">  <p>date format<br>  <input type="radio" name="dateformat" value="yyyy-mm-dd">yyyy-mm-dd</p>  <p><input type="radio" name="dateformat" value="yyyy-dd-mm">yyyy-dd-mm</p>  <p><input type="radio" name="dateformat" value="dd-mm-yyyy">dd-mm-yyyy</p>  <p><input type="radio" name="dateformat" value="mm-dd-yyyy">mm-dd-yyyy</p>  <p><input type="radio" name="dateformat" value="ddmmyyyy">dd.mm.yyyy</p>      <p><input type="submit" name="usersubmit" value="go"></p> </form>    </td>   </tr>   </table>  <?php 

edit: after trying hours think makes more sense upload user input array temporary table in mysql (date format accepted etc). had change foreach()-part in code above to:

for($y = 0;$y < count($zeilen);$y++){     list($datum, $zeitreihe) = explode($separatorsign, $zeilen[$y], 2);     $daten[$y]['datum'] = $datum;     $daten[$y]['zeitreihe'] = $zeitreihe;     } 


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -