Forum Moderators: coopster
i have a script that creates a link in a member area when there are files for them to download. what i am trying to do is if there are no files, then instead of the 'Download File' link there is a text messag like 'No files available'. I have tried various things but keep getting erroring. the latest was this piece of code that works in that it displays the message but dosen't put it in place of the download link.
if ($file ==''){$file="sorry I got nothing for you"; }here is the code and if someone could cast an eye over it and tell me where i am going wrong i would be grateful. The code works fine and does what i need it to but i need this function so that if there are no files the link isn't visible. 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'];
}
//$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");
if ($file ==''){
$file="sorry I got nothing for you";
}
$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">
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><br />';
$result->movenext();
}
$files = $test;
DisplayTemplate($theme_path . "cp/myfiles.html", "\$files,\$error_msg");
}
many thanks for help.
I think you are donig it well. What is the error you are getting?
One comment though, once you run the if condition, don't repeat it back again. if file was initially empty, at the first condition then it won't be empty anymore as it is being asigned to some value.
If you are not getting the result you wanted, you need to check if $file = $result->Fields("url"); is getting you any output or not.
Post back with the specific problem you are facing.
Habtom
$file = $result->Fields("url");
if ($file ==''){
$file="sorry I got nothing for you";
} is becoming part of the url. ie, [domain.com...] I got nothing for you. this is not what i want.
many thanks
if ($file ==''){
$error="sorry I got nothing for you";
}
if (isset($error)) {
echo $error;
}
You may be able to add that to the global errors that you already have.
[edited by: PHP_Chimp at 11:43 am (utc) on Oct. 4, 2007]
$test = '';
for($i = 0;$i < $result->RecordCount(); $i++){
$file = $result->Fields("url");
if ($file ==''){
$file="sorry I got nothing for you";
}
Are you missing } here? To close the for statment.
$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">
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><br />';
You have checked for a lack of $file twice. The second one adds your error message to the table, so isnt this what you wanted? Cant you get rid of the first check?
[edited by: PHP_Chimp at 12:09 pm (utc) on Oct. 4, 2007]