SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot m0h's Avatar
    Join Date
    Sep 2001
    Location
    Cairo, Egypt
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Print it only if it has a value!

    I got :
    PHP Code:
    $str "VAL1=$val1&VAL2=$val2&VAL3=$val3&VAL4=$val4"
    what i want to do is to print VAL 1,2,3,4 only if they got a value (not = to "" or "0").

    So if only VAL1 and VAL3 got a value it prints

    PHP Code:
    $str "VAL1=$val1&VAL3=$val3"
    I know that this is done using IF but I'm not sure how!

  2. #2
    SitePoint Zealot sonique's Avatar
    Join Date
    Sep 2001
    Location
    Missouri [U.S.]
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and if they are not filled.....what effect would you like?
    jmulder[THE MENTOR]'s nice guy online!
    Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW

  3. #3
    SitePoint Zealot m0h's Avatar
    Join Date
    Sep 2001
    Location
    Cairo, Egypt
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing, Not added to "$str" only the ones with a value should be added to "$str".

  4. #4
    SitePoint Zealot m0h's Avatar
    Join Date
    Sep 2001
    Location
    Cairo, Egypt
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So if
    PHP Code:
    $val1 "25";
    $val2 "";
    $val3 "50";
    $val4 ""
    $str will be like this:
    PHP Code:
    $str "VAL1=25&VAL3=50"
    not
    PHP Code:
    $str "VAL1=25&VAL2=&VAL3=50&VAL4="
    Got me now? or still confused ?

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there might be a better way but do something like

    PHP Code:

    if ($val1 != "0" && $val1 != "") {
     
    $str "&VAL1=$val1";
    }

    if (
    $val2 != "0" && $val2 != "") {
     
    $str . = "&VAL2=$val2";

    etc...

    then you need to remove the first character to get rid of that extra & but can't remember what function that is.

  6. #6
    SitePoint Zealot m0h's Avatar
    Join Date
    Sep 2001
    Location
    Cairo, Egypt
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by padders

    then you need to remove the first character to get rid of that extra & but can't remember what function that is.
    What?

    How can I do that!

  7. #7
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by m0h
    How can I do that!
    This is one way:

    PHP Code:
    $str ereg_replace("^&"""$str); 
    This is another:

    PHP Code:
    $str substr($str1); 
    The first will remove & from the beginning of the string. The second will return the string minus the first character

    Sean
    Last edited by seanf; Oct 7, 2001 at 09:54.
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  8. #8
    SitePoint Zealot m0h's Avatar
    Join Date
    Sep 2001
    Location
    Cairo, Egypt
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    :0)

    Thanx alot both of you!



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
  •