Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Jamiesw

  • Rank
  1. Perfect thanks, code works a treat now.
  2. Hi there, I am wanting to insert post data into my DB, this is guest information if i do a $safePost = filter_input_array(INPUT_POST); print_r($safePost); i get the following output. Array ( [action] => addGuestInfo [guestno] => 2 [bookingid] => 151 [customerid] => 22 [Guestname-0] => Jamie [Guestname-1] => Joe [GuestAge-0] => 4-3 [GuestInfo-0] => celiac [GuestAge-1] => 18 [GuestInfo-1] => wheat ) normally the guestname-0, guestage-0, guestinfo-0 would be in correct or
  3. thanks yes, however the bit i have been struggling with is the children can have children so it is N deep. and of course then the children can be parents aswell. Array ( [1] => Array ( [question] => looking for accommodation? [pageid] => 1A [relations] => Array ( [0] => Array ( [question] => How do you pay? [pageid] => 1A1 [relations] => Array ( [0]=> Array
  4. Thanks for relying. We have 2 tables Table 1 - tbl_questions (pageid has nothing to do with the parent \child, it references something else) id | Question | pageid 1 | looking for accommodation? | 1A 2 | How do you pay? | 1A1 3 | Can you stay with friends? | 2A2 Table 2 - tbl_question_relations parentid | childid 1|2 1|3 1|4 2|3 2|4 3|5 3|6 4|3 4|1 so the output would be in hierarchical json
  5. I have modified the code and i think it is giving me the right answers. My question is adding the child array to the parent. $question = new Question($db); //query $results = $question->read(); $numRows = $results->rowCount(); //check for data if ($numRows >0) { $question_arr['questions'] = array(); $child_arr = array(); $question_arr['questions'] = $results->fetchAll(PDO::FETCH_ASSOC); foreach ($question_arr['questions'] as $row){ //Need to add $child_arr to the current $question_arr['question'] $child_arr = buildTree($row[
  6. Hi Barand, here is the result. <pre>Array ( [parentid] => 1 [question] => Looking for somewhere to stay [pageid] => 1 [typeid] => 1 [numclicks] => 503 [date_created] => ) </pre>
  7. Hi All, Thanks, i have changed the code but get new error. Line 42 is : $question->parentid = $row['parentid']; <b>Warning</b>: Illegal string offset 'parentid' in <b>C:\htdocs\api\questions\read.php</b> on line <b>42</b><br /> function buildTree($child) { global $question; $branch = array(); foreach ($child as $row) { $question->parentid = $row['parentid']; $childresults = $question->read_children(); while ($childrow =$childresults->fetch(PDO::FETCH_ASSOC)) {
  8. Hi I am trying to create a hierarchy array from our mysql database. What i have so far is: //instantiate DB & connect $database = new Database(); $db = $database->connect(); //instantiate question object $question = new Question($db); //query $results = $question->read(); //check for data if ($results) { $question_arr['questions'] = array(); $child_arr = array(); while ($row = $results->fetch(PDO::FETCH_ASSOC)) { array_push($question_arr['questions'], $row); $question_arr['questions'][] = buildTree($row)
  9. yeah i can use either htmlentities($pagecontent) or htmlspecialchars($pagecontent) and it displays all my data now as json. Now need to work out how to convert it back to html in javascript. thanks for everyone's help.
  10. Hi there, Thanks for everyones help, the code works properly including reducing it down and not use the extract etc. The problems looks like the json_encode doesn't like the content within the Database, some of the pagecontent records contain html syntax for forms, i changed my sql to a different table and it worked as expected. any ideas on getting the json_encode to handle html syntax. (see below of sample data in the pagecontent field). [pagecontent] => <p>We just need to ask you a few questions so we can get you the right answer</p><h2>What is your
  11. Thanks, where can i find your examples?
  12. Hi, As I mentioned I am new to using PDO and was using an example from brad traversy building a backend api, the code i have used is more or less what he provided in his example including the fetch. The idea being i can pull the outputted json and use on the frontend using javascript.
  13. Thanks for replying so quickly, I am not echoing the json_encode within the loop it is echoing within the if{}, once the while{} is completed. If i print_r($page_arr['pages']); instead of trying to echo json_encode then i can see all the entries within the array. I just seems to be the json_encode isnt working, i am using PHP 7.3.6 if that makes a difference? i tried it at the end and it still made no difference..
  14. Hi there, Hoping some one can help. I am new to using PDO and i am trying to get data from my db to json I can get the data down to my $result so i know that part is working, my issue is with encoding it to json, if i pull a single record then it works if i pull all records then it doesn't, an i am not sure why $result = $page->read($_GET['pageid']); //check for data if ($result) { //page array $page_arr['pages'] = array(); while ($row =$result->fetch(PDO::FETCH_ASSOC)) { extract($row); $page_item = array(
  • 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.