Results 1 to 13 of 13

Thread: check for empty field

  1. #1
    Join Date
    Jul 2007
    Posts
    126

    Default check for empty field

    hi coders. i need to check if a field is empty and return result as either msg or $error_msg. here is the code:

    Code:
    $test = '';
       for($i = 0;$i < $result->RecordCount(); $i++){
       $file = $result->Fields("url");
       $date = $result->Fields("date");
       $messages = $result->Fields("messages");
       $test .= '<table width="100%%"  border="0">
      <tr>
        <td>Latest files and Messages</td>
      </tr>
    </table>
    
    <table cellpadding="2" cellspacing="1" border="0" align="center" width="100%" class="tbl_border_mem">
    <tr class="tbl_caption_mem">
      <td width="16%"><strong>Files</strong></td>
      <td width="13%"><strong>Date</strong></td>
      <td width="71%"><strong>Messages</strong></td>
    </tr>
    <tr class="tbl_caption_mem">
      <td valign="top">[ <a href="'.$file.'">Download File</a> ]</td>
      <td valign="top">'.$date.'</td>
      <td valign="top">'.$messages.'</td>
      </tr>
    </table><br />';
    
    $result->movenext();
    }
    $files = $test;
       DisplayTemplate($theme_path . "cp/myfiles.html", "\$files,\$error_msg");
      }
    what i would like to achieve, is if the field 'url' is empty then output message in that field. ie, no files available. i think i need to place if statement somewhere, but not sure where. any suggestions guys? many thanks
    I know more today than i did yesterday...
    V5.3.0

  2. #2
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    You can steal and modify a line from add.php

    if (empty($_POST['captcha_key']) || empty($_SESSION['captcha_key']))
    $error_msg = $msg["10120"];
    elseif ($_POST['captcha_key'] != $_SESSION['captcha_key'])
    $error_msg = $msg["10120"];
    elseif (empty($title))
    $error_msg = $msg["10101"];
    elseif (empty($url) || $url == 'http://')
    $error_msg = $msg["10102"];

    So you could use

    if (empty($url)) $error_msg = $msg["errormessage"];

  3. #3
    Join Date
    Jul 2007
    Posts
    126

    Default

    hi bruce. yeh already thought of that. problem with that, is that because it outputs results to a table, i am not sure where i need to place for this to work. i have tried near enough what you suggested, but i think it needs to be called from somewhere within the table. cheers
    I know more today than i did yesterday...
    V5.3.0

  4. #4
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    You can always force it via javascript

  5. #5
    Join Date
    Jul 2007
    Posts
    126

    Default

    don't know enough java to implement. i shall keep plodding away. many thanks
    I know more today than i did yesterday...
    V5.3.0

  6. #6
    Join Date
    Nov 2004
    Posts
    1,822

    Default

    Code:
       for($i = 0;$i < $result->RecordCount(); $i++){
       $file = $result->Fields("url");
    
    if ($file ==''){
    $file="sorry I got nothing for you";
    }
    
       $date = $result->Fields("date");
       $messages = $result->Fields("messages");
       $test .= '<table width="100%%"  border="0">
    if it finds nothing it will output the message instead of url.
    Main IndexU sites : | Campsite Directory | Tourist Guide | Places2B | AfterDirectory <-- Half price submission using coupon DP50 (from just $11 premium, and $10 basic permanent )

  7. #7
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    while I have no desire to code this, there are some issues with the code.

    the code logic seems wrong to me. I assume you have all the records returned in the $result array. you start out with a FOR loop that builds two tables. FOR EACH RECORD. probably not what you want to do. The description (Latest files and Messages) and column headings should come before the FOR loop.

    As for the FOR loop the psuedo code would be something like:

    Code:
    IF record_count>0
        FOR loop to display File, Date, Messages (is there more than one message?)
    ELSE
        Display Message 'No Records Found'
    END IF
    CLOSE TABLE
    I noted a couple of errors in the code.

    $test .= '<table width="100%%" border="0">

    should be

    $test .= '<table width="100%" border="0">



    you start out using single quotes

    $test .= '<table width="100%%" border="0">

    but then you use unescaped single quotes later on.

    <td valign="top">[ <a href="'.$file.'">Download File</a> ]</td>
    etc

    Looks like that would cause an error to me.

    actually you should probably do this in SMARTY. That is what it was designed to do. see the HTML pages for an example. I think there are some there.

    I don't know SMARTY and have no desire to learn it at this time.



    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  8. #8
    Join Date
    Jul 2007
    Posts
    126

    Default

    inspireme. the code

    if ($file ==''){
    $file="sorry I got nothing for you";
    }
    adds the message to the url. so it becomes:

    Code:
    http://domain.com/cp/sorry I got nothing for you
    what i am trying too achieve, is to replace the 'Download File' with 'sorry I got nothing for you' which is here:

    Code:
    <tr class="tbl_caption_mem">
      <td valign="top">[ <a href="'.$file.'">Download File</a> ]</td>
      <td valign="top">'.$date.'</td>
      <td valign="top">'.$messages.'</td>
      </tr>
    </table>
    esm. apart from this modification, the script is doing everything i need it to do. i have corrected the points you made and thanks for bringing them to my attention. inspireme, i think we are on the right track with your code, just need to find a way to implement it. many thanks
    I know more today than i did yesterday...
    V5.3.0

  9. #9
    Join Date
    Nov 2004
    Posts
    1,822

    Default

    you could try this :


    <tr class="tbl_caption_mem">
    if ($file==''){
    <td valign="top">[ sorry no files ]</td>
    }
    else {
    <td valign="top">[ <a href="'.$file.'">Download File</a> ]</td>
    }

    <td valign="top">'.$date.'</td>
    <td valign="top">'.$messages.'</td>
    </tr>
    </table>

    i have to say im a little confused about how thats working, i guess your assigning the tables to a variable? probably wont be able to put if statement where i have it in the code, but i guess see what happens.
    Last edited by inspireme; 10-03-2007 at 03:17 PM.
    Main IndexU sites : | Campsite Directory | Tourist Guide | Places2B | AfterDirectory <-- Half price submission using coupon DP50 (from just $11 premium, and $10 basic permanent )

  10. #10
    Join Date
    Jul 2007
    Posts
    126

    Default

    correct inspireme. dosen't work in tables. error message:

    Code:
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in
    there must be a way? cheers
    I know more today than i did yesterday...
    V5.3.0

  11. #11
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    http://javascript.internet.com/forms...ed-fields.html shows you the simple way using javascript. Modify to your liking

  12. #12
    Join Date
    Jul 2007
    Posts
    126

    Default

    bruce. thanks for that. however,that isn,t what i am looking for. that is more suited to forms etc. what i am trying to achieve, is basically, if one field is empty display message in it's place instead of blank download link. cheers
    I know more today than i did yesterday...
    V5.3.0

  13. #13
    Join Date
    Jul 2007
    Posts
    126

    Default

    sorted. here is the code for anyone else who may need it:

    Code:
    <tr class="tbl_caption_mem">
      <td valign="top"> ';
      if ($file ==''){ $test .= 'No New Files Available</td>
      <td valign="top">'.$date.'</td> 
      <td valign="top">'.$messages.'</td>
      </tr>
    </table><br />';
    }
    else
    {
     $test .= '[ <a href="'.$file.'">Download File</a> ]</td> 
      <td valign="top">'.$date.'</td>
      <td valign="top">'.$messages.'</td>
      </tr>
    </table><br />';
    
    }
    many thanks as usual for all your help guys.
    I know more today than i did yesterday...
    V5.3.0

Similar Threads

  1. application.php file empty
    By boboboyz in forum v5.x
    Replies: 3
    Last Post: 04-28-2007, 12:37 PM
  2. Instead of the catalogue empty page
    By individ in forum v3.2
    Replies: 0
    Last Post: 02-08-2006, 02:34 AM
  3. Fixed: admin check cat-structure check
    By Frank71 in forum v3.2
    Replies: 1
    Last Post: 01-15-2006, 05:58 PM
  4. Replies: 0
    Last Post: 01-05-2006, 05:25 AM
  5. Check of the URL
    By franceliens in forum v3.2
    Replies: 1
    Last Post: 08-28-2001, 06:41 PM

Posting Permissions

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