2011-04-12 51 views
1

我已經瀏覽了幾個相關的問題,看起來似乎無法看到問題!在函數內調用函數

以下兩個函數都在我的函數include文件中,而且由於某種原因,我似乎無法獲得check_orientation函數來將比例返回到display_months_news函數。

我很確定我只是很明顯地錯過了一些東西。

的display_news功能

function display_months_news() 
{ 
    //header('Content-type: image/jpeg'); 
    $year = date("y"); 
    $year = "20" .$year; 
    $month = date("m"); 
    if ($month) { 
     switch ($month){ 
      case "01": $month = "January"; break; 
      case "02": $month = "February"; break; 
      case "03": $month = "March"; break; 
      case "04": $month = "April"; break; 
      case "05": $month = "May"; break; 
      case "06": $month = "June"; break; 
      case "07": $month = "July"; break; 
      case "08": $month = "August"; break; 
      case "09": $month = "September"; break; 
      case "10": $month = "October"; break; 
      case "11": $month = "November"; break; 
      case "12": $month = "December"; break; 
     } 
    } else { 
     echo '<p>The date field is empty.</p>'; 
    } 
    $nowdate = $month." ".$year; 

    $result = mysql_query("SELECT * FROM news ORDER BY sqldate DESC LIMIT 6") or die(mysql_error()); 

    while ($row = mysql_fetch_array($result)) { 
     global $imgurl; 
     $imgurl = $row['img1']; 

     check_orientation4($imgurl); 

     $comcount = comment_count($row['nid']); 
     if ($comcount == NULL) {$comcount = 0;} 

     echo '<div class="news-preview-container">'; 
     echo '<div class="news-preview-container-date">'; 
     echo "<P>" .$row['mmonth']. " ".$row['dday']. ", " .$row['yyear']. "</p><BR>"; 
     echo '</div>'; 
     echo '<div class="news-preview-container-title">'; 
     echo "<p><a href='article.php?id=" .$row['nid']."'>" .$row['title']."</a></p><BR>"; 
     echo '</div>'; 
     echo '<div class="news-preview-container-inner">'; 
     echo '<div class="news-preview-container-text">'; 
     echo '<p>'.ShortenText($row['body']).'</p>'; 
     echo '</div>'; 
     echo '<div class="news-preview-container-image"><img src="'.$imgurl.'"'.$scale.'"></div><BR></div>'; 
     echo '<div class="news-preview-container-bottombar">Posted in '.$row[tag].'/'.$comcount.' Comments</div>'; 
     echo '</div>'; 

    } 
} 

和check_orientation功能

function check_orientation4($imgurls){ 

if ($imgurls == NULL){ echo ""; } 
else { 
     $imgurlshrunk = NULL; 
     $maxsize = 120; 
     $filename = NULL; 
     $height = NULL; 
     $width = NULL; 
     $scale = NULL; 
     $imgurlshrunk = $imgurls; 
     $filename = basename($imgurlshrunk); 
     $filename = "admin/uploads/" . $filename; 
     list($width,$height,$type,$attr) = getimagesize("$filename"); 
     $wRatio = $maxsize/$width; 
     $hRatio= $maxsize/$height; 

    global $scale; 

    if (($width <= $maxsize) && ($height <= $maxsize)) 
     { 

     $scale = ""; 
     return $scale; 
     } 
    elseif (($wRatio * $height) < $maxsize) 
    { 
     $scale = "width = '100%'"; 
     return $scale; 
    } 
    elseif ($height == NULL) 
    { 

     echo "empty height"; 
    } 
    else 
    { 
    global $height; 
     $scale = "height = '100%'"; 
     return $scale; 
    }  }} 

在此先感謝誰指出了愚蠢的錯誤我錯過了!

+0

難道是'$ imgurls'在check_orientation4的第三行是NULL? – Arjen 2011-04-12 13:42:56

+0

$ imgurl明確擁有一個值,並且看不到任何阻止它傳入check_orientation的東西,所以我懷疑這是問題 – Xand94 2011-04-12 13:44:34

+1

如果'imgurls'沒有聲明爲全局變量,則會出現這種情況 – 2011-04-12 13:44:53

回答

5

您不會在任何地方存儲check_orientation4($imgurl);的結果。嘗試改變該行這樣的:

$scale = check_orientation4($imgurl); 
+0

啊,出於某種原因,我在印象之下,返回將變量推到另一個函數......謝謝指出錯誤! – Xand94 2011-04-12 13:46:56

0

因爲你放棄了check_orientation4的返回值,也許?

+0

' check_orientation4'沒有返回任何值 – 2011-04-12 13:46:38

+0

當然,所有其他答案都指出了。 – 2011-04-15 14:20:02

+0

我站好了。對不起。 – 2011-04-15 19:14:32

2

你是不是有check_orientation4

2

你並沒有使用check_orientation4的任何東西的返回值的返回值做任何事情。

check_orientation4($imgurl); 

應該

$scale = check_orientation4($imgurl); 
2

你不應該回成規模某種類型的變量?現在你只是運行該功能。你應該這樣做:

$toScale = check_orientation4($imgurl);