2013-04-09 84 views
1

這是代碼:我無法從php數組中檢索值

我無法在第二個功能中打印站點類型。發送「所有」從不同的功能參數時,我能夠打印陣列。

function site_type_find($site_type) 
{ 
$site_type_name_array=['Youtube','Wikipedia','Mashable','Wired']; 
    if($site_type="all") 
    return $site_type_name_array; 
    else 
    return $site_type_name_array[$site_type]; 
} 
function display_topic_category_sitetype($topic_id,$category_id,$site_type) 
{ 
    $result=mysql_query("select topic_name from topic_table where topic_id=$topic_id"); 
    $result1=mysql_query("select category from categorytable where category_id=$category_id"); 
    $site_type_name=site_type_find($site_type); 
    $resultarr=array(); 
    $resultarr1=array(); 
    $resultarr=mysql_fetch_array($result); 
    $resultarr1=mysql_fetch_array($result1); 
    $topic=$resultarr[0]; 
    $catname=$resultarr1[0]; 
?> 
    <section> 
    <header><?php echo $topic."\n";?></header> 
    <article><?php echo $catname."\n";?></article> 
    <article><?php echo $site_type_name."\n";?></article> 
<?php 
} 

回答

5

您應該使用==代替=作爲比較操作。

這是一個在4號線:

if($site_type="all") // use two = 
+0

比較謝謝的回答!不能想出這麼簡單的事! :( – Aravind 2013-04-09 08:10:31

1

變化

if($site_type="all") 

if($site_type=="all") 
5

使用==,而不是=作爲比較操作。

在管路4中,使用下面的代碼。

if($site_type=="all") 

其中:

==用於checking equality OR爲comparison目的。

=用於assigning values到PHP變量。

1

單等於運算符(=)是賦值運算符和雙等於運算符(==)是一個比較運營商,所以你必須使用if($site_type=="all") bcoz這裏你的$site_type值與所有