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
https://forums.phpfreaks.com/topic/71683-help-with-if-statement/
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

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.

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

Archived

This topic is now archived and is closed to further replies.

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