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 Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/ Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 bump Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360962 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.';} Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360963 Share on other sites More sharing options...
ploppy Posted October 3, 2007 Author Share Posted October 3, 2007 ??? Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360966 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? Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360967 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? Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360969 Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 sure would help more Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360970 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 Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360975 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? Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360982 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. Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360989 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. Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-360990 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 Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-361003 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 Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-361014 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. Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-361029 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 Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-361036 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 Link to comment https://forums.phpfreaks.com/topic/71683-help-with-if-statement/#findComment-361085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.