Results 1 to 16 of 16
  1. #1
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    I am trying to get this to work but for some reason, it's not doing what I want it to do...say if the row contains text in that particular column searched, I want it to print out the text, but if it's blank, then to dish out 'not applicable'...it's for a jewelry feed...so I'm trying to get it to print out the 'Stone' if it's present, but to print out 'not applicable' if that is blank...what I'm getting is that it prints out the first section regardless...so I get the output all the time as :

    Stone :

    This is the script :

    if ($Stone<>' ')
    echo "Stone : ".$Stone."</p>";
    elseif ($Stone ==' ')
    echo "Stone : Not applicable</p>";

    Oscar
    My DataFeed Scripts - php datafeed scripts for your site
    Shareasale datafeed scripts - to display Shareasale datafeeds
    Linkshare datafeed scripts - for multiple Linkshare merchants

  2. #2
    ABW Ambassador Doug247's Avatar
    Join Date
    January 18th, 2005
    Location
    DE USA
    Posts
    931
    Just off the top your missing the {} in your if statment.

    Try this:

    if ($Stone<>' '){
    echo "Stone : ".$Stone."</p>";
    elseif ($Stone ==' ')
    echo "Stone : Not applicable</p>";
    }

    Hope this helps, I am kinda new to PHP but learning fast.

    Doug
    Thanks,
    Doug

  3. #3
    Full Member
    Join Date
    January 18th, 2005
    Posts
    379
    The if and else statements need their own brackets. You may alo want to use an 'else' instead of an 'elseif'.

    if ($Stone<>' '){
    echo "Stone : ".$Stone."</p>";
    }elseif ($Stone ==' '){
    echo "Stone : Not applicable</p>";
    }

  4. #4
    ABW Ambassador Doug247's Avatar
    Join Date
    January 18th, 2005
    Location
    DE USA
    Posts
    931
    I kinda though that too but wasn't too sure. Like aI said I am still learning my self but I knew brackets were missing.
    Thanks,
    Doug

  5. #5
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    Ahhh....thanks...yes learning php is kinda fun, it's powerful stuff - but as with all coding, it can get frustrating and when you keep getting that parse error coming up, it's like 'ARGGHHHH!'

    Oscar
    My DataFeed Scripts - php datafeed scripts for your site
    Shareasale datafeed scripts - to display Shareasale datafeeds
    Linkshare datafeed scripts - for multiple Linkshare merchants

  6. #6
    Full Member
    Join Date
    January 18th, 2005
    Posts
    362
    my favorite parse errors are forgetting the ; at the end or something pertaining to concatenation depending if I'm using accumulation or echo

    Did the brackets fix it? I sometimes have problems with NULL or empty values and using = or == which I still haven't figured out completely so I just try every combination until something works. (I know what = and == are.. detecting the empty value is the part which doesn't work 100% of the time)

  7. #7
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    ÄúsTrálíĺ
    Posts
    1,372
    if (!empty($Stone)){

    echo "Stone : ".$Stone."</p>";

    } else {

    echo "Stone : Not applicable</p>";

    }

  8. #8
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    Me learning too.

    Pete: Does that mean look for $stone, if variable is not null, display it and if null display Not applicable?

  9. #9
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    O Pete - you're the guru! The brackets didn't quite fix it...and the elseif had to go in if I was going to put in the conditional clause but it would work if I took it out (ie use the else only like what Pete's got)...

    Pete's solution was way simpler and I would've used it if I had read this earlier but this seemed to work too...

    if (!$Stone){
    echo "Stone : Not applicable"</p>";
    }elseif ($Stone <>' '){
    echo "Stone : ".$Stone."</p>";
    }

    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Pete: Does that mean look for $stone, if variable is not null, display it and if null display Not applicable?
    <HR></BLOCKQUOTE>

    I think I can answer that...yes...what Pete's done and what I was trying to do was to do a query and if there's nothing in that particular string column ie in this case no stone specified in that column (blank) then to return the text 'Not applicable' but if there's something there then to print out the relevant stone.

    Oscar
    My DataFeed Scripts - php datafeed scripts for your site
    Shareasale datafeed scripts - to display Shareasale datafeeds
    Linkshare datafeed scripts - for multiple Linkshare merchants

  10. #10
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    ÄúsTrálíĺ
    Posts
    1,372
    Yes.

    This may not be 'technically' correct, but it works for me.

    You can use

    if (!$Stone) {
    if (!isset($Stone)) {
    if (!empty($Stone)) {

    I'm sure there are differences between the above which the hardcore PHP'ers will no doubt pick me up on, but they should all work.

    My preference is for the following. IMO it makes it easier to read 6 months down the track.

    if (empty($Stone)) {

    echo "Not applicable";

    } else {

    echo $Stone;

    }

    Also, != is the preferred method of "Not equal to", not &lt;&gt; (although I do remember using &lt;&gt; back in the C64 days)


    [added]
    From http://www.php.net/empty .
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>empty() returns FALSE if var has a non-empty and non-zero value. In otherwords, "", 0, "0", NULL, FALSE, array(), var $var;, and objects with empty properties, are all considered empty. TRUE is returned if var is empty. <HR></BLOCKQUOTE>
    So there are differences between ISSET and EMPTY. Make sure you choose the correct one you need. (ie, if a 0 result should return as 0 or as empty)

  11. #11
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    Does anyone use:

    $_REQUEST["stone"]

    I think this looks for $stone in the URL as opposed to just leaving it simply as $stone. I ran into this problem when looking for an URL variable but it was also in the cookie, had to differentiate the two.

  12. #12
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    ÄúsTrálíĺ
    Posts
    1,372
    You definition of $_request is incorrect. (see http://www.php.net/variables.predefined )

    You should specify if you want $_GET['stone'] or $_COOKIE['stone'] to get the different values.

  13. #13
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    Thanks Pete.

    Still not 100% on this, sorry buddy, I am not good with codes. So...

    $_COOKIE['stone'] (retrieves cookies value)

    $_request retrieves anything via url or cookie?

    And what is $_GET

    TIA Pete!

  14. #14
    ABW Ambassador FFoc's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,015
    The $_GET global variable specifically looks for items passed using the GET method, either through a form using method="GET" or passing using url encoding directly (page.php?var=value).

    The $_POST global variable looks for values passed via the &lt;form method="POST"&gt; mechanism.

    $_COOKIE via cookies.

    $_REQUEST looks in all three spots, GET, POST, and COOKIE.
    “An adventure is an inconvenience rightly considered. An inconvenience is an adventure wrongly considered.” - G.K. Chesterton

  15. #15
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by FFoc:
    $_REQUEST looks in all three spots, GET, POST, and COOKIE. <HR></BLOCKQUOTE>
    ahh I see! That make sense. So it would be a bad idea to use $_REQUEST just in case a cookie varible and an URL variable are identical. This would "break" the system. Am I right in thinking this?

  16. #16
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    ÄúsTrálíĺ
    Posts
    1,372
    <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by Ian @ eyiproducts.com:
    So it would be a bad idea to use $_REQUEST just in case a cookie varible and an URL variable are identical. <HR></BLOCKQUOTE>
    There is an order you can select to determine which method has priority.

    I would think it would be more of a security problem. Imagine you are looking for a $_COOKIE value. All someone has to do is append that value to the cookie name as a $_GET variable, and it's passed.

  17. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Need Someone to Customize a PHP Script for Me
    By bandi in forum Midnight Cafe'
    Replies: 1
    Last Post: July 30th, 2010, 07:09 PM
  2. PHP Menu Script
    By John Powell in forum Programming / Datafeeds / Tools
    Replies: 7
    Last Post: January 4th, 2006, 03:39 PM
  3. Need help with PHP Script..
    By triumph in forum Midnight Cafe'
    Replies: 6
    Last Post: August 25th, 2005, 08:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •