Jump to content

help with if statement


ploppy

Recommended Posts

hello what i am trying to is check for empty field and print message if empty. Here is the code that displays the fileds etc:

 

$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");
  }

 

i have tried with if statement like thus:

 

if (empty($file))
      $error_msg = 'this filed is empty.';

 

alas, it is not working. it just prints to the screen but dosen't check $file for empty field. Any help gratefully received. cheers

Link to comment
Share on other sites

here you go:

 

/*===================================================
    ShowMyFiles()
  ===================================================*/

  function ShowMyFiles() {
  
    // vars global configuration
    global $dbConn, $theme_path;

    // vars messages
    global $msg;

    // vars template
    global $error_msg, $username, $status, $owner, $files,$test;

    if ($err) {
      $error_msg = $msg['20191'];
    }
    if (empty($result)) $error_msg = 'no files';

    //$links_obj                      = new clsLink;


    // get file listing
    $query  = "select * from idx_files where username = '".$_COOKIE[COOKIE_USERNAME]."'";
    //$links_obj->query               = $query;
    //$links_obj->table_name          = "idx_users";
   // $links_obj->date_format         = $msg["10151"];
    //$links_obj->max_rows            = 100;
    //$files                           = $links_obj->Display();

$query      = "select * from idx_files where username = '".$_COOKIE[COOKIE_USERNAME]."'";
    $result     = $dbConn->Execute($query);
    //$files = $result->Fields("url");
// $owner = $result->Fields("owner");
// $date = $result->Fields("date");

    // $files = explode ( " ", $files );

$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");
  }

 

obviously, disregard the // lines. cheers

Link to comment
Share on other sites

thanks darkfreaks. had a look for JS collapse etc but do not think i have the time to research and start to learn a new language when i am still getting to grips with PHP :-) thoguth php would have done it. the other possibility is CSS. may have to go done that route. cheers for your help.

Link to comment
Share on other sites

sorry, darkfreaks. not with you on this. is that the code i would put in script? have tried:

 

if ($file ==''){
$file="sorry I got nothing for you";

 

the above becomes part of the url link. and this:

 

if (empty($file))
      $error_msg = 'There are no files';

 

this works and outputs msg when the field is empty, but the download link is still there and is clickable. basically, what i am trying to do, is swap the text so that if there are no files, the 'Download File' becomes 'There are no files'. many thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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