Jump to content

Barand

Moderators
  • Content Count

    18,850
  • Joined

  • Last visited

  • Days Won

    346

Everything posted by Barand

  1. To make the data you load useful yo need the skill and a date the scores applied. +------------+ +-------------+ | user | | skill | +------------+ +-------------+ | user_id(PK)|---+ +------| skill_id(PK)| | name | | | | description | | etc | | | +-------------+ +------------+ | +----------+ | | | score | | | +----------+ | +----<| user_id | | | skill_id |>--+ | rank | | level | | xp | | date | +----------+
  2. Strange there is nothing to say which of the 27 skills those numbers refer to. Do you want the text that is in (..) also writing to the csv or just the number value?
  3. function validate() isValid = true; if email is invalid set isValid = false if password is invalid set isValid = false if passwords do not match set isValid = false return isValid end
  4. Can you show us a sample portion of $highscores that you egt from the api call? A point on data design - you have the user's name in the user table. You should not be repeating it in every row of the data table, they should contain the user's id value as a foreign key instead.
  5. Barand

    Best approach guidance

    If you don't like the object notation (eg $result=$conn->query("SELECT foo FROM bar"); ) you can always write yourelf a set of procedural PDO functions so you call $result = pdo_query($conn, "SELECT foo FROM bar") instead. After all , that is all that MySqli does, and, like mysqli procedural versions, you will always have that overhead of the intermediate function call. function pdo_query(PDO $conn, $querystring) { return ($conn->query($querystring)); }
  6. Barand

    PDO double entries

    Below is the output from echo '<pre>', print_r($response, 1), '</pre>'; showing a cut-down version of your response array. All you need to do is step through the sequence of keys on the way down to the item you want.
  7. Barand

    PDO double entries

    The array flattening is just a waste of time and effort. Get the data from the multi-D array directly. It's not rocket science. $myarray = array( 'Page_id' => $i, //your database table column name => data you want to insert 'County' => $response['county'], 'Country' => $response['country'], 'Post_Town' => $response['listings'][0]['post_town'] );
  8. Barand

    PDO double entries

    It's on this page of the manual. Scroll down a bit to "Variadic functions"
  9. Barand

    PDO double entries

    That line is wrong. It is pushing an array on to the $values array. You need to push the individual values from the array, hence the "..." in array_push($values, ...array_values($myarray));
  10. Barand

    PDO double entries

    $db->exec("DROP TABLE IF EXISTS test2DB"); //<---- I GOT THE ERROR HERE $db->exec("CREATE TABLE test2DB (
  11. Barand

    PDO double entries

    I cannot see anything obvious. I don't know what editor you are using but I did get a syntax error when I copied and pasted some of your code. The error disappeared when I deleted the whitespace between the lines, so it looks like some weird unprintable characters are lurking in there.
  12. Barand

    PDO double entries

    Have you tried to determine at which point the error is occurring? Does this bit work OK? for($i = $startnum; $i <= $endnum; ++$i) { $url = "http://api.somesite.com&page_number=$i"; $response = json_decode(file_get_contents($url), true); $resp = FlattenMultiArray($response, true, NULL); }// end for
  13. Barand

    Best approach guidance

    The trickiest bit will be determining age from date of birth, so here's easiest way SELECT ... WHERE timestampdiff(YEAR, date_of_birth, curdate()) BETWEEN 20 AND 35
  14. Barand

    PDO double entries

    What is your code that tries to do that with a for loop (and "goes to pot")? Where are you putting th loop? I have shown you code that uses a loop so I cant understand why you are having problems. As for the code pasting, use the <> button in the toolbar then paste.
  15. Barand

    Best approach guidance

    Query the table to get your friends' namea and ids for each result output checkbox whose name is "friend[]", label is the friend name and value is the friend id end for To process the posted data foreach ($_POST['friend] as $id) send email to friend whose id = $id end foreach
  16. Barand

    PDO double entries

    Per haps it is time for you to tell me what your table structure is what your response data looks like what you are trying to do, exactly Then perhaps I will be better able to help (though no guarantees).
  17. Barand

    PDO double entries

    That is what this line does - puts the values for the page_id ($i) and those from the $response array into the $values array. [Edit] Your version " array_push($values, $i, $myarray['County'], $myarray['Country']); " does exactly the same thing.
  18. Barand

    PDO double entries

    The comment in my code explained what the $mydata array was for. It merely provides the data to the $response and is nothing to do with its processing
  19. Barand

    PDO double entries

    What are you talking about? I don't have a $myarray or any other superfluous intermediate array to store the values from the $respnse, I use the keys and values directly from the $response array
  20. If you don't want to submit, return false from your validate function. EG <html> <head> <title>test</title> <script type='text/javascript'> function checkData() { return document.getElementById('chck').value != '' } </script> </head> <body> <form onsubmit='return checkData()'> <input type='text' name='chck' id='chck' value=''> <input type='submit' name='btnSub' id='Submit'> </form></body> </html>
  21. If it's expecting a 2D array to be rows and columns then perhaps you could make a 3D array be sheets, rows columns.
  22. Barand

    PDO double entries

    $mydata =[10=>['county' => 'Cheshire', 'country' => 'England'], ['county' => 'Lancashire', 'country' => 'England'], ['county' => 'Cumbria', 'country' => 'England'], ['county' => 'Derbyshire', 'country' => 'England'], ['county' => 'Yorkshire', 'country' => 'England'], ['county' => 'Lincolnshire', 'country' => 'England'], ['county' => 'Surrey', 'country' => 'England'], ['county' => 'Hampshire', 'country' => 'England'], ['county' => 'Pembrokeshiire', 'country' => 'Wales'], ['county' => 'Devon', 'country' => 'England'] ]; $db->exec("DROP TABLE IF EXISTS testdb"); $db->exec("CREATE TABLE testdb ( page_id int, county varchar(50), country varchar(50), primary key (page_id) )"); $startnum = 10; $endnum = 14; $placeholders = []; $values = []; for($i = $startnum; $i <= $endnum; ++$i) { /* $url = "http://api.somesite.com&page_number=$i"; $response = json_decode(file_get_contents($url), true); */ $response = $mydata[$i]; // no access to your data so substituting from array $mydata $mykeys = 'page_id, ' . implode(', ', array_keys($response)); $placeholders[] = "(?,?,?)"; array_push($values, $i, ...(array_values($response))); } //endfor $res = $db->prepare("INSERT INTO TestDB ($mykeys) VALUES " . join(', ', $placeholders)) ; $res->execute($values); echo $res->queryString; echo '<pre>$values = ', print_r($values, 1), '</pre>'; The query looks this, with sets of 3 placeholders for each of 5 records INSERT INTO TestDB (page_id, county, country) VALUES (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?) The $values array has 15 values (1 for each placeholder in the query) $values = Array ( [0] => 10 [1] => Cheshire [2] => England [3] => 11 [4] => Lancashire [5] => England [6] => 12 [7] => Cumbria [8] => England [9] => 13 [10] => Derbyshire [11] => England [12] => 14 [13] => Yorkshire [14] => England )
  23. Barand

    PDO double entries

    Yes. The $response array only contains county and country keys, so I added the page_id manually. The $myarray you created contains all three keys, which is why adding the page_id manually gives it twice.
  24. There won't be any "affected rows". It is not an update, delete or insert query.
  25. Barand

    PDO double entries

    I cannot understand why there are more than 5 records being written (10 to 14) If you bothered to look what it is doing you would see why that does and mine didn't. A home-grown function used for testing. I originally forgot to remove it.
×

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.