皆さん、ありがとうございました... 私は1つのデータベースと3つのクエリを同時に持っています。すべてのクエリで別の年が選択され、その列からデータが取得されます。foreach - 2番目または3番目の配列から特定の値を取得
私が入力するとこれは私のコード
$items = array();
// while we still have rows from the db, display them
while ($row = mysql_fetch_array($result1)) {
$items[] = $row;
}
while ($row = mysql_fetch_array($result2)) {
$items[] = $row;
}
while ($row = mysql_fetch_array($result3)) {
$items[] = $row;
}
mysql_close($connect);
?>
<?php foreach($items as $key => $item) : ?>
<?php print "I DONT KNOW WHAT TO DO"; ?>
<?php endforeach; ?>
です:
<?php echo print_r($keys); ?>
私は私がから特定の行を取得するのが大好きだ0、1及び2の配列を持っていることがわかります最初の配列(1)または2番目の配列(2)。
私はそれを把握しようとしていますし、私はちょうどカント...
はそんなにあなたのすべてをありがとう!
編集:
完全なコード:ループ内
<?php
include ('db.php'); // for db details
include ('functions.php');
$connect = @mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>');
if (!$connect) {
die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>');
$query1 = "SELECT * FROM godina2015 WHERE mjesec='8' AND godina='2015'";
$query2 = "SELECT * FROM godina2015 WHERE mjesec='7' AND godina='2015'";
$query3 = "SELECT * FROM godina2015 WHERE mjesec='6' AND godina='2015'";
$result1 = @mysql_query("$query1") or die('<p class="error">There was an unexpected error grabbing news from the database.</p>');
$result2 = @mysql_query("$query2") or die('<p class="error">There was an unexpected error grabbing news from the database.</p>');
$result3 = @mysql_query("$query3") or die('<p class="error">There was an unexpected error grabbing news from the database.</p>');
$items = array();
// while we still have rows from the db, display them
while ($row = mysql_fetch_array($result1)) {
$items[] = $row;
}
while ($row = mysql_fetch_array($result2)) {
$items[] = $row;
}
while ($row = mysql_fetch_array($result3)) {
$items[] = $row;
}
mysql_close($connect);
?>
<?php foreach($items as $key => $item) : ?>
<?php print_r ($item); ?>
<?php endforeach; ?>
EDIT#2
<?php
include ('db.php'); // for db details
include ('functions.php');
$connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>');
if (!$connect) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>');
$query = "SELECT * FROM godina2015 WHERE mjesec IN(8,7,6) AND godina='2015'";
$result = mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing news from the database.</p>');
$items = array();
// while we still have rows from the db, display them
while ($row = mysql_fetch_array($result)) {
$items[] = $row;
}
mysql_close($connect);
?>
<?php foreach($items as $key => $item) : ?>
<?php echo $items[1]['AWAsistCTR2']; ?>
<?php endforeach; ?>
foreachループで 'print_r($ item);'を実行するとどうなりますか? –
これは、 'var_dump($ items)'を表示するのに役立ちますhttp://stackoverflow.com/questions/17139453/php-accessing-multidimensional-array-values –
。あなたのデータ構造がどのように見えるかを正確に表示/説明する必要があります。配列をどのように構築しているかを考えれば、最初のクエリ結果の '$ items [0] ... $ items [n]'、 '$ items [n + 1] ... 2番目のクエリの$ items [n + m] 'など –