php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2004

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 21.06.2004, 19:46  
Gast
 
Beiträge: n/a
Standard Array mit while Schleife auslesen

Hallo,

ich habe folgendes Problem:

Ich habe einen Array, bei dem ich aber keine Ahnung habe, wie ich den jetzt in ein schön formatierten HTML text umwandeln kann.

Mit open_r($data); wird mir im HTML Quelltext der Array folgendermaßen angezeigt:



Code:
Array
(
    [0] => amazonrezensionen Object
        (
            [Rating] => 5
            [Summary] => the best to understand cities now and then
            [Comment] => this book, published for the first time in 1978, ask the main principle of the modern mouvement. Rowe and Koetter write about the opposition of the concept of "tabula rasa and an urban tradition taken from the historical memory and progressive sedimentation of the cities. "Collage" is a possible assimilation of the two different problematic, in the way that it's take past and future in a complex present.
        )

    [1] => amazonrezensionen Object
        (
            [Rating] => 1
            [Summary] => Pompous garbage
            [Comment] => This book is the most pompous garbage I have ever seen. It is unreadable drivel that has no point and adds nothing to the search for solutions to our urban problems. What were the authors thinking? They deserve the "Emperor has no clothes" award for this trash. Save your money and buy "A Pattern Language," "Edge City," "Changing Places," "Home from Nowhere," or any of many meaningful books that say something relevant.
        )

    [2] => amazonrezensionen Object
        (
            [Rating] => 5
            [Summary] => Most Important Book on Urban Design Theory Today
            [Comment] => Colin Rowe proposes a form of inclusive urbanism that meshes the modern city with the traditional city.
        )

)
Was ich am Ende im Browser Angezeigt haben möchte wäre z.B. sowas:

5 Punkte the best to understand cities now and then
this book, published for the first time in 1978, ask the main principle of the modern mouvement. Rowe and Koetter write about the opposition of the concept of "tabula rasa and an urban tradition taken from the historical memory and progressive sedimentation of the cities. "Collage" is a possible assimilation of the two different problematic, in the way that it's take past and future in a complex present.

1 Punkt Pompous garbage
This book is the most pompous garbage I have ever seen. It is unreadable drivel that has no point and adds nothing to the search for solutions to our urban problems. What were the authors thinking? They deserve the "Emperor has no clothes" award for this trash. Save your money and buy "A Pattern Language," "Edge City," "Changing Places," "Home from Nowhere," or any of many meaningful books that say something relevant.

5 Punkte Most Important Book on Urban Design Theory
Colin Rowe proposes a form of inclusive urbanism that meshes the modern city with the traditional city.

Natürlich kann es aber auch mehr Datensätze geben.

Irgenwie müsste es doch so aussehen, nur ist das $array sicherlich falsch?!

Zitat:
while ($array < 10) {
echo "$Rating Punkte",
."$Summary
",
."[i]$Comment";
}
Kann mir da jemand bitte helfen

vorab schonmal danke,
Flözen[/quote]
 
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 21.06.2004, 22:37  
Gast
 
Beiträge: n/a
Standard

Code:
$i = 0;
while($i < count($array))
{
echo $array[Rating]."
".$array[Summary]."
".$array[Comment]."

;
$i++;
}
Meinste das so ?
 
Alt 22.06.2004, 07:06  
Gast
 
Beiträge: n/a
Standard

Zitat:
Zitat von Biertrinker3
Code:
$i = 0;
while($i < count($array))
{
echo $array[Rating]."
".$array[Summary]."
".$array[Comment]."

;
$i++;
}
so werden einfach nur die 3 array elemente 3 mal ausgegeben
zur ausgabe eines assoziativen array hilft keine while-schleife
am einfachsten geht es so:
Code:
foreach($array as $key=>$value){
echo "Index " . $key . " hat den Wert " . $value . "
";
}
 
Alt 22.06.2004, 09:30  
Erfahrener Benutzer
 
Benutzerbild von lazydog
 
Registriert seit: 02.04.2008
Beiträge: 4.032
lazydog befindet sich auf einem aufstrebenden Ast
Standard

So falsch war Biertrinker3s Vorschlag gar nicht, er hat nur den ersten (nummerischen) Index vergessen. So sollte es gehen:
Code:
for($i = 0;$i < count($data);$i ++)
{
    echo '' . $data[$i]['Rating'] . '' . $data[$i]['Summary'] . '
' . $data[$i]['Comment'] . '

';
}
__________________
Gruss
L
lazydog ist offline  
Alt 22.06.2004, 19:57  
Gast
 
Beiträge: n/a
Standard

Vielen dank für die Zahlreichen antworten. Ein stückchen weiter wäre ich damit, aber die anzeige haut noch nicht hin

Mit
Code:
for($i = 0;$i < count($data);$i ++) {
 
echo 'test:' . $data[$i]['Rating'] . '' . $data[$i]['Summary'] . '
' . $data[$i]['Comment'] . '

'; 
 }
[/quote]

oder

Code:
$i = 0; 
 while($i < count($data)) 
 { 
 echo $i.$data[Rating]."
".$data[Summary]."
".$data[Comment]."

"; 
 $i++; 
 }
oder auch
Code:
foreach($data as $key=>$value){ 
 echo "Index " . $key . " hat den Wert " . $value . "
"; 
 }
bekomme ich immerhin 3 Datensätze angezeigt (Also Zeilen, in denen nur was steht, was ich auch direkt in den Quelltext geschrieben habe). Leider Fehlt bei allen der Inhalt der Felder Rating, Summery und Comment...
Bei der letzten Methode steht dann:

Index 0 hat den Wert Object
Index 1 hat den Wert Object
Index 2 hat den Wert Object

Also irgendwie noch nicht ganz befriedigend...

Hier nochmal die Funktionen aus denen das oben beschriebenen Array erzeugt wird. Vielleicht kann mir auf Grund dieser Info jemand noch weiter helfen


Code:
global $amazon_id, $developer_token;

$get_xml = fopen("http://xml-eu.amazon.com/onca/xml3?t=$amazon_id&dev-t=$developer_token&AsinSearch=$isbn&type=heavy&f=xml&locale=de", "r");
while ($read = fread($get_xml, 1024)) {
$amazon_file .= $read;
}
fclose($get_xml);


$CustomerReview = $amazon_file;


class AmazonRezensionen {
	var $Rating;
	var $Summary;
	var $Comment;
	
	function AmazonRezensionen ($aa) {
		foreach ($aa as $k=>$v)
			$this->$k = $aa[$k];
			}
}

function readRezension($CustomerReview) {

// Read the part of the Database we need
// Da wir keine Datei lesen kommt folgendes
$data = $CustomerReview;

// Falls aus einer XML Datei gelsen werden soll
//$data = implode("", $CustomerReview);


$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);

// loop through the structures
foreach ($tags as $key=>$val) {
	if ($key == "CustomerReview") {
		$reviewranges = $val;
		// each contiguous pair of array entries are the 
		// lower and upper range for each review
		for ($i=0; $i < count($reviewranges); $i+=2) {
				$offset = $reviewranges[$i] + 1;
			$len = $reviewranges[$i + 1] - $offset;
			$tdb[] = parseRezension(array_slice($values, $offset, $len));
			}
		} else {
			continue;
		}
	}
	return $tdb;
}

function parseRezension($amazonvalues) {
	for ($i=0; $i < count($amazonvalues); $i++) {
		$arez[$amazonvalues[$i]["tag"]] = $amazonvalues[$i]["value"];
		}
		return new AmazonRezensionen ($arez);
}

$data = readRezension($CustomerReview);
echo "Amazon ausgabe:
";
print_r($data);
Vielen Dank soweit

Floezen
 
Alt 23.06.2004, 08:05  
Erfahrener Benutzer
 
Benutzerbild von lazydog
 
Registriert seit: 02.04.2008
Beiträge: 4.032
lazydog befindet sich auf einem aufstrebenden Ast
Standard

Sorry, ich habe übersehen, dass es sich um einen Array von Objekten handelt, und nicht einen Array von Arrays. Dann gehts z.B. folgendermassen:
Code:
for($i = 0;$i < count($data);$i ++)
{
    echo '' . $data[$i]->Rating . ' Punkt(e) ' . $data[$i]->Summary . '
' . $data[$i]->Comment . '

';
__________________
Gruss
L
lazydog ist offline  
Alt 26.06.2004, 18:39  
Gast
 
Beiträge: n/a
Standard

Ahh, ok vielen Dank. Ist scheinbar doch komplizierter, als ich anfangs dachte, aber so klappts.


Grüsse
Florian
 
Alt 26.06.2004, 19:56  
Erfahrener Benutzer
 
Registriert seit: 18.09.2003
Beiträge: 13.598
PHP-Kenntnisse:
Fortgeschritten
imported_Ben ist zur Zeit noch ein unbeschriebenes Blatt
Standard

kleine anekdote .. ich hab gestern nacht an einem 2-dimensionalen array rumgewerkelt, wobei die zweite dimension objekte beinahltet hat, die dann aber wiederum unterschiedliche eigenschaften hatten ..

ich sag nur ..
um 3:00 hatte ich es dann .. man muss nur lang genug probieren ..

naja .. nur so ein wenig spam am rande ..
imported_Ben ist offline  
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Turnierbaum aus array erstellen kingflo PHP-Fortgeschrittene 11 30.07.2008 11:32
Dynamisch Array aus MySQL mit PHP auslesen. Muuip PHP Tipps 2008 2 26.08.2007 21:19
while schleife auslesen geht nicht richtig... T-sneak PHP Tipps 2006 6 28.05.2006 16:29
Zweidimensionales Array auslesen u wieder in Array schreiben Lobo PHP Tipps 2006 7 20.04.2006 11:37
Ausgabe Array in schleife PHP Tipps 2006 2 01.02.2006 13:49
Array auslesen andrew22 PHP Tipps 2006 3 21.01.2006 23:06
array auslesen mit while Calli PHP Tipps 2007 17 15.12.2005 15:21
[Erledigt] While schleife in while schleife = nur ein datensatz?! PHP Tipps 2005-2 9 28.10.2005 12:48
Menü mit Unterpunkten supertramp Beitragsarchiv 7 18.10.2005 22:40
while schleife in einer while schleife beim tmpl-sys PHP Tipps 2005-2 0 27.07.2005 15:07
Array in Session speichern und wieder auslesen Riot PHP Tipps 2005-2 3 08.07.2005 11:43
MySQL auslesen ohne while schleife PHP Tipps 2005 3 10.05.2005 12:43
while schleife beenden PHP Tipps 2005 3 29.03.2005 20:35
Array wie auslesen? PHP Tipps 2005 7 07.03.2005 11:43

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
while array, php while array, php array while, array while, php array auslesen while, while array php, while schleife array, array mit while auslesen, array while schleife, php while array auslesen, while php array, array while php, array auslesen while, php array while auslesen, php array mit while auslesen, php array auslesen schleife, array auslesen schleife, array mit schleife auslesen, while array auslesen, array mit while

Alle Zeitangaben in WEZ +2. Es ist jetzt 04:58 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.