Jump to content


  • Posts

  • Joined

  • Last visited

jnymris's Achievements


Newbie (1/7)



  1. Firstly, Sorry about the lack of detail in the title, i'm not sure how to describe what i'm trying to achieve without going into detail. So I have a table: mysql> SELECT * FROM notes; +----+---------+-----------------+---------------------+----------+ | id | user_id | note | datetime | order_id | +----+---------+-----------------+---------------------+----------+ | 1 | 7 | Update Please? | 2018-02-16 22:22:18 | 1 | | 2 | 6 | Update Provided | 2018-02-16 22:25:18 | 1 | | 3 | 7 | test | 2018-02-17 10:03:20 | 2 | +----+---------+-----------------+---------------------+----------+ I'm trying to get the most recent row for each order_id. from the data above it result would be: Rows 2 and 3. I thought using a subquery would be the best way to go but i'm getting unexpected result: If i run the first part of the query I do get ID row 2 and 3 (which is a good sign). SELECT DISTINCT (order_id) FROM notes; If i run the second part of the query: I do get one result. SELECT user_id FROM notes WHERE order_id=1 ORDER BY datetime DESC LIMIT 1; When I combine both queries together I get an odd result. SELECT DISTINCT (order_id), user_id = (SELECT user_id FROM notes tbl2 WHERE tbl2.order_id=tbl.order_id ORDER BY datetime DESC LIMIT 1) FROM notes tbl; RESULT: +----------+------------------------------------------------------------------------------------------------------------+ | order_id | user_id = (SELECT user_id FROM notes tbl2 WHERE tbl2.order_id=tbl.order_id ORDER BY datetime DESC LIMIT 1) | +----------+------------------------------------------------------------------------------------------------------------+ | 1 | 0 | | 1 | 1 | | 2 | 1 | +----------+------------------------------------------------------------------------------------------------------------+ 3 rows in set (0.01 sec) Could anyone point me where i am going wrong? If it helps i'm actually only interested in getting the last row matches a specific value (7), but i just planned on doing this match with PHP if($user_id==7) //echo Will Display Data;
  2. Hi, I am currently using a webbrowse from within vb.net and have been able to navigate to a website login successfully. I am now looking to be able to download a .tar.gz and specific where to save this file to. (In order to get access to the download you have to login to create a cookie hence why i have logged in) When attempting to load the page (http://mysite/admin/backup.tar.gz) this then returns a dialog box. I am looking to see if i cane save this file automatically and not prompt the user? Example code to populate the username section For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input") If element.Name = "sessionUser" Then Dim i = 0 Dim strLine = "admin" element.InnerText = strLine End If Next and here is when prompts to save the file as: WebBrowser1.Navigate("") Thanks Johnny
  3. JustSomeGuy pcntl_fork appears to require *nix?
  4. Thanks JustSomeGuy I'm not sure i'm understanding pnctl_fork 100% from the examples it appears to return back to the user who 'created' the fork? I'm wanting the system to run script 'without the users knowledge which might take up to 15 minutes to run' Quick example how i'd call c:/inetpub/wwwroot/backgroundtask.php to be run in the background and the user can continue to browse pages? Thanks! Johnny
  5. are the current websites using php? have you tried a simple phpinfo to see what it showing? is php installed? in IIS you know you need a handler for php right? <?phpphpinfo();?>
  6. Hello, I've come across the need to run a background task after a user has submitted a form. Which i am having problems running. the php script calling the backup task does not need to wait for the response from the task. When i run the following command from cmd from within windows it runs fine: "c:program files (x86)phpv5.3php.exe" c:/inetpub/wwwroot/backgroundtask.php > c:/inetpub/wwwroot/backgroundtask.log however when running: exec('"C:Program Files (x86)PHPv5.3php.exe" C:/inetpub/wwwroot/Honours/bgprocess.php > C:/inetpub/wwwroot/Honours/bgprocess.log'); It fails to do anything (At the moment it is just creating and writing data into a text file as a proof of concept) I have also granted cmd.exe access to anyone in case this was an issue. Thanks Johnny
  7. I have updated the code to be more readable. Regards
  8. I'm attempting to upload files using Ajax. With the following code it will upload the first file correctly (and return the ID of that file) After changing the file to another file it will upload the second file again fine however it also re-uploads the first file thus generating two copies of the file. it is like the data is appended. I have attempted to remove the if (formdata){formdata.append("images[]",file);} which does not resolve this i have printed the value of len and it is always set to one. no matter how many files are being uploaded. (this is the problem for FireFox, Chrome and IE. Suggestions?: Javascript Code: var input = document.getElementById("files"),formdata = false;if(window.FormData){formdata = new FormData();document.getElementById("btn").style.display = "none";} function showUploadedItem (source){var list = document.getElementById("image-list"), li = document.createElement("li"),img = document.createElement("img");img.src = source;li.appendChild(img);} if(input.addEventListener){input.addEventListener("change", function (evt) {var i = 0, len = this.files.length, img, reader, file;document.getElementById("response").innterHTML = "Uploading . . ."for ( ; i < len; i++){ file = this.files[i]; if ( window.FileReader ){ reader = new FileReader(); reader.onloadend = function (e) { showUploadedItem(e.target.result); }; reader.readAsDataURL(file); } if (formdata) { formdata.append("images[]",file); }}if (formdata){$.ajax({url: "<?php echo base_url().index_page(); ?>meetings_ajax/upload_file",type: "POST",data: formdata,processData: false,contentType: false,success: function (res){document.getElementById("response").innerHTML = res;}});}}, false);}[/codeBOX]
  9. jnymris


    Morning/Afternoon/Evening all I've been using SOAP for around 3 months without any issues. Recently it has came to light that these SOAP requests (Currently have one request which is being called on two separate pages). To try and debug this i have try the same website on my machine (Copying the source files and config)(using phpinfo) SOAP if enabled on both my machine and the server along with all the SOAP configs being the same. It runs successfully on my machine yet fails to run on the server. To investigate this further i then created a 'internal soap' which again works successfully on my machine and fails on the server. the Server is currently in a DMZ which hasn't changed as far as I'm aware but to rule any changes out i disabled my Network card to ensure the soap on my machine still runs to find it does not? What would be the reason for this? and if it is possible, how can I remove this dependency? i can see reference to http://schemas.xmlsoap.org/... and http://www.w3.org/2001, would it be possible to download these files? (I'm assuming this isn't like HTML where it's a Document Type?) If this has been working so far and the DMZ has changed what may have caused this? What would be the best way to ensure everything is working. I've just replaced the .php files and again it is working on my machine and not on the server. Any Suggestions?
  10. jnymris

    MySQL If statement

    Thanks justsomeguy How would I go about creating a function and then calling the function? I've never created a function in MySQL. any suggestions/tutorials?
  11. jnymris

    MySQL If statement

    Morning/Afternoon All, I'm trying to create a simple if statement in SQLThis has been casuing me so much trouble since yesterdayHere's what i'm trying to achieve. IF((SELECT COUNT(*) FROM computers WHERE name='PC-01' AND domain='mydomain.local')==1)SELECT ComputerID FROM computers WHERE name='PC-01' AND domain='mydomain.local'ELSE IF((SELECT COUNT(*) FROM computers WHERE name='PC-01' AND domain='mydomain')==1)SELECT ComputerID FROM computers WHERE name='PC-01' AND domain='mydomain'ELSE IF(SELECT COUNT(*) FROM computers WHERE name='PC-01')==1)SELECT ComputerID FROM computers WHERE name='PC-01' I have tried: IF((SELECT COUNT(*) FROM computers WHERE name='PC-01' AND domain='mydomain.local')==1)BEGINSELECT ComputerID FROM computers WHERE name='PC-01' AND domain='mydomain.local'ENDELSE IF((SELECT COUNT(*) FROM computers WHERE name='PC-01' AND domain='mydomain')==1)BEGINSELECT ComputerID FROM computers WHERE name='PC-01' AND domain='mydomain'ENDELSE IF(SELECT COUNT(*) FROM computers WHERE name='PC-01')==1)BEGINSELECT ComputerID FROM computers WHERE name='PC-01'END Along with other suggests which google returned. to no luck. How can a simple IF statement be so complicated? (Side Note: using phpmyadmin i cannot do print/echo/prompt commands is that normal?)
  12. Scott, When to use the username and first name is totally down to you. When you log into W3school at the top you can see your full name. However i logged in with my username. But W3schools wish to display my first and second name to me rather than the username which they could have done. You could use a firstname, surname and password as a login action but of course more than one person exsist in the world with the same name and if they both have the same password what happens then? It's NOT Recommended but it's possible.
  13. Thanks JustSomeGuy (You've always helped on this board and i've been here for a 'while' you seem to be the most helpful person on this board that sticks around so Thank you for that aswell !I did managed to use this (the row_number function) just wondering which of the two would be best for performance/speed? SELECT * FROM (SELECT row_number() OVER ($sOrder) as rownum, * FROM $sTable $sWhere) as a WHERE a.rownum BETWEEN 10 AND 20 );
  14. EDITThanks Very Much i got this workingI was trying to create a new variable using: $result=usort($query,'sort_clients'); instead of using usort($query,'sort_clients'); Can i ask, Where does the $b come from cause we are onyl passing one variable through? Thanks So i've tried two ways to do the uSort i'm using a MCV design method so i tried: (This is all being done in the model because this is reference more than once and it always to be in alphabetical order. function get_clients_list(){ $portal = $this->load->database('clientportal', TRUE); $query = $portal->get('cplinktable')->result(); foreach ($query as $client) $client->client_name=$this->get_username($client->autotaskid)->account_name; $result=usort($query,$this->sort_clients); die(var_dump($result)); return $query; } function sort_clients($a,${ if($a->client_name > $b->client_name) return 1; else if ($a->client_name < $b->client_name) return -1; else return 0; } Error returned was:Message: usort() expects parameter 2 to be a valid callback, no array or string given and retruned NULL when pringin $result so i tried: function get_clients_list(){ function sort_clients($a,${ if($a->client_name > $b->client_name) return 1; else if ($a->client_name < $b->client_name) return -1; else return 0; } $portal = $this->load->database('clientportal', TRUE); $query = $portal->get('cplinktable')->result(); foreach ($query as $client) $client->client_name=$this->get_username($client->autotaskid)->account_name; $result=usort($query,'sort_clients'); die(var_dump($result)); return $query; } Error Returned:bool(true)
  15. Solution function get_clients_list(){ $portal = $this->load->database('clientportal', TRUE); $query = $portal->get('cplinktable')->result(); foreach ($query as $client) $client->client_name=$this->get_username($client->autotaskid)->account_name; $result=usort($query,array($this,'sort_clients')); die(var_dump($result)); return $query; } function sort_clients($a,${ if($a->client_name > $b->client_name) return 1; else if ($a->client_name < $b->client_name) return -1; else return 0; } QuestionOkay I'm really having problems with trying to sort an array which contain objects Here's my output from my query $client is the array thats being shown. array(49) {[0]=> object(stdClass)#19 (6 { ["id"]=> int(3) ["external_id"]=> int(29735292) ["asset_db"]=> string(18) "WaspTrackAsset_SFT" ["business_mgr"]=> NULL ["tech_mgr"]=> NULL ["client_name"]=> string(22) "Client Name 1 } [1]=> object(stdClass)#20 (6) { ["id"]=> int(4) ["external_id"]=> int(27529753) ["asset_db"]=> string(17) "WaspTrackAsset_TS" ["business_mgr"]=> NULL ["tech_mgr"]=> NULL ["client_name"]=> string(28) "Client Name 2" } [2]=> object(stdClass)#21 (6) { ["id"]=> int(5) ["external_id"]=> int(27529736) ["asset_db"]=> string(17) "WaspTrackAsset_HC" ["business_mgr"]=> NULL ["tech_mgr"]=> NULL ["client_name"]=> string(14) "Client Name 3" } [3]=> object(stdClass)#22 (6) { ["id"]=> int(14) ["external_id"]=> int(29701765) ["asset_db"]=> string(18) "WaspTrackAsset_ATA" ["business_mgr"]=> NULL ["tech_mgr"]=> NULL ["client_name"]=> string(15) "Client Name 4" }.. (You get the point right?)} now what i'm trying to do is arrange the arrange for the client_name with the most alabetical name to be $client[0] without loosing the external_id, asset_db etc. i have tried ksort() and looked at usort(). I've google search for this but nothing seems to explaining in clearly. Arrays and objects are not my strong point however I am starting to understand them much more.Would greatly if someone could take the time to give an example AND explain (it's pointless giving the just the code) Thanks Very MuchJohnny (The reason i cannot use an order_by is due to the full function: function get_clients_list(){ $portal = $this->load->database('clientportal', TRUE); $query = $portal->get('cplinktable')->result(); foreach ($query as $client) $client->client_name=$this->get_username($client->autotaskid)->account_name; //die(var_dump($query)); return $query; } )
  • Create New...