Jump to content

Drongo_III

Members
  • Posts

    579
  • Joined

  • Last visited

Posts posted by Drongo_III

  1. 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");
    

     

    But first, store your dates in a format that can be sorted

  2. 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
        )
    
    )
    
    

  3. Try:

     

    $list .= implode('; ', $row['email']);

     

    I am trying to create a mailing list, with the email addresses being pulled from the dB. I have this:

    $emails = array($row['email']);
    $list .= implode('; ', $emails);
    

     

    Which returns all of the values from the dB, but it is not creating the "; " (semicolon and space) between each email address.

  4. 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.

     

     

     

    I have setup the connection in a seperate file (tested it is working) with the following code:

     

    function MySQLDB(){
    /* Make connection to database */
    $this->connection = new mysqli( DB_SERVER, DB_USER, DB_PASS, DB_NAME) or die ('Cannot open database');
    //mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
    // mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
    

     

    So when I changed my code in my index file to

     

    $session->connection;
    $result = $connection->query($sql);
    While ($row = $result->fetch_array(MYSQLI_BOTH)){
    
    echo "<li class=\"clear\">";
    if ($img = $row['image'] != ""){
    echo "<div class\"imgl\"><img src=\".$img.\" alt=\"\"/></div>";
    }
    echo "<div class=\"latestnews\">".
    "<p><a href=\"news.php?id=".$row['id'].">".$row['title']."</a></p><p>".$row['content']."</p></div>";
    }
    $connection->close();
    

     

    Im sure my issue is when trying to use $connection as my database connector im just not sure why/what I am doing wrong?

  5. 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

     

     

     

    Please assist me with this form. I want to send the email to me when the client hits the send button on www.themogulwaltononthames.com/contacts.html

    Where on this script should i place my email so that i can receive the form.

     

    Here is the java script im using:

     

     

    //forms

    ;(function($){

    $.fn.forms=function(o){

    return this.each(function(){

    var th=$(this)

    ,_=th.data('forms')||{

    errorCl:'error',

    emptyCl:'empty',

    invalidCl:'invalid',

    notRequiredCl:'notRequired',

    successCl:'success',

    successShow:'4000',

    mailHandlerURL:'bat/MailHandler.php',

    ownerEmail:'support@template-help.com',

    stripHTML:true,

    smtpMailServer:'localhost',

    targets:'input,textarea',

    controls:'a[data-type=reset],a[data-type=submit]',

    validate:true,

    rx:{

    ".name":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},

    ".state":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},

    ".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},

    ".phone":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},

    ".fax":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},

    ".message":{rx:/.{20}/,target:'textarea'}

    },

    preFu:function(){

    _.labels.each(function(){

    var label=$(this),

    inp=$(_.targets,this),

    defVal=inp.val(),

    trueVal=(function(){

    var tmp=inp.is('input')?(tmp=label.html().match(/value=['"](.+?)['"].+/),!!tmp&&!!tmp[1]&&tmp[1]):inp.html()

    return defVal==''?defVal:tmp

    })()

    trueVal!=defVal

    &&inp.val(defVal=trueVal||defVal)

    label.data({defVal:defVal})

    inp

    .bind('focus',function(){

    inp.val()==defVal

    &&(inp.val(''),_.hideEmptyFu(label),label.removeClass(_.invalidCl))

    })

    .bind('blur',function(){

    _.validateFu(label)

    if(_.isEmpty(label))

    inp.val(defVal)

    ,_.hideErrorFu(label.removeClass(_.invalidCl))

    })

    .bind('keyup',function(){

    label.hasClass(_.invalidCl)

    &&_.validateFu(label)

    })

    label.find('.'+_.errorCl+',.'+_.emptyCl).css({display:'block'}).hide()

    })

    _.success=$('.'+_.successCl,_.form).hide()

    },

    isRequired:function(el){

    return !el.hasClass(_.notRequiredCl)

    },

    isValid:function(el){

    var ret=true

    $.each(_.rx,function(k,d){

    if(el.is(k))

    ret=d.rx.test(el.find(d.target).val())

    })

    return ret

    },

    isEmpty:function(el){

    var tmp

    return (tmp=el.find(_.targets).val())==''||tmp==el.data('defVal')

    },

    validateFu:function(el){

    el.each(function(){

    var th=$(this)

    ,req=_.isRequired(th)

    ,empty=_.isEmpty(th)

    ,valid=_.isValid(th)

     

    if(empty&&req)

    _.showEmptyFu(th.addClass(_.invalidCl))

    else

    _.hideEmptyFu(th.removeClass(_.invalidCl))

     

    if(!empty)

    if(valid)

    _.hideErrorFu(th.removeClass(_.invalidCl))

    else

    _.showErrorFu(th.addClass(_.invalidCl))

    })

    },

    getValFromLabel:function(label){

    var val=$('input,textarea',label).val()

    ,defVal=label.data('defVal')

    return label.length?val==defVal?'nope':val:'nope'

    }

    ,submitFu:function(){

    _.validateFu(_.labels)

    if(!_.form.has('.'+_.invalidCl).length)

    $.ajax({

    type: "POST",

    url:_.mailHandlerURL,

    data:{

    name:_.getValFromLabel($('.name',_.form)),

    email:_.getValFromLabel($('.email',_.form)),

    phone:_.getValFromLabel($('.phone',_.form)),

    fax:_.getValFromLabel($('.fax',_.form)),

    state:_.getValFromLabel($('.state',_.form)),

    message:_.getValFromLabel($('.message',_.form)),

    owner_email:_.ownerEmail,

    stripHTML:_.stripHTML

    },

    success: function(){

    _.showFu()

    }

    })

    },

    showFu:function(){

    _.success.slideDown(function(){

    setTimeout(function(){

    _.success.slideUp()

    _.form.trigger('reset')

    },_.successShow)

    })

    },

    controlsFu:function(){

    $(_.controls,_.form).each(function(){

    var th=$(this)

    th

    .bind('click',function(){

    _.form.trigger(th.data('type'))

    return false

    })

    })

    },

    showErrorFu:function(label){

    label.find('.'+_.errorCl).slideDown()

    },

    hideErrorFu:function(label){

    label.find('.'+_.errorCl).slideUp()

    },

    showEmptyFu:function(label){

    label.find('.'+_.emptyCl).slideDown()

    _.hideErrorFu(label)

    },

    hideEmptyFu:function(label){

    label.find('.'+_.emptyCl).slideUp()

    },

    init:function(){

    _.form=_.me

    _.labels=$('label',_.form)

     

    _.preFu()

     

    _.controlsFu()

     

    _.form

    .bind('submit',function(){

    if(_.validate)

    _.submitFu()

    else

    _.form[0].submit()

    return false

    })

    .bind('reset',function(){

    _.labels.removeClass(_.invalidCl)

    _.labels.each(function(){

    var th=$(this)

    _.hideErrorFu(th)

    _.hideEmptyFu(th)

    })

    })

    _.form.trigger('reset')

    }

    }

    _.me||_.init(_.me=th.data({forms:_}))

    typeof o=='object'

    &&$.extend(_,o)

    })

    }

    })(jQuery)

    ---------------------------------------------------------------

    Im also using a form mail handlers PHP script:

    ----------------------------------------------------------------------------

     

     

    <?php

    $owner_email = $_POST["owner_email"];

    $headers = 'From:' . $_POST["email"];

    $subject = 'A message from your site visitor ' . $_POST["name"];

    $messageBody = "";

     

    if($_POST['name']!='nope'){

    $messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }

    if($_POST['email']!='nope'){

    $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }else{

    $headers = '';

    }

    if($_POST['state']!='nope'){

    $messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }

    if($_POST['phone']!='nope'){

    $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }

    if($_POST['fax']!='nope'){

    $messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";

    $messageBody .= '<br>' . "\n";

    }

    if($_POST['message']!='nope'){

    $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";

    }

     

    if($_POST["stripHTML"] == 'true'){

    $messageBody = strip_tags($messageBody);

    }

     

    try{

    if(!mail($owner_email, $subject, $messageBody, $headers)){

    throw new Exception('mail failed');

    }else{

    echo 'mail sent';

    }

    }catch(Exception $e){

    echo $e->getMessage() ."\n";

    }

    ?>

  6. 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?

     

    Hey there im trying to change my website from mysql statments to mysqli. I tried changing one of my simple statments to get some news from the db and im running into the following error:

     

     

     

    Here is the code I am using, does anyone know what/why the error is producing:

     

    $sql = "SELECT * FROM news ORDER by id DESC LIMIT 2,0";
    $result = $mysqli->query($sql);
    While ($row = $result->fetch_array(MYSQLI_BOTH)){
    
    echo "<li class=\"clear\">";
    if ($img = $row['image'] != ""){
    echo "<div class\"imgl\"><img src=\".$img.\" alt=\"\"/></div>";
    }
    echo "<div class=\"latestnews\">".
    "<p><a href=\"news.php?id=".$row['id'].">".$row['title']."</a></p><p>".$row['content']."</p></div>";
    }
    
    

  7. 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

     

     

     

     

    try

     

    SELECT jobs.job_number, jobs.brand, jobs.description,
    CASE WHEN jobs.request_other <> 0 THEN req.email ELSE users.email END as email
    FROM jobs
    INNER JOIN users on jobs.user_id = users.id
    LEFT JOIN users as req ON jobs.request_other = req.id
    WHERE jobs.status !='live'
    ORDER BY jobs.brand ASC, jobs.date_created DESC

     

    or you could replace the CASE...END with

     

    IFNULL(req.email, users.email) as email

  8. 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!

  9. 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"); ?>

     

    Hi, I am following a tutorial on Youtube and I am trying to construct a php menu that will be a single php file that will be inserted as a header on all my pages. I have created the index.php file and a header.inc.php file (for the header script), and when I insert the "include" code to grab the header and display it, it doesn't show.

    (yes, my file is misspelled --headder instead of header, so that shouldn't be an issue)

     

    Here is my indiex.php code:

     

    <?include("inc/incfiles/headder.inc.php"); ?>

    <body>

    </html>

    <table class="homepageTable">

    <tr>

    <td width="60%" valign="top">

    <h2>Join friendbook today!</h2>

    <img src="img/social_image.jpg" width="400">

    </td>

    <td width="40%" valign="top">

    <h2>Sign Up Below</h2>

    <form action="#" method="post">

    <input type="text" size="25" name="fname" placeholder="First Name">

    <input type="text" size="25" name="lname" placeholder="Last Name">

    <input type="text" size="25" name="Username" placeholder="User Name">

    <input type="text" size="25" name="email" placeholder="Email">

    <input type="text" size="25" name="email2" placeholder="Repeat Email">

    <input type="text" size="25" name="password" placeholder="Password">

    <input type="text" size="25" name="password2" placeholder="Repeat Password">

    <input type="submit" name="submit" value="Sign Up!">

    </form>

    </td>

    </tr>

    </table>

    </body>

    </html>

     

    and here is my "header.inc.php" script that I want to display (I am directing the index.php to grab this code and use it for a common header:

     

    <head>

    <link href="css/main.css" rel="stylesheet" type="text/css">

    <title>friendsBook - A New social network</title>

    <head>

    <body>

    <div class="headerMenu">

    <div id="wrapper">

    <div class="logo">

    <img src="img/logo.png">

    </div>

    <div class="search_box">

    <form method="GET" action="search.php" id="search">

    <input name="q" type="text" size="60" placeholder="search ..." />

    </form>

    </div>

    <div id="menu">

    <a href="#">Home</a>

    <a href="#">About</a>

    <a href="#">Sign Up</a>

    <a href="#">Login</a>

    </div>

    </div>

    </div>

    <br />

    <br />

    <br />

    <br />

     

     

     

    Any help would help me from pulling out my hair at this point.

     

    Jimmy

  10. 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

  11. 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.

  12. 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.

     

     

    Hi,

     

    First of all, thanks for creating this site, lots of wonderful information here :)

     

    Im totally new to PHP, and im trying to implement a little php script in a new website im building.

     

    Basicly i have a table:

     

     

     

     

    When i click on a certain page, say Page 1, i wan't Page 1 to be underline and the rest of the links not.

     

    Im really lost as how i would code this in PHP, but i figure it would go something like this:

     

     

     

     

     

    This obviously dosen't work, i need a "little" help here.

  13. 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.

  14. 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>
    

  15. 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);
    

     

     

    Hi Guys

     

    Having my first unsuccessful trip into the world of facebook graph api (oh how i hate facebook).

     

    All I want to do is retrieve the facebook wall posts for a specified user.

     

    I created an app to get an access token and secret that part appears to be working as no errors are being returned.

     

    However when i try to pull the feed using the following line of code I get only the user ID back and nothing else:

     

    $json_str = file_get_contents('https://graph.facebook.com/100005065530030?fields=feed&access_token='.$access_token);
    

     

    If I replace ''feed' with 'name' I get the name so it's clearly working on one level.

     

    As I am woefully unfamiliar with facebook api I would very much appreciate if someone could give me a clue as to why this might be happening?

     

    Thanks,

     

    Drongo

  16. 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 .

  17. Hi guys

     

    Building a new application that is likely to grow in complexity over time. I therefore figured it would be perhaps wise to follow some mvc principles.

     

    The thing I am confused about is the how best to setup a mysqli db con I can reuse througout my models.

     

    Options one - have a base db class and pass in the object to the constructor of each model - thereby utilising one connection.

     

    option two - for each model setup new db connection but pass db credentials as constants via config file.

     

    or I am sure someone will recommend a better option yet. Any advice is welcome.

     

     

  18. Hi Guys

     

    Having my first unsuccessful trip into the world of facebook graph api (oh how i hate facebook).

     

    All I want to do is retrieve the facebook wall posts for a specified user.

     

    I created an app to get an access token and secret that part appears to be working as no errors are being returned.

     

    However when i try to pull the feed using the following line of code I get only the user ID back and nothing else:

     

    $json_str = file_get_contents('https://graph.facebook.com/100005065530030?fields=feed&access_token='.$access_token);
    

     

    If I replace ''feed' with 'name' I get the name so it's clearly working on one level.

     

    As I am woefully unfamiliar with facebook api I would very much appreciate if someone could give me a clue as to why this might be happening?

     

    Thanks,

     

    Drongo

  19. Hello

     

    Not entirely sure if this post should reside here but here goes...

     

    All I want to do is get a particular facebook page's public posts and display them on my website. Twitter does this easy enough by just requesting some xml - but facebook seems very complicated, mostly because most guides are outdated and I am not at all familiar with oAuth.

     

    I've tried to the following:

     

    https://graph.facebook.com/<page_id>/feed
    

     

    But this returns an error saying I need an acess token. This is where I am confused. Does anyone know preciesly what kind of access token I would need to achieve my simple task? And do I simply create this in the apps section of facebook?

     

    It would be very much appreciated if someone could point me in the right direction as I have a client breathing down my neck and no time to delve deeply into the fb documentation at this stage :/

     

    Drongo

  20. Hi Crystal

     

    Something like this should point you in the right direction:

     

     

    
    <script>
    
       function removeText(){
    
           var textArea = document.getElementById("text");
           if(textArea.value == 'Please add your comment'){
           textArea.value = '';
           }
    
       }
    </script>
    
    
    <form>
    
    <textarea id="text" onfocus="removeText();">Please add your comment</textarea>
    
    </form>
    

     

    The onfocus event is useful for form elements. When the user clicks into the field (making it the focus) then the function will fire.

     

    Hope that helps.

     

    Drongo

     

     

     

    I'm creating a form and I don't know much javascript but I have a value that displays in a textbook before the user enters anything and I would like to clear the textbook on click but I was wondering if I could set it to only be cleared on the first click or something like that because if the user enters a value and accidentally clicks again I don't want that value to be cleared.

     

    Thanks,

     

    -Crystal.

  21. Thanks Christian

     

    As long as I know this is normal behaviour.

     

    Incidentally is 'bubble up' the technical term ;)

     

    Drongo

     

    Events bubble up the layers, so when you click on a child element the click will bubble up unless prevented.

  22. Yes but in the example if I click the div with ID '#popUp' the click function fires.

     

    But if I click the 'close' link, the click function also fires. This is the bit I don't understand. surely the click function should only fire when you click the div and not the link?

     

    You confuse me. Or maybe I confuse myself. :sweat: If you mean it is only supposed to work for the div id of popUp then yes.

  23. Hi

     

    Is there supposed to be an attachment? You seem to be referring to something...

     

    Anyway you could probably achieve this by simply setting the checkbox and then in your php code do a check for it, e.g.

     

    $to  = 'aidan@example.com' . ', '; // note the comma
    if(isset($_POST['ccEmail'])){
    $to .= $_POST['userEmail'];
    
    

     

    Obviously you wouldn't directly use post variables in your code without validating and sanitising them but you get the idea. At least I think this is what you're after.

     

    Alternatively you could substitute the $to for a Bcc with an extra header:

     

    $headers .= 'Bcc: $_POST['userEMAIL'] . "\r\n";
    

     

    All mail functions are explained here: http://php.net/manual/en/function.mail.php

×
×
  • 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.