Jump to content

stubarny

Members
  • Posts

    122
  • Joined

  • Last visited

Everything posted by stubarny

  1. Hi, Please could you tell me how to control a robot from a php script? I've been looking at raspberry pie based robots on the internet but they don't seem to use php as the controlling code. For example if I receive an order on my website, how do I use php to activate a product dispenser to drop a product onto a robot, and then use php to direct the robot to a packing area? Thanks for any pointers. S
  2. $result returns "Resource id #5" if I use echo or print_r, which i think is normal?
  3. Hello, This is confusing me! - this code is finding 2 rows of data ($nrows is 2), but I'm only getting 1 row of data returned. On the second while loop I'm getting the following error message: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/website.com/test.php on line 26 $query ="SELECT * FROM Accounts WHERE (jaaLatitude = '' OR jaaLongitude = '')"; $result=mysql_query($query) or die ("Connection to database table failed." . mysql_error()); $nrows=mysql_num_rows($result); $i = 0; if ($nrows > 0) { while($record = mysql_fetch_array($result, MYSQL_BOTH)) { $jaaIndex = $record[jaaIndex]; $jaaEmail = $record[jaaEmail]; $jaaLocation = $record[jaaLocation]; $jaaLongitude = $record[jaaLongitude]; $jaaLatitude = $record[jaaLatitude]; echo "<br>test jaaEmail is $jaaEmail<br>"; $i = $i + 1; } } As I say the first while loop is working, so I don't see what can be wrong with the qurery (it's not failing). Thanks for your help, S
  4. I'm looking to download a file and save it to my server. the link http://webmail.website.com/src/download.php?mailbox=INBOX&passed_id=6475&startMessage=1&override_type0=text&override_type1=html&ent_id=2&absolute_dl=true INITIATES the download (it is not the file being downloaded), and the file being downloaded it called test.html. At the moment I have to hard code in my php script to call the downloaded file "test.html", shouldn't I be able to find the file name from the downloaded file? Secondly I don't know how to download non html files with CURL - I've tried to download .pdf and .docx files and both have failed. Is it possible? Thanks, Stu
  5. The download link is: http://webmail.WEBSITE.com/src/download.php?mailbox=INBOX&passed_id=6475&startMessage=1&override_type0=text&override_type1=html&ent_id=2&absolute_dl=true and that link successfully downloads a file called test.html I then save that file as "test.html" but I've had to hard code the file name and the extension in the code of my first post. I want to have the code automatically find the file name and extension. Is this information not somewhere in the $data variable?
  6. Hi, The file extension of the download file isn't in the URL. The URL prompts the download, and the file is then downloaded. I need to know how to capture the file name and the extension from the file (not the url). Does that make sense?
  7. Hello, I have managed to find, retrieve and save a file using CURL. But I am having to hard code the file extension, is there a way to find the file extension automatically? (it seems the file extension isn't within the download URL) (also, is there a way of getting the file name so I can save it as the same filename - that would be great) Thanks for your help, Stu p.s. I've tried the pathinfo($url) function, but that gets information out of the download URL rather than the download file. $url="http://webmail.WEBSITE.com/src/redirect.php"; $cookie="cookie.txt"; $postdata = "login_username=USERNAME&secretkey=PASSWORD&js_autodetect_results=0&just_logged_in=1"; # get the cookie $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); curl_close($ch); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //read cookies from here curl_setopt($ch, CURLOPT_URL, "http://webmail.WEBSITE.com/src/right_main.php"); curl_setopt($ch, CURLOPT_HEADER, 0); $result = curl_exec($ch); curl_close($ch); # download file $source = "http://webmail.WEBSITE.com/src/download.php?mailbox=INBOX&passed_id=6475&startMessage=1&override_type0=text&override_type1=html&ent_id=2&absolute_dl=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //read cookies from here curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION,3); $data = curl_exec ($ch); $error = curl_error($ch); curl_close ($ch); # !!! The line below needs to be automated !!! $destination = "./files/test.html"; $file = fopen($destination, "w+"); fputs($file, $data); fclose($file);
  8. Many thanks Jacques, it's working perfectly.
  9. yes but I'm not calling those links (so I can't fix them?) - the email login page calls them on the server side? I don't see why me using curl makes the relative links to fail
  10. OK great, getting closer! I can see the structure (there's a frame divide where I expect it to be), so I'm convinced I'm logged in and the inbox webpage if being (partly) returned. But I'm getting two errors returned: Not FoundThe requested URL /left_main.php was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Not FoundThe requested URL /right_main.php was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. I don't really see why the files wouldn't be found due to an incorrect file path, because I thought curl just requests the webpage - if that webpage requires other files aren't those files called server side? (I've visited the squirrelmail inbox manually and it definately works). Here's the code that's almost working: $url="http://webmail.WEBSITE.com/src/redirect.php"; $cookie="cookie.txt"; $postdata = "login_username=USERNAME&secretkey=PASSWORD&js_autodetect_results=0&just_logged_in=1"; # get the cookie $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); curl_close($ch); # retrieve the inbox page $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //read cookies from here curl_setopt($ch, CURLOPT_URL, "http://webmail.WEBSITE.com/src/webmail.php"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch);
  11. Thanks, yes my (very limited) curl experience is about 2 hours in total! I've tried adding an extra section to retrieve the page after initialising the cookie, but I'm still getting a blank response with the code below, I guess I'm still doing something wrong? ... $username="my_user"; $password="my_passs"; $url="http://webmail.WEBSITE.com/src/redirect.php"; $cookie="cookie.txt"; $postdata = "login_username=USERNAME&secretkey=PASSWORD&js_autodetect_results=0&just_logged_in=1"; # get the cookie $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); echo $result; curl_close($ch); # retrieve the inbox page $url="http://webmail.WEBSITE.com/src/webmail.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //read cookies from here curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); curl_close($ch);
  12. OK thanks, I've checked that my host has CURL (which it does) and have tried the code below. I remembered to add the hidden variables but I still just get a blank page. Am I missing something? Thanks, Stu $url= "http://webmail.MY_WEBSITE.com/src/redirect.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); # POST variables $postdata = "login_username=USERNAME&secretkey=PASSWORD&js_autodetect_results=0&just_logged_in=1"; curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $output = curl_exec($ch); echo $output; curl_close($ch);
  13. Hi, I need to log into a website to check for the latest data, and I want to automate this with php script that will use a cronjob to log in, retrieve the data and email it to me. Currently I'm stuck on the logging in part (I'm testing the script below on my squirrelmail email login page). I've tried using the snoopy php class (sourceforge.net/projects/snoopy/) but it seems the POST variables aren't being recognised (because the email program is directing me to the log in page, as opposed to telling me that my username/password is wrong). (is it even possible for a servers to accept POST variables in this way??? I'm kind of surprised but lots of poeple seem to use snoopy to login via userforms) Please could someone point me in the right direction? Thanks, Stu / load the snoopy class and initialize the object / $snoopy = new Snoopy(); / set some values / $login_form['login_username'] = 'MY_USERNAME'; $login_form['secretkey'] = 'MY_PASSWORD'; $snoopy->cookies['vegetable'] = 'carrot'; $snoopy->cookies['something'] = 'value'; / submit the data and get the result / $snoopy->submit('http://webmail.MY_WEBSITE_NAME.com/src/redirect.php' $p_data); / output the results / echo '<pre>' . htmlspecialchars($snoopy->results) . '</pre>';
  14. Hi All, I'm very comfortable with PHP/MYSQL programming but my websites look very basic visually (e.g. like craigslist.org). What is the best way to apply a good website graphical design? I've noticed a lot of nice looking wordpress websites but I would prefer to have complete control over the PHP/SQL database. Any ideas? Thanks, Stu
  15. Hi, Thank you very much for your help - I've tidied up the field names (I've left the initial of the table name just so that the php variables are ready-named when I retrieve them out of sql), and I've removed the ID field on the correlations field as suggested. Keyphrases: kID | kContent 1 | Accountant 2 | Management Accountant 3 | Financial Accountant JobAdverts: jaID | ja_kID 1 | 1 2 | 2 3 | 3 4 | 2 5 | 1 6 | 3 Correlations: cKeyphrase1_kID | cKeyphrase2_kID | cContent 1 | 3 | 0.76 1 | 2 | 0.84 1 | 1 | 4 (my correlations are 'relative' instead of absolute therefore a good correlation often has a value greater than 1 - sorry, not my source data!) Please could you give me a hand creating SQL code for the below tasks?: I think I need an SQL query to: 1. Find kID for the searched for keyphrase 2. Select all records in the JobAdverts table 3. Attach cContent to each record in the JobAdverts table --> (done by finding cContent where kID of the search term = cKeyphrase1_KeyphraseID and JobAdvert_KeyphraseID = cKeyphrase2_KeyphraseID) 4. Sort by cContent DESC Is the below code is close to the correct answer? Is there a way of finding the relevant value for kID and using the value all in the same query, instead of splitting this into 2 queries like below? SELECT kID from Keyphrases WHERE kContent = '$searched_for_keyphrase' # extract result to variable $kID SELECT * from JobAdverts INNER JOIN Correlations ON (Correlations.cKeyphrase1_kID=$kID AND Correlations.cKeyphrase2_kID=JobAdverts.ja_kID) ORDER BY JobAdverts.cContent DESC Many thanks, Stu
  16. Thank you Barand, yes that would be fine. Any idea how best to construct the SQL query?
  17. sorry, I didn't realise you meant foreign keys. But using your methodology I could enter 1 or 5 for "Accountant" which isn't normalised? Let me try again, this time adding an extra table for the "keyphrases" and then referring to it with foreign keys: Keyphrases: KeyphraseID | KeyphraseContent 1 | Accountant 2 | Management Accountant 3 | Financial Accountant JobAdverts: JobAdvertID | JobAdvert_KeyphraseID 1 | 1 2 | 2 3 | 3 4 | 2 5 | 1 6 | 3 I also have a big (millions of records) table of job title correlations, for example: Correlations CorrelationID | CorrelationKeyphrase1_KeyphraseID | CorrelationKeyphrase2_KeyphraseID | CorrelationContent 1| 1 | 3 | 0.76 2| 1 | 2 | 0.84 Is that more useful? I think I need an SQL query to: 1. Find KeyphraseID for the searched for keyphrase 2. Select all records in the JobAdverts table 3. Attach CorrelationContent to each record in the JobAdverts table --> (done by finding CorrelationContent where KeyphraseID of the search term = CorrelationKeyphrase1_KeyphraseID and JobAdvert_KeyphraseID = CorrelationKeyphrase2_KeyphraseID) 4. Sort by CorrelationContent DESC Please could you show me how to create an SQL query to do that? Thanks, Stu
  18. Thank you Christian, Please my ask for you to explain the below part further? I assume this has nothing to do with aliases?: Thank you, Stu
  19. Hi All, I need to create a job search tool for the below table of job adverts: JobAdvertNumber | JobAdvertTitle 1 | Accountant 2 | Management Accountant 3 | Financial Accountant 4 | Management Accountant 5 | Accountant 6 | Financial Accountant I also have a big (millions of records) table of job title correlations, for example: JobTitle1 | JobTitle2 | Correlation Accountant | Financial Accountant | 0.76 Accountant | Management Accountant | 0.84 Please could you tell me how to create a job search tool that returns the adverts in order of their job title's correlation with the searched for term. For example if I did a job search for "Accountant" it should return all the "Accountant" jobs first, then all the "Management Accountant" jobs and finally all the "Financial Accountant" jobs. Many thanks, Stu
  20. Thank you Barand! :'( Here is the finished code: $query_recommendations=" SELECT submission_votes.submission_vote_submission_number, COUNT(*) as recommendation_subtotal FROM submission_votes INNER JOIN ( SELECT submission_vote_account_number, submission_votes.submission_vote_submission_number FROM submission_votes INNER JOIN ( SELECT submission_vote_submission_number FROM submission_votes WHERE (submission_vote_account_number = 1200 AND submission_vote_content = 1) ) as X ON submission_votes.submission_vote_submission_number = X.submission_vote_submission_number WHERE (submission_votes.submission_vote_account_number <> 1200 AND submission_votes.submission_vote_content = 1) ) as Y ON submission_votes.submission_vote_account_number = Y.submission_vote_account_number WHERE submission_votes.submission_vote_content = 1 GROUP BY submission_votes.submission_vote_submission_number ORDER BY recommendation_subtotal DESC; "; which gives the following result: (it doesn't use SELECT DISTINCT submission_vote_account_number but I'm fine with this because the above code gives more weighting to accounts that have more in common with the user). Out of curiosity I have an academic question.... .... if I comment out the group by statement in the penultimate line: $query_recommendations=" SELECT submission_votes.submission_vote_submission_number, COUNT(*) as recommendation_subtotal FROM submission_votes INNER JOIN ( SELECT submission_vote_account_number, submission_votes.submission_vote_submission_number FROM submission_votes INNER JOIN ( SELECT submission_vote_submission_number FROM submission_votes WHERE (submission_vote_account_number = 1200 AND submission_vote_content = 1) ) as X ON submission_votes.submission_vote_submission_number = X.submission_vote_submission_number WHERE (submission_votes.submission_vote_account_number <> 1200 AND submission_votes.submission_vote_content = 1) ) as Y ON submission_votes.submission_vote_account_number = Y.submission_vote_account_number WHERE submission_votes.submission_vote_content = 1 # GROUP BY submission_votes.submission_vote_submission_number ORDER BY recommendation_subtotal DESC; "; Then I get the following result: Why do I only get 1 row of data but a subtotal count of 9? Thanks, Stu
  21. Hello, Please could someone tell me how to apply synoyms to a search? For example a job search for "airline pilot" should also return jobs adverts for "first officer", "second officer" and "captain". I guess such a system would need prepopulating with millions of relationships, is there somewhere I can get such a file? Thanks, Stu
  22. Sorry I'm back I tried this code from the other thread but the result isn't quite right: $query_recommendations=" SELECT submission_vote_submission_number, COUNT(*) as recommendation_subtotal FROM submission_votes INNER JOIN ( SELECT submission_vote_account_number FROM submission_votes INNER JOIN ( SELECT submission_vote_submission_number FROM submission_votes WHERE submission_vote_account_number = 1209 ) as X ON submission_votes.submission_vote_submission_number = X.submission_vote_submission_number WHERE submission_vote_account_number <> 1209 ) as Y ON submission_votes.submission_vote_account_number = Y.submission_vote_account_number GROUP BY submission_vote_submission_number ORDER BY recommendation_subtotal DESC; "; I assume the 2 lines below that I edited are horribly wrong? as X ON submission_votes.submission_vote_submission_number = X.submission_vote_submission_number as Y ON submission_votes.submission_vote_account_number = Y.submission_vote_account_number (It returned the following result arrays. The submission_vote_submission_number values are wrong and the count is just returning the number of records?): Array ( [0] => 1070 [submission_vote_submission_number] => 1070 [1] => 7 [recommendation_subtotal] => 7 ) Array ( [0] => 1071 [submission_vote_submission_number] => 1071 [1] => 7 [recommendation_subtotal] => 7 ) Array ( [0] => 1072 [submission_vote_submission_number] => 1072 [1] => 7 [recommendation_subtotal] => 7 ) Array ( [0] => 1073 [submission_vote_submission_number] => 1073 [1] => 7 [recommendation_subtotal] => 7 ) Array ( [0] => 1074 [submission_vote_submission_number] => 1074 [1] => 7 [recommendation_subtotal] => 7 ) Array ( [0] => 1075 [submission_vote_submission_number] => 1075 [1] => 7 [recommendation_subtotal] => 7 ) Thanks, Stu
  23. Ok thank you, I'll yield and use single votes for each submission/user combination. I've added the missing quotes incase someone googles this: INSERT INTO submission_votes SET userid = '$userid', submissionid = '$submissionid', content = '$likeOrNot' ON DUPLICATE KEY UPDATE content = '$likeOrNot' I'll try steps 2-4 tomorrow. Thank you :-) Stu
  24. I give up, I've spent 3 hours on step 2 but I can't do it. I would post my workings but I don't want to confuse people. Does anyone understand what I'm trying to do?
  25. Thank you - I have step 1 (find all the submissions that I like) working. I just needed to add submission_vote_timestamp into the first line and " AND (submission_vote_content = '1')" into the 2nd line: SELECT submission_vote_submission_number, submission_vote_timestamp FROM `submission_votes` WHERE ((submission_vote_account_number = '$_SESSION_account_number') AND (submission_vote_content = '1')) GROUP BY `submission_vote_submission_number` HAVING `submission_vote_timestamp`= MAX(`submission_vote_timestamp`) Now for step 2: "find all the users who like at least 1 submission that I like"....
×
×
  • 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.