Jump to content

jimfog

Members
  • Posts

    1,803
  • Joined

  • Last visited

Everything posted by jimfog

  1. In the following line of your code I get error "trying to get property" of a non-object. $appdata[$appdetails->apID] = $details;
  2. Before doing what you propose I have to say this.... In the first while loop the code must be like this while ($appdetails = $result->fetch_object()){$details []= array('name' => $appdetails->name,'apID'=>$appdetails->apID,'start'=>$appdetails->startDate,'end'=>$appdetails->endDate,'staffID'=>$appdetails->staffID,'origin'=>$appdetails->apps_origin);$appdata[$appdetails->apID] = $details;} Cause your version will overwrite the previous array element....and we have 3 rows for example,only one will end up in the details array.
  3. Each query retrieves data from a different db table-the tables are related though in the following manner: The one table holds columns/data regarding appointments(APid,names,start,end etc)...the first query targets this table-APid is the primary key. The other query targets a table where it holds the services chosen for a specific appointment. For example we might have 2 rows there that correspond to the same appointments(same APid) but each row deals with a different service(service "1",service "2") So I have to take these 2 values(related to two different service) from this second table and add them as an array to the array produced by the first query. In essence the first query creates an array where each element is another array holding appointment data. I hope I was clear.
  4. Yes var_dump produces a 2 dimensional array and the way the for loop is now the offset error is justified. Nonetheless by looking at your answer here again http://w3schools.invisionzone.com/index.php?showtopic=51266&hl= and by doing some testing I have reached to some conclusions. First of all,the function must return a 3 dimensional array-something that does not happen now-and the reason lies in the answer you gave me in the above topic. You gave me this code-I remind you that I was asking you how to add the service in an array-: $details; while ($appdetails = $result->fetch_object()){ $details = array( 'name' => $appdetails->name, 'apID'=>$appdetails->apID, 'start'=>$appdetails->startDate, 'end'=>$appdetails->endDate, 'staffID'=>$appdetails->staffID, 'origin'=>$appdetails->apps_origin );} while($service = $result1->fetch_object()){ $details['service'] = $service->serviceID;} $names[] = $detail; The above creates a 2 dimensional array-which is undesirable-let me explain. The problem lies in the first while loop,if the result of the query is more than one row,only the last will be passed to the $details array. That is the mistake....service does get added successfully but the problem is directly above. With the code below I solve this issue but the service addition code must be reconsidered cause it no longer works. { while ($appdetails = $result->fetch_object()){ $appdata[]=['name'=>$appdetails->name,'apID'=>$appdetails->apID, 'start'=>$appdetails->startDate,'end'=>$appdetails->endDate,'staffID'=>$appdetails->staffID ,'origin'=>$appdetails->apps_origin]; } } I hope i was clear.Take a look now at var_dump($appdata): array(2) { [0]=> array(6) { ["name"]=> string(7) "Kostas " ["apID"]=> string(2) "16" ["start"]=> string(19) "2014-08-27 12:30:00" ["end"]=> string(19) "2014-08-27 15:00:00" ["staffID"]=> string(1) "5" ["origin"]=> string(7) "backend" } [1]=> array(6) { ["name"]=> string(3) "nik" ["apID"]=> string(2) "17" ["start"]=> string(19) "2014-08-27 09:00:00" ["end"]=> string(19) "2014-08-27 11:00:00" ["staffID"]=> string(1) "5" ["origin"]=> string(7) "backend" }} For each of the above services must be added,and since this may contain more than one value,this must be another array(hence the 3 dimensional array). I must take a look at the code in the function first before json_encode.
  5. I think the for loop does exactly that...unless you mean something else.
  6. I do not understand what are you trying to say. Outside the function $appdata DOES look like your example-here is the result of var_dump: array(7) { ["name"]=> string(7) "Kostas " ["apID"]=> string(2) "16" ["start"]=> string(19) "2014-08-27 12:30:00" ["end"]=> string(19) "2014-08-27 15:00:00" ["staffID"]=> string(1) "5" ["origin"]=> string(7) "backend" ["service"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" }}
  7. here is the result of print_r Array( [name] => Kostas [apID] => 16 [start] => 2014-08-27 12:30:00 [end] => 2014-08-27 15:00:00 [staffID] => 5 [origin] => backend [service] => Array ( [0] => 1 [1] => 2 ))
  8. No,it will not do it.I get a bunch of undefined offset errors. I could isolate the services with this but it must be added somehow to the JSON related to the $event array: for($k=0;$k<count($appdata['service']);++$k) { $service[$k]=array($appdata['service'][$k]); } echo json_encode($service); The above works but the downside is that I am sending a separate JSON stream while it needs to be a single one. I do not if a for loop within a for loop will do the job.
  9. This topic is related to this one http://w3schools.invisionzone.com/index.php?showtopic=51266&hl= I need to json_encode a multidimensional array....this is an example array-var_dump: array(7) { ["name"]=> string(7) "Kostas " ["apID"]=> string(2) "16" ["start"]=> string(19) "2014-08-27 12:30:00" ["end"]=> string(19) "2014-08-27 15:00:00" ["staffID"]=> string(1) "5" ["origin"]=> string(7) "backend" ["service"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" }} As you see....the above is a multidimensional array. The function that creates the above is this: function get_appointments($connection,$email)//να μάθω για το μηνυμα που σχετίζεται με το κιτρινο τριγωνακι { $connection->set_charset("utf8"); $result=$connection->query('select appointments.name,appointments.apID,staffID,appointments.app s_origin,FROM_UNIXTIME( startDate ) as startDate ,FROM_UNIXTIME( endDate ) as endDate from appointments,users where users.email="'.$email.'" and appointments.bookedfor=users.user_ID'); if(!$result) {printf("Errormessage for result: %sn", $connection->error); return false;} elseif($result->num_rows>0) { while ($appdetails = $result->fetch_object()){ $appdata=['name'=>$appdetails->name,'apID'=>$appdetails->apID, 'start'=>$appdetails->startDate,'end'=>$appdetails->endDate,'staffID'=>$appdetails->staffID ,'origin'=>$appdetails->apps_origin]; } } $result1 = $connection->query('select serviceID from services_list,appoint_servi_chosen where services_list.serviceID=appoint_servi_chosen.service_ID and appoint_servi_chosen.app_ID="'. $appdata['apID'].'"'); if(!$result1) {printf("Errormessage for result1: %sn", $connection->error); return false; } elseif($result1->num_rows>0) { while($service = $result1->fetch_object()) { $appdata['service'][] = $service->serviceID; }} return $appdata; } So,in the first query,data are loaded in the $appdata array,with each key of the array being another array which corresponds to a different database row-let us forget for now the second query(with $service related info being passed to the $appdata array) I can access the $appdata array with this for loop: for($i=0;$i < count($appdata);++$i) { $event[$i] = array('id'=>$appdata[$i]["apID"], 'title' => $appdata[$i]["name"], 'staff_ID'=>$appdata[$i]['staffID'], 'start' =>$appdata[$i]['start'], 'end'=>$appdata[$i]['end'], 'color'=>$backend,'allDay'=>false);//$backend and allday are not contained in the array...do not be confused with these two } echo json_encode($event); The problem arises when we add to the array the service(the result off the second query....it is what you see in the beginning of the topic )...how am I going to access the service key and its data? So,in essence(and tell me if I am wrong) we are dealing here with a 3-dimensional array(after service has been added). Thanks and sorry for the length of the topic.
  10. Υes,that worked thanks....
  11. I tried your code and the problem is that overwriting takes place. While result of the query related to the $service brings 2 rows from the db(with values "1" and "2")what gets passed to the array is only "2". Here is the result of var_dump to see for your self: array(1) { [0]=> array(7) { ["name"]=> string(7) "Kostas " ["apID"]=> string(2) "16" ["start"]=> string(19) "2014-08-27 12:30:00" ["end"]=> string(19) "2014-08-27 15:00:00" ["staffID"]=> string(1) "5" ["origin"]=> string(7) "backend" ["service"]=> string(1) "2" }} Take a look at the key service and its value.It is "2". The goal is that the key service contains another array that holds the values fetched from the db.In this example it is "1" and "2". It might as well be more values than two....but I think you have understood the nature of the problem. Thanks
  12. I have created a function that fetches some data from the db and these populate an array...what I want to do is add some more data to it and create a multidimensional array,,,,these second data are also fetched from the db.Take a look at the code and I will explain further: { while ($appdetails = $result->fetch_object()){ $names[]=array('name'=>$appdetails->name,'apID'=>$appdetails->apID,'start'=>$appdetails->startDate,'end'=>$appdetails->endDate,'staffID'=>$appdetails->staffID ,'origin'=>$appdetails->apps_origin); } while($service = $result1->fetch_object()) { $names[]=array('service'=>$service->serviceID); } The second data are in the second while loop. &service can me more than one row.As the syntax is now an array is created where 3 arrays are contained in it Let us suppose $service is 2 rows-in this example. One array contains $appdetails data,a second contains the results of one $service row and a third array contains the result of another $service row The goal here is that the names array gets another key,named services, and in it we have the result of the 2 services rows. So far,by trying various syntax either I will achieve the above,either I will get the overwriting problem. What do you propose?
  13. I have the following code: <?php if(empty($serviceslist)) { ?> <label>Services</label><br> <input class='service' id='servname' size='20' type="text" name="staff"> <?php} else { ?> <input class='service' id='servname' size='40' type="text" name="staff"> <?php } ?> $servicelist is an array, and in this case it is an empty array. So,logically the statement inside the else brackets should not run,but the weird thing is that is does. The end result being that the browser prints two input elements. What is wrong here. The IDE(netbeans) where I am developing the project does not indicate any syntax error. I need to stress also that if inside the else brackets there is an echo statement("pure" PHP code),this is not going to be executed. So the problem seems to be related with the HTML.
  14. let's start clarifying some things and ask some questions. fetch() involves a GET request I do not use REST...despite I use backbone. Regarding the syntax you see(without JSON.stringify), I asked the backbone google group and someone proposed this. Yes, you are right,JSON is usually sent in the payload with POST/PUT. As I said above though fetch() is a GET request and I do not think I can change that. And yes you are right...a JSON object is sent.I can see that in the dev tools now. Still cannot understand the diff between a JSON string and an object.
  15. I am trying to send to the server something using backbone's fetch command.... This is the code: events.fetch({ data: { service: 'service'}}); It is a JSON string as you can see. In the PHP script where the above goes I have this test code to see that the above actually goes to the server: $test=$_GET['service'];var_dump($test); Unfortunately the server responds with the usual error undefined index: service. And this happens(probably) because this is what is appended to the end of the URL which I cannot understand why: [object%20Object] Normally in the end of the URL there should be the string service...instead I see the above. The above would make sense(I think) if there was something wrong with the syntax....but I think the syntax is OK. What do you think?
  16. jimfog

    call method

    If it is not much of a trouble can you give an example? From the way you put it I assume that with the "traditional way" you cannot specify the scope-am I correct?
  17. jimfog

    call method

    I found here info about the call method here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call I assume you already know that it is a way to call a function. The question I want to make is if there any point in using it instead of the "traditional" way to do it-namely writing the function name?
  18. Yes,your solution worked....by making a minor adjustment though: this.selestrt=selestrt; P.S It had not occurred to me that backbone models are actually objects(with properties/methods)...I know that this can easily be deducted,nonetheless I hadn't noticed it(although it is apparent)
  19. As already stated, I just followed the stackoverflow post... Maybe I should prepare a jsfiddle demo.
  20. Regarding the first 2 lines...I just copied the code from StackOverflow and begun testing. And about the last line....if you notice it is INSIDE the changefrom function,cause I wanted to be available there. Of course there is more code there...I just omitted it for reasons of simplicity,the variable as it is there,"alone",of course it does not make sense. I can post the whole code if you want. Here is the error message as it appears in the console....http://1drv.ms/1sUJQoH
  21. This is the stackoverflow topic from where I got the above....http://stackoverflow.com/questions/9411896/using-global-variables-in-backbone-js#comment38377574_9411976 I have forgotten to put the variable inside the initialize function...still the problem remains.Here, how the code is now...again simplified: var EventView = Backbone.View.extend({ selestrt: null, initialize: function() { _.bindAll(this); this.selestrt; }, events: {"change #timesfrom": "changefrom", }, dropfrom:function(selestrt,test) { selestrt;//global }, changefrom:function(){ selestrt;//global }}); To get an understanding of what I am trying to do: When dropfrom is called,the dropdown menu appears with a preselected vaue...(the UNIX timestamp, which is stored at selestrt ). I want this to available at the changefrom function,which(as stated) is called when the user goes to change/selects a value from the drop menu.
  22. Below you will see code related to a backbone view(simplified)...I have not included some code so as to keep things as simple as possible-I think the omitted code will not affect what I am trying to convey here. var EventView = Backbone.View.extend({ selestrt: null, events: {"change #timesfrom": "changefrom", }, dropfrom:function(selestrt,test) { selestrt;//global }, changefrom:function(){ selestrt;//global }}); I have declared a global variable selestrt so that his can be available at BOTH functions...and here is where the problem manifests itself. The dropfrom function is used to build a dropdown menu(selestrt is a UNIX timestamp that is used to create the menu). Changefrom is called when the user makes s selection from the dropdown menu(you can see also the code corresponding to the event) #timesfrom is the id of the div where the menu is included. Unfortunately when changefrom is called selestrt is considered undefined. I did not include any HTML or prepare a fiddle for that matter cause I want to portray the problem as simple as possible-but if you consider it necessary I will do it.
  23. I did not know that the depedencies could be loaded with functions. Is it possible that jquery can be loaded as a function...instead of using script tags in the header. Probably not...but I am asking anyway. Now things make more sense. I did not know we were talking about two different things.
×
×
  • Create New...