php非法字符串偏移量

时间:2015-08-24 08:57:16

标签: php mysql

输出数组时遇到一些问题。基本上,一些文档和其他信息正在上传到数据库,我想显示下载链接和之后上传的关于它们的详细信息(onclick)。 这是我的代码:

$sqlresult = mysql_query("SELECT DISTINCT u.username, p.p_url FROM users AS u INNER JOIN papers AS p ON p.user_id = u.user_id WHERE username = '{$_SESSION['user']}'");
$check_row = mysql_num_rows($sqlresult);
$counter = 1;
$output = "";
$outarray = array();
if ($check_row > 0) {
  while ($output = mysql_fetch_array($sqlresult)) {
    $outarray[1] = $output[1];
    if (is_array($outarray)) {
      foreach ($outarray as $val) {
        $query = mysql_query("SELECT p_name, p_authors, p_corresponding, p_email, p_cauthor, p_abstract, p_jname, p_date FROM papers INNER JOIN users ON papers.user_id = users.user_id WHERE p_url = '$val' AND username='{$_SESSION['user']}'");
        $last = mysql_fetch_assoc($query);
        foreach ($last as $key => $value){
          // echo "$key"."=="."$value";
          $search = substr($val, 0, strpos($val, '.'));
          $trim = str_replace($val, '', $search);
          $counter++;
        }
      }
      echo <<<HERE
      <a href="http://localhost:8080/laboratory/users/{$_SESSION['user']}/{$val}" target="_blank">{$trim}</a>&nbsp;&nbsp;
      <a href="#collapse{$counter}" style="text-decoration: none; font-size: 14px; " onclick="$('p').show();return false;" class="nav-toggle">+ See details</a>

      <div id="collapse{$counter}" style="display:none">
      <p>Name:{$value['p_name']}, Author:{$value['p_authors']}, Corresponding author:{$value['p_corresponding']}, etc ...</p>
      </div>  
      <br />
      HERE;
    }
  }
} else {                           
  echo "You don't have any papers uploaded !";
}
}
}

我收到警告:“警告:非法字符串偏移”,但是当第二个foreach循环给出正确的输出(注释回声部分)时,这怎么可能?有什么建议 ?谢谢。

1 个答案:

答案 0 :(得分:0)

只是一个猜测:如果','strpos将返回FALSE。在$ val中找不到。在substr中使用FALSE时会触发警告。