2012-02-25 17 views
0

私は誰かが私を助けてくれるかどうか疑問に思います。PHPを使用してパネルを切り替える

いくつかのデモとチュートリアルからわかりましたが、thisページをまとめて、ページにトグルペインを追加しました。このページには、mySQLデータベースの値を使用してフィールドを設定しています。

私が抱えている問題は、各レイヤーで複数のレコードのうち最初のものだけが表示されていることです。

画面は現在、唯一のレコードとして16/03/2012を示していますが、2012年2月23日にはもう1つのレコードが必要です。

2012年3月16日以内に次のレベルに2つの項目が表示されますが、1つのみ表示されます。

私はしばらくの間これをやってきましたが、正しい数のレコードを表示する方法の解決策を見つけることができないようです。

私はちょうど誰かがこれを見て、私がどこに間違っているのかを教えてもらえるかどうか疑問に思った。

参考までに以下のスクリプトをすべて追加しました。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Panel Test</title> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
<script type="text/javascript"> 
jQuery(document).ready(function() { 
    jQuery(".content").hide(); 
    //toggle the componenet with class msg_body 
    jQuery(".heading").click(function() 
    { 
    jQuery(this).next(".content").slideToggle(500); 
    }); 
}); 
</script> 
<style type="text/css"> 
body { 
    margin: 20px auto; 
    font: 12px Verdana,Arial, Helvetica, sans-serif; 
} 
.layer1 { 
margin: 0; 
padding: 0; 
width: 500px; 
} 

.heading { 
margin: 1px; 
color: #fff; 
padding: 3px 10px; 
cursor: pointer; 
position: relative; 
background-color:#c30; 
} 
.content { 
padding: 5px 10px; 
background-color:#fafafa; 
} 
p { padding: 5px 0; } 
</style> 
</head> 
<?php 
mysql_connect("hostname", "username", "password")or 
die(mysql_error()); 
mysql_select_db("database"); 

$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, detectinglocations.locationname, finds.userid, finds.locationid, detectinglocations.locationid, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 ORDER BY dateoftrip DESC"); 

if (mysql_num_rows($result) == 0) 
// table is empty 
    echo 'There are currently no finds recorded for this location.'; 
    else 
{ 
    while ($row = mysql_fetch_array($result)) 
    { 
    $dateoftrip = $row['dateoftrip']; 
    $findname = $row['findname']; 
{ 
} 
} 
} 
?> 
<body> 
<div class="layer1"> 
     <p class="heading"><input name="dateoftrip" id="dateoftrip" type="text" value="<?php echo $dateoftrip;?>" disabled="disabled"/></p> 
     <div class="content"> 
      <input name="findname" id="findname" type="text" value="<?php echo $findname;?>" disabled="disabled"/> 
     </div> 
</div> 
</body> 
</html> 

多くの感謝と種類について

+0

whileループでは、$ dateoftripと$ findnameを何度も繰り返し割り当てます。 –

答えて

0

あなたはすべてのレコードをフェッチするが、最後のものだけを使用しています。あなたは内部のあなたの出力を配置する必要があり

 while ($row = mysql_fetch_array($result)) 
     { 
     $dateoftrip = $row['dateoftrip']; 
     $findname = $row['findname']; 
echo '<div class="layer1"> 
      <p class="heading"><input name="dateoftrip" id="dateoftrip" type="text" value="'.$dateoftrip.'" disabled="disabled"/></p> 
      <div class="content"> 
       <input name="findname" id="findname" type="text" value="'.$findname.'" disabled="disabled"/> 
      </div> 
    </div>'; 
     } 
+0

こんにちは、これは本当に素晴らしいです。ありがとうございます。しかし、私は自分自身を十分に説明していないかもしれない、私の心からの謝罪。複数の 'layer2(content)'レコードがある場合は、同じ 'レイヤー1(日付)'レコードの下にそれらを保存したいと思います。したがって、2012年3月16日のケースでは、'16/03/2012 'レイヤーを2つの'レイヤー2コンテンツエントリ 'が1つずつ表示されるようにしたいと思います。私はこれをどうやってやるか教えてください。もう一度、これを適切に説明しないことをお詫び申し上げます。種類については – IRHM

+0

を参考にしてください。 (ちょうどHTMLコードでさえ?) –

+0

こんにちは@Ofir、これにあなたの継続的な助けをたくさん感謝します。ここにページへのリンクがあります。 http://www.mapmyfinds.co.uk/development/panelest2.php これが助けになることを願っています。私に知らせてくれないと、それ以外の方法で提供することができます。種類に関して – IRHM

0

:データを取得whileループ内

<div class="layer1"> 
     <p class="heading"><input name="dateoftrip" id="dateoftrip" type="text" value="<?php echo $dateoftrip;?>" disabled="disabled"/></p> 
     <div class="content"> 
      <input name="findname" id="findname" type="text" value="<?php echo $findname;?>" disabled="disabled"/> 
     </div> 
</div> 

while ($row = mysql_fetch_array($result)) 
    { 
    $dateoftrip = $row['dateoftrip']; 
    $findname = $row['findname']; 

だから、このようになります あなたはこれを置く必要がありますあなたのループ。また、複数のコンテンツIDのアカウントに合わせてjavascriptを変更する必要があるかもしれません。

フォームコントロールを配列にして、必要に応じて解析できるようにする必要があります(下記参照)。

たとえば、これはフォームを変更する方法です。

?> 
<body> 
<div class="layer1"> 
<?php 
    while ($row = mysql_fetch_array($result)) 
    { 
    $dateoftrip = $row['dateoftrip']; 
    $findname = $row['findname']; 

    $i++; 
?> 
    <p class="heading"><input name="dateoftrip[]" id="dateoftrip" type="text" value="<?php echo $dateoftrip;?>" disabled="disabled"/></p> 
    <div class="content"> 
     <input name="findname[]" id="findname" type="text" value="<?php echo $findname;?>" disabled="disabled"/> 

<?php 

{ 
} 
} 
}  
?> 
    </div> 
</div> 
関連する問題