ploppy Posted October 3, 2007 Share Posted October 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 bump Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 if (empty($file)){ $error_msg = 'this filed is empty.';} Quote Link to comment Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 ??? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 missing the curly brackets in your if statement also where are you echoing out $error? Quote Link to comment Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 thats the part im having trouble with darkfreaks. should i post complete code? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 sure would help more Quote Link to comment Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 try if (empty($files)) $error_msg = 'no files'; also what is in the files variable? Quote Link to comment Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 no. outputs the message but dosen't replace the 'download file' with message. the download file link is still there. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 i got an idea use abit of javascript collapse menu and if it equals empty have it collapse the table. Quote Link to comment Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 i wish i could. i do not know about JS to know where to start. is there a archive of snippets somewhere? cheers Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 google javascript expand/collapse menu and then mmake it collapse on error msg Quote Link to comment Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 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. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 well you could do somethingh like if files empty { str_replace(link here,'') } which would replace the link with nothing Quote Link to comment Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.