Jump to content

Drongo_III

Members
  • Posts

    579
  • Joined

  • Last visited

Everything posted by Drongo_III

  1. Lachild thank you so much for your response. That fixed it all and now works perfectly. I'm now very happy As you've highlighted the mime type to me the penny kind of drops. So I guess 'multipart/related' might be used for things like attachments? Christian - thanks for the tip. To be honest I was just working from examples on php.net which isn't overly expansive but I guess I'm looking in the wrong place for descriptive info on this. I shall check out RFC article.
  2. This is probably going to centre around two main functions. Firstly file_get_contents (http://www.php.net/manual/en/function.file-get-contents.php) to grab the page data. You can enter a url as the file name. Then you'll want to break out your regular expressions and use a function such as preg match (http://php.net/manual/en/function.preg-match.php). This returns an array of matches.
  3. Hi Guys I am trying to setup an email template that contains both a html and plain text version in one. What follows is a simplified version but what I want to do is simply have both versions in an email template and then run a str_replace which will populate the template's place holders with the relevant data before sending - this is why I want everything in a single file. But before I get to that point I simply need to get the email working - however at present when I run the code below I just get blank output in the email body. If anyone could propose a reason why this is happening it would be appreciated. Incidentally I realise the mime boundary isn't ideal - this is just for testing. <?php $headers = "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/related; boundary=\"boundaryMarker\"\n"; $headers .= "Content-Transfer-Encoding: 7bit\n"; $body = " --boundaryMarker\n Content-Type: text/plain; charset=\"charset=us-ascii\" \n Content-Transfer-Encoding: 7bit\n\n THIS IS PLAIN TEXT EMAIL \n\n --boundaryMarker\n \n\n Content-Type: text/html; charset=ISO-8859-1\n Content-Transfer-Encoding: 7bit\n\n <h1>THIS IS HTML VERSION</h1> \n\n --boundaryMarker--\n "; $to = 'MyEmail@Myemail.com'; $subject = 'This is a test message'; mail($to, $subject, $body, $headers);
  4. Hi Kick Sorry it has taken a while to respond to this. Lets assume that this isn't possible to setup - because I have very limited control over the hardware in this instance. As a way of doing it via php would perhaps ftping the files via php's ftp functions be a possible solution? Any reasons you would advise not using this?
  5. Thanks Jessica You give me too much credit and I can't in fact see from the time stamps what the dates are... However you did give me cause to check what I was doing with the dates and it appears it wasn't the output that was the problem but there was some test code messing up the strtotime conversion earlier in the code. So thank you for prompting me to check that.
  6. Hi Guys Posted on here a few days ago about sorting a multi dimensional array based on date. I thought I had it working but now i realise it doesn't appear to be sorting correctly. Essentially I have an array that is combined from feeds from twitter and facebook. I converted the dates using strtotime and the unsorted array looks like this: print_r($socialMediaArray); ( [0] => Array ( [date] => 1359214851 [message] => some message [from] => twitter ) [1] => Array ( [date] => 1358991499 [message] => some message [from] => twitter ) [2] => Array ( [date] => 1358799273 [message] => some message [from] => twitter ) [3] => Array ( [date] => 1387741833 [message] => some message [from] => twitter ) [4] => Array ( [date] => 1387490401 [message] => some message [from] => twitter ) [5] => Array ( [date] => 1357263343 [message] => some message [from] => facebook ) ) I then ran the following code to try and sort on date order function cmp ($a, $B) { return $a['date'] - $b['date']; } usort($socialMediaArray, "cmp"); // Sort the array by date order. echo "SORTED ARRAY <pre>"; print_r($socialMediaArray); SORTED ARRAY Array ( [0] => Array ( [date] => 1357263343 [message] => some message [from] => facebook ) [1] => Array ( [date] => 1358799273 [message] => some message [from] => twitter ) [2] => Array ( [date] => 1358991499 [message] => some message [from] => twitter ) [3] => Array ( [date] => 1359214851 [message] => some message [from] => twitter ) [4] => Array ( [date] => 1387490401 [message] => some message [from] => twitter ) [5] => Array ( [date] => 1387741833 [message] => some message [from] => twitter ) ) But when I then convert the dates back into something readable it becomes apparent that the dates haven't been sorted correctly as they come out as Fri Jan 04 1:35:43 Mon Jan 21 20:14:33 Thu Jan 24 1:38:19 Sat Jan 26 15:40:51 Thu Dec 19 22:00:01 Thu Dec 19 22:00:01 I'm not overly familiar with using usort, hence why I posted here, so if someone could offer up a possible reason as to why this may be happening it would appreciated. Many thanks, Drongo
  7. Thanks very much guys that worked a treat. I was getting massively confused because I thought I have to pass $a and $b and I couldnt quite see how I would make that dynamic - over complicating it clearly!
  8. Two questions so I can get my tired grey matter around this: 1) I should convert the date values to unix time stamps? 2) in the example usort function on php manual ( copied below) what is $b? Is this a copy of the original array against which the value $a is compared? function cmp($a, $B) { if ($a == $B) { return 0; } return ($a < $B) ? -1 : 1; } $a = array(3, 2, 5, 6, 1); usort($a, "cmp");
  9. Hi Guys Bit confused on the best way to approach this so some advice would be welcome. I have a multidimensional array which is created from a twitter and facebook feed combined into a single array. I want to sort the array by date order but I'm not sure of the best way to do this. I have been looking at array_multisort but I can't see how you get that to work without specifying a precise index. An example of the array I am working with is as follows: print_r($socialMediaArray); Array ( [0] => Array ( [date] => Fri Jan 04 1:35:43 [Message] => Brilliant day last thursday - lets do it again [from] => facebook ) [1] => Array ( [date] => Sat Jan 26 15:40:51 [Message] => how do you like my new fb page? [from] => facebook ) [2] => Array ( [date] => Thu Jan 24 01:38:19 [Message] => Some test message from twitter [from] => twitter ) [3] => Array ( [date] => Mon Jan 21 20:14:33 [Message] => @tester here is a message just for you [from] => twitter ) [4] => Array ( [date] => Sun Dec 16 19:50:33 [Message] => some other message #test [from] => twitter ) )
  10. I think you need to post the full code but based on what I can see there you setup the connection on '$this->connection' so when you try to retrieve the result you should write it: $result = $this->connection->query($sql); Also in your index file trying using var_dump($this->connection); to see what you're getting.
  11. I've not read through the miles of code but at a glance if you wanted to get a copy of this email you would change the first line of your php script $owner_email = $_POST["owner_email"] . ", YOUREMAIL@DOMAIN.com"; Or if you don't want the user to see your email address has been added then add yourself as a BCC http://php.net/manual/en/function.mail.php
  12. Could be a silly question but you have formed the connection via mysqli to create an object? i.e. $mysqli = new mysqli("localhost", "user", "password", "database"); And are you sure the sql query is sound?
  13. I went with Barand's suggestion as it seemed more inline with the way I envisoned it working and it worked a treat. I confess I've only used very simple joins and I would like to understand mutilple joins better - I am a bit weak on my sql. So I'm hoping someone can answer a few questions on this... Firstly this line: CASE WHEN jobs.request_other <> 0 THEN req.email ELSE users.email END as email The only thing confusing me is the 'as email' bit at the end. Why do you give it the alias 'email'? It doesn't appear to be used anywhere else in the query so what's the purpose here? Also the req.email part. 'req' at this point in the query has no meaning so am I right in saying that it becomes meaningful when you alias it as 'uses as req' later in the query? And my last question is about how the query gets executed with mutliple joines like this. Is it the case that the Inner join statement will run first and retrieve all email results where and ID matches in both tables. Then the query gets re-run with the Left join statement and overwrites the email results whereever there is an id match resulting from 'jobs.request_other <> 0' in boht tables? Is that right? Many thanks for your patience, Drongo
  14. Thanks Guys Lots of very helpful suggestions there. I will give these a whirl tomorrow in work and see what fits best. I shall report back! Many thanks! Drongo
  15. Hello Very much stuck on this and it's held me up for a good few hours so help is much appreciated - i'll try and keep this brief. Essentially I have two tables - a 'users' table with cols for user id, email, name etc. and a 'jobs' table containing a lot of columns that I won't list but there are two that are relevant to this. The two columns are 'user_id' and 'request_other' - both of these are relational to the users table user id. There are two cols because the application stores data on the person adding the job (in user_id) and the person who requested it (in request_other). This latter field get set to '0' if the person adding the job is also the requester. So here's where I'm stuck. When I query the jobs table to populate some data in a page I need to get the email address, based on the user_id, from the users table. So I query the jobs table and perform an inner join as follows and all works well(stripped out most of the fields for the sake of clarity): SELECT jobs.job_number, jobs.brand, jobs.description, users.email FROM jobs INNER JOIN users on jobs.user_id = users.id WHERE jobs.status !='live' ORDER BY jobs.brand ASC, jobs.date_created DESC Here the join is done on the basis of a match between user_id in both tables. BUT what I really want is to conditionally alter the '...INNER JOIN users on' part of the query to say: "If request_other !=0 then use request_other = users.id ELSE use jobs.user_id = users.id" I dont know if that's possible or not? I've tried adding in cases and If statements but nothing seems to work as I am probably doing it wrong - despite a lot of trying :/ If anyone could suggest a means of achieving what I am after I would be eternally thankful!
  16. Umm out of interest. You are actually running this on a web server right? Not just from your local machine?
  17. Here are a few things to try and help you resolve the issue: 1) ensure error reporting is on - error_reporting(E_ALL); . This might give you a clue as to the issue. 2) Your include uses short tags, i.e. <? SOME PHP CODE ?> instead of full tag structure <?php SOME PHP CODE ?>- So try using full tags as depending your individual configuration short tags may not be enabled. <?include("inc/incfiles/headder.inc.php"); ?>
  18. Hello Wonder if someone can give some advice. I am working on quite a high volume website (800k+ hits per month) which operates on two load balanced servers. I'm creating an image upload page that will enable users to send images and some other details to backoffice staff. The upload facility will typically allow around 4-5 image uploads at once totalling between 2-10mb of images (need to be quite high res). The intention is to allow backoffice staff to access these images for their own business purposes. But the problem i foresee is that because the servers are load balanced the images will be uploaded to one or other of the servers. So if had the system simply generate a link to a zipped folder of images and email the link to backoffice staff they would end up not being able to access the images if the load balancer directs them to a server other than the one where the images were uploaded - phew! So I'm looking for some advice on the best approach in this scenario: a) setup some kind of sync between the servers - what would you suggest? b ) store the images in a database - guessing blob data ? The servers both share a mysql service so this seems reasonable. c) some other ingenious solution proposed by the all knowing people of php freaks Any advice is very welcome! Drongo
  19. Hi Mate As christian pointed out basename is needed - sry my bad i was typing it out a bit fast earlier. Your code to grab what is essentially the file name should look like this: $PageLink = basename($_SERVER['PHP_SELF']); Then the conditional for the link will look something like <a href="fysio.php" <?php if($PageLink == 'fysio.php'){ echo 'class="ClassToApplyUnderline"';} else {echo 'class="ClassThatDoesNotUseUnderline"';}?> >page1</a> A good practice if you need to test a variable that doesn't appear to be matching is to echo it out. So try doing echo $PageLink; This way you can see what basename(...) is giving you to work with and you can formulate your if statement from there. Hope that helps! [quote name=Togo' timestamp='1360361064' post=' 1411153] Yes, and that is exactly what i want the script to do. I want the link beeing clicked on underlined when the condition is met (beeing on the page the link refers too), and if not then don't underline it. My html table may be a mess, but it looks fine to me. I did try building it the way i assume you wan't to, but it didn't give me a different result. But this: Dosen't do a thing, and thats what im now trying to figure out why not.
  20. Hi Togo What follows is a very simplistic demonstration to get you kick started. You need to be able to grab the url. So if your site is www.mysite.com/page1.php you can do something along the lines of the following: $pageLink = $_SERVER['PHP_SELF']; This will populate a variable with whatever follows the base domain. So in the example of www.mysite.com/page1.php $pageLink will now be equal to "page1.php" You can then perform your if statement to find if you actually are on page1 <a href="page1.php" id="navLink" <?php if($pageLink == 'page1.php'){ echo 'class="UNDERLINE"'} ?> >page1</a> In reality you wouldn't really get by with something quite as simplistic as the above because the url structure would be more complicated but it should get you thinking in the right direction.
  21. There are probably lots of ways of acheiving this and if it does what you want then who is to argue? If you would prefer the page didn't refresh itself then you should look into ajax. Just do a google search on 'ajax php' and you will find lots of examples. Ajax uses javascript to get/post data asynchronously enabling data to be exchanged with the server in the background without need to to refresh the page. ajax looks a bit puzzling at first but once you break it down it's very straight forward. If you have any more questions on it after googling just shout.
  22. Hey mate Don't know if you're still working on this and what follows is a hidiously impractical solution but this might point you in the right direction. In this instance it hinges on you wrapping a span around the letter in question - which would probably mean you need to do some sort of str replace when you generate the document. Probably not worth it unless you only use the fonts sparingly - i.e. in a header. Hope thi shelps a bit! <html> <head> <style> span { display: inline-block; -webkit-transform:rotateY(180deg) !important; -moz-transform:rotateY(180deg) !important; -o-transform:rotateY(180deg) !important; -ms-transform:rotateY(180deg) !important; unicode-bidi:bidi-override !important; direction:rtl !important; } </style> </head> <body> <p> H<span>e</span>llo World</p> </body> </html>
  23. Hi Guys I worked this out in the end and I learned two things - firstly that most tutorials for this online are outdated, and secondly that facebook is the single largest sack of horse s%$t known to man with a 'war and peace' sized documentation that is mostly contradiction and dead ends. Anyway rant aside I thought I would post the solution that will hopefully help other facebook dev. noobies like me work it out. The very first step is to setup an app. For this you need to have a normal facebook profile and not a page account. IF you register just with a page style account facebook will still let you register as a developer, it will still let you enter your telephone number but once you get to the app section it will not give you the 'create app' button that you need - but facebook wont tell you that! And then you'll try to register a normal profile account and it wont let you re-enter that telephone number to register as a dev again - haha yes it's true! One you've visited the dev section of facebook and registered there (you need to enter your telephone number and they text you a code) then click 'create app'. Once you create the app you will get an 'App ID' and 'App Secret' - two long strings. Note those down and then use the script below to access the graph api: // First off you need to get an access token. This is done by sending a HTTP request to facebook. Facebook responds with a $_GET variable named $access_token . You can access this by parsing the $appToken result. $appToken = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=APP_ID_GOES_HERE&client_secret=APP_SECRETE_GOES_HERE&grant_type=client_credentials'); // Use this function to retrieve the $_GET var. The variable name, as sent by FB, is called $access_token parse_str($appToken); //Now we've retrieved the access token we can make a call to the graph api for user data. In this instance we request id, name, feed. Requesting 'feed' retrieves status updates. It gets returned as Json $json_str = file_get_contents('https://graph.facebook.com/USER_PAGE_ID_GOES_HERE?fields=id,name,feed&access_token='.$access_token); //Decobe the json str which gives an array and then go nuts $data = json_decode($json_str); //var_dump($data); //print_r($data);
  24. Thanks Christian - as ever. I think I need to spend some time learning about building a class to inject the right resource based on requirement - altho that's quite a BIG topic to get to grips with. At least I am vaguely on the right track by passing the db con via the model constructor so that's reassuring .
×
×
  • 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.