2010-01-24 5 views
1

데이터베이스에서 일부 결과를 얻으려고하고 있지만, 저는 오늘 뇌가 죽은 것 같아요.PHP에서 MySQL 결과를 구문 분석하는 데 문제가 있습니다

foreach($castrow['cast_id'] as $caster) 
{ 
    echo "<p>"; 
    if ($caster['avatar_url']!='') echo "<img src=\"".$caster['avatar_url']."\" alt=\"".$caster['name']."\">"; 
    echo "<a href=\"?edit=".$caster['cast_id']."\">".$caster['name']."</a></p>"; 
} 

$castquery = "SELECT * FROM cast " . 
    "WHERE player_id = '" . $userid ."' "; 
$castresult = mysql_query($castquery) or die(mysql_error()); 
$castrow = mysql_fetch_array($castresult); 

는 ... 분명히 내가 여기에 뭔가를 분명 내려다 보이는거야.

+0

, 어떤 결과 당신이 얻을려고? – Matchu

답변

4

db 구조가 무엇인지 모르지만 $castrow['cast_id']은 배열이 아닌 단일 필드입니다. 당신이 아마 의미하는 것은 : 그것은 지금 모든 당신의 foreach

+0

'castrow'는 기술적으로 "castrows"라고해야합니다. 하나의 행이 아니라 행 집합이기 때문입니다. –

+0

글쎄, 기술적으로, mysql_fetch_array()를 호출 할 때마다 * one * 행을 얻는다. –

+0

고마워, 나는 그것이 단순하고 멍청한 무언가라는 것을 알았다. – aslum

1

최초의 대신

while ($castrow = mysql_fetch_array($castresult)) { 
    // use $castrow array here 
} 

, 코드는 하나 개의 행을 가져옵니다.

$castrow = mysql_fetch_array($castresult); 

foreach($castrow['cast_id'] as $caster) 
{ 

은이어야한다

스크립트가 실패하는 방법
while ($castrow = mysql_fetch_array($castresult)) { 

    $caster = $castrow['cast_id']; 
    .... 
관련 문제