Jump to content
#StayAtHome ×

Stoffer

New Members
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Stoffer

  • Rank
    Newbie

Profile Information

  • Gender
    Not Telling
  1. But my saveWorkout class extends my connection class, shouldn't that be enough to do a referral? Furthermore, is this the appropriate way to use prepared statements? I feel there is not a lot gained from this if I create a prepared statement for every update..
  2. Hi, how do I use prepared statements when working with classes and functions? I need to do perform multiple identical inserts/updates to mySQL. I have been trying to implement into my connection class, based on what I have seen in examples I found on google. I keep getting fatal errors. My code is (save.php) <?php //Class extends DB_connect to access database class saveWorkout extends DB_Connect { // $stml->close(); public function get_jQueryData($planned_workout_id,$array_input) { // loop through workout progress, and check if input already exists in database for ($i = 0; $i < count($array_input['field_id']); $i++) { if(empty($array_input['field_id'][$i])) { $planned_workout_id = $array_input['planned_id'][$i]; $exercise_id = $array_input['exercise_id'][$i]; $set_id = $array_input['set_id'][$i]; $weight = $array_input['weight'][$i]; $reps = $array_input['reps'][$i]; $this->insertNewEntry->$stmt->execute(); } // closing else else { // Do something } //closing else } // Closing for statement } protected function insertNewEntry() { $stmt = $this->$connect()->prepare("INSERT INTO Workout_Log (planned_workout_id, exercise_id, set_id, weight, reps, entry_date) VALUES ( ?, ?, ?, ?, ?, ?)"); $stmt->bind_param($planned_workout_id, $exercise_id, $set_id, $weight, $reps, date("Y-m-d H:i:s")); } } // closing class save_workout ?> my connection file is looks like this (connect.php) class DB_Connect { private $servername; private $username; private $password; private $dbname; protected function connect() { $this->servername = "localhost"; $this->username = "root"; $this->password = "XXXXXX"; $this->dbname = "NNNNNNN"; $conn = new mysqli($this->servername,$this->username,$this->password,$this->dbname); return $conn; } };
  3. I managed to create multiple flat arrays, but struggling to map them into arrays and order them together based on exercise_id > set_id. In this case I would end up with 18 arrays, that contains data from each of the arrays below. Array ( [field_id] => Array ( [0] => h [1] => h [2] => h [3] => h [4] => h [5] => h [6] => h [7] => h [8] => h [9] => h [10] => h [11] => h [12] => h [13] => h [14] => h [15] => h [16] => h [17] => h ) [planned_id] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 [6] => 1 [7] => 1 [8] => 1 [9] => 1 [10] => 1 [11] => 1 [12] => 1 [13] => 1 [14] => 1 [15] => 1 [16] => 1 [17] => 1 ) [exercise_id] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 13 [5] => 13 [6] => 13 [7] => 13 [8] => 13 [9] => 14 [10] => 14 [11] => 14 [12] => 15 [13] => 15 [14] => 15 [15] => 16 [16] => 16 [17] => 16 ) [set_id] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 1 [5] => 2 [6] => 3 [7] => 4 [8] => 5 [9] => 1 [10] => 2 [11] => 3 [12] => 1 [13] => 2 [14] => 3 [15] => 1 [16] => 2 [17] => 3 ) [weight] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => ) [reps] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => ) )
  4. So far I can only transfer the data from jQuery in one of the 2 ways mentioned above
  5. Hi Brand, The data is a dynamic created form, which is contains a number of input-fields which are dublicated X amount of times, so that the user can enter the progress. It is transferred to my PHP page via jQuery, using the serialise function. The raw data which is transferred can be delivered in 2 different formats, whichever I choose - See the snips below. How I save the data in my database is going to be multiple different tables,I want to normalise my data as much as possible when I store it. Furthermore the data will be enriched by other data sources before I save it the database. Serialised form: Weight=&repetition=&field_id=h&set_id=1&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=2&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=3&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=4&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=1&exercise_id=13&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=2&exercise_id=13&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=3&exercise_id=13 or in array form.. which is 200+ subarrays Array ( [0] => Array ( [name] => Weight [value] => ) [1] => Array ( [name] => repetition [value] => ) [2] => Array ( [name] => exercise_id [value] => ) [3] => Array ( [name] => set_id [value] => ) [4] => Array ( [name] => field_id [value] => ) [5] => Array ( [name] => planned_id [value] => ) --- The array continues looping through all the fields about giving me 200+ subarrays [2xx] => Array ( [name] => Weight [value] => ) [2xx] => Array ( [name] => repetition [value] => ) [2xx] => Array ( [name] => exercise_id [value] => ) [2xx] => Array ( [name] => set_id [value] => ) [2xx] => Array ( [name] => field_id [value] => ) [2xx] => Array ( [name] => planned_id [value] => )
  6. Hi, I am trying to organise some data from a form which is transferred to me via jQuery. Right now I can transfer the data to my php function as either serialised data. Here I need to figure out to structure my data in arrays that allows me to work with them before I save to the database.. But how do I do this? I have been fiddling with explode, and trying to flatten it and do an array_push using a "while" for every 6'th item.. What I am looking for is this: Array[$i] ( Weight=>, repetition=>, field_id=>, set_id=> exercise_id=>, planned_workout_id= ) Array[$i++] ( Weight=>, repetition=>, field_id=>, set_id=> exercise_id=>, planned_workout_id= ) The structure I can have the data in Serialised form: Weight=&repetition=&field_id=h&set_id=1&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=2&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=3&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=4&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=1&exercise_id=13&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=2&exercise_id=13&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=3&exercise_id=13 or in array form.. which is 200+ subarrays Array ( [0] => Array ( [name] => Weight [value] => ) [1] => Array ( [name] => repetition [value] => ) [2] => Array ( [name] => field_id [value] => h ) [3] => Array ( [name] => set_id [value] => 1 ) [4] => Array ( [name] => exercise_id [value] => 1 ) [5] => Array ( [name] => planned_workout_id [value] => 1 ) [6] => Array ( [name] => Weight [value] => ) [7] => Array ( [name] => repetition [value] => )
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.