2013-02-28 86 views
0

我该如何解决我的未定义索引:标题。 为什么这是幸福吗?我已经尝试定义索引标题,但它没有工作我如何解决我的未定义索引:标题

在我使用href之前,它工作得很完美。在此声明的标题:

<td><?= isset($restaurant_result['title']) ? $restaurant_result['title'] : '<span style="color:red">MANGLER</span>'; ?></td> 

实施HREF后,我得到一个未定义的索引。

<td><a href="restaurantoversigt?email=<?php echo $restaurant_result['title']?>"> <?= isset($restaurant_result['title']) ? $restaurant_result['title'] : '<span style="color:red">MISSING</span>'; ?></a></td> 
+0

哪儿来的'isset($ restaurant_result ['title'])'进入你的'href'实现! – Broncha 2013-02-28 09:04:06

回答

2

你缺少isset检查,请使用以下内容:

<?php $title = isset($restaurant_result['title']) ? $restaurant_result['title'] : ""; ?> 

<td><a href="restaurantoversigt?email=<?php echo $title ?>"> <?= $title != "" ? $title : '<span style="color:red">MISSING</span>'; ?></a></td> 
0

尝试

array_key_exists('title', $restaurant_result) ? $restaurant_result['title'] : '<span style="color:red">MISSING</span>' 
0

$restaurant_result['title']是不确定的。您之前没有收到错误信息,因为您在尝试使用之前检查是否使用isset未定义错误。

1

试试这个:

<?php 
    $title = isset($restaurant_result['title'])?$restaurant_result['title'] :""; 
?> 
<?php if($title){ ?> 
<td><a href="restaurantoversigt?email=<?php echo $title;?>"> <?= $title ?></a></td> 
<?php } else {?> 
<td><a href="restaurantoversigt?email=<?php echo $title;?>"> <span style="color:red">MISSING</span></a></td> 
<?php }?> 

注:在其他条件会有$title空,所以HREF将是:restaurantoversigt?email=

1
<?php 
    $title = null; 
    if (isset($restaurant_result['title'])) 
     $title = $restaurant_result['title']; 
    ?> 

    <td><a href="restaurantoversigt?email=<?php echo $title; ?>"> <?= $title !== null ? $title : '<span style="color:red">MISSING</span>'; ?></a></td> 
0

试试这个:

<td><a href="restaurantoversigt?email=<?php echo $restaurant_result['title']?>"> <?php echo isset($restaurant_result['title']) ? $restaurant_result['title'] : '<span style="color:red">MISSING</span>'; ?></a></td> 
相关问题