Professional Web Applications Themes

If statement question - PHP Development

Hi there, I have the following code: echo "\n <address>"; if ($entry_info[location] and $entry_info[location] != '') { echo "\n ".stripslashes($entry_info[location]).".,"; } if ($entry_info[address1] and $entry_info[address1] != '' ) { echo "\n ".stripslashes($entry_info[address1]); } if ($entry_info[address2] and $entry_info[address2] != '' ) { echo ','; echo "\n ".stripslashes($entry_info[address2]); } If the mysql database does not have the field populated I do not want the ., to appear in the address. What can I put to show not equal to any data in the database. Thanks in advance for your help. Smriti...

  1. #1

    Default If statement question

    Hi there,

    I have the following code:

    echo "\n <address>";
    if ($entry_info[location] and $entry_info[location] != '') {
    echo "\n ".stripslashes($entry_info[location]).".,";
    }
    if ($entry_info[address1] and $entry_info[address1] != '' ) {
    echo "\n ".stripslashes($entry_info[address1]);
    }
    if ($entry_info[address2] and $entry_info[address2] != '' ) {
    echo ',';
    echo "\n ".stripslashes($entry_info[address2]);
    }
    If the mysql database does not have the field populated I do not want the .,
    to appear in the address.
    What can I put to show not equal to any data in the database.

    Thanks in advance for your help.
    Smriti


    Smriti Dev Guest

  2. #2

    Default Re: If statement question

    "Smriti Dev" a écrit le 08/12/2003 : 

    Sorry I don't get your question... Maybe because it's late...
    You statement if ($entry_info[adress2]) is not very clear and clean,
    what do you want to test there? Do you mean isset()?

    --
    Have you read the manual?
    http://www.php.net/manual/en/

    Jedi121 Guest

  3. #3

    Default Re: If statement question


    On 8-Dec-2003, "Smriti Dev" <smriti.devutoronto.ca> wrote:
    > I have the following code:
    >
    > echo "\n <address>";
    > if ($entry_info[location] and $entry_info[location] != '') {
    > echo "\n ".stripslashes($entry_info[location]).".,";
    > }
    > if ($entry_info[address1] and $entry_info[address1] != '' ) {
    > echo "\n ".stripslashes($entry_info[address1]);
    > }
    > if ($entry_info[address2] and $entry_info[address2] != '' ) {
    > echo ',';
    > echo "\n ".stripslashes($entry_info[address2]);
    > }
    > If the mysql database does not have the field populated I do not want the
    > .,
    > to appear in the address.
    > What can I put to show not equal to any data in the database.
    If the location column is a CHAR, it is fixed length and the database will
    return that length of spaces. Comparing it to '' will not work. You could
    compare to ' ' (the appropriate number of spaces) or use trim() to
    remove the spaces.

    You should be coding quotes or apostrophies around your column names (unless
    you've defined them as constants or they are in a double quoted string), for
    example:
    if ($entry_info['location'] and trim($entry_info['location'])!='')

    --
    Tom Thackrey
    [url]www.creative-light.com[/url]
    tom (at) creative (dash) light (dot) com
    do NOT send email to [email]jamesbutlerwillglen.net[/email] (it's reserved for spammers)
    Tom Thackrey Guest

  4. #4

    Default Re: If statement question

    "Smriti Dev" <smriti.devutoronto.ca> wrote in message news:<HpLL36.AM6campus-news-reading.utoronto.ca>...
    > Hi there,
    >
    > I have the following code:
    >
    > echo "\n <address>";
    > if ($entry_info[location] and $entry_info[location] != '') {
    > echo "\n ".stripslashes($entry_info[location]).".,";
    > }
    > if ($entry_info[address1] and $entry_info[address1] != '' ) {
    > echo "\n ".stripslashes($entry_info[address1]);
    > }
    > if ($entry_info[address2] and $entry_info[address2] != '' ) {
    > echo ',';
    > echo "\n ".stripslashes($entry_info[address2]);
    > }
    > If the mysql database does not have the field populated I do not want the .,
    > to appear in the address.
    > What can I put to show not equal to any data in the database.
    >
    > Thanks in advance for your help.
    > Smriti

    Hi Smriti,

    I assume the location field in your database is string.

    There are two possibilities:-

    1. If you declare the field as *NULL-allowed field*

    You can check for NULL value with is_null($entry_info['location']) function

    2. If the field in database is declared as *NOT NULL field*
    You can check for empty string $entry_info['location'] ==""


    I think better way to do this checking is by merging these two conditions
    with a single statement:

    empty($entry_info['location'])

    It will return false only when your location field is populated and non empty.

    -- Rahul
    Rahul Anand Guest

Similar Threads

  1. Replies: 9
    Last Post: April 27th, 04:44 AM
  2. Simple If statement question
    By quovadimus02 in forum Macromedia ColdFusion
    Replies: 2
    Last Post: March 22nd, 06:37 PM
  3. real if then statement question.
    By aoninja webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 0
    Last Post: October 25th, 04:51 AM
  4. SQL statement question
    By Jason Reljac in forum PHP Development
    Replies: 2
    Last Post: July 20th, 06:06 AM
  5. Select Statement Question (Again)
    By Largo SQL Tools in forum Microsoft SQL / MS SQL Server
    Replies: 9
    Last Post: July 14th, 05:02 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139