Nappi Posted June 17, 2010 Share Posted June 17, 2010 Hi all Im still lerning english and PHP - so rorry for my bad english and sorry for some question My problem i like to write a HTML file with PHP with some variables from my mysql database thats was i hasfe right now <?php require_once ('inc.php'); $filename = 'member.html'; // Siche $db_link = mysql_connect (MYSQL_HOST, MYSQL_BENUTZER, MYSQL_KENNWORT); // Nutzen von Datenbank - Name ist hinterlegt in // Konstante MYSQL_DATENBANK $db_sel = mysql_select_db( MYSQL_DATENBANK ) or die('Auswahl der Datenbank fehlgeschlagen'); $sql = 'SELECT * FROM jos_zoomfiles'; $db_erg = mysql_query( $sql ); if ( ! $db_erg ) { die('Ungültige Abfrage: ' . mysql_error()); } while ($zeile = mysql_fetch_array($db_erg, MYSQL_ASSOC)) { $content = "<div id='".$zeile['imgname']."'><h3>'".$zeile['imgname']."'</h3><p><div ><img style='float: left; padding: 5px; margin: 5px 5px 5px 5px; border: 2px solid black' src='/images/stories/'".$zeile['imgfilename']."' alt='".$zeile['imgname']."' width='400px' /></div><p>'".$zeile['imgdescr']."'</p></div>"; } //sicher gehen, dass die Datei existiert und beschreibbar ist if (is_writable($filename)) { // Wir öffnen $filename im "Anhänge" - Modus. // Der Dateizeiger befindet sich am Ende der Datei, und // dort wird $somecontent später mit fwrite() geschrieben. if (!$handle = fopen($filename, "w")) { print "Kann die Datei $filename nicht öffnen"; exit; } // Schreibe $somecontent in die geöffnete Datei. if (!fwrite($handle, $content)) { print "Kann in die Datei $filename nicht schreiben"; exit; } print "Fertig, in Datei $filename wurde geschrieben"; fclose($handle); } else { print "Die Datei $filename ist nicht schreibbar"; } mysql_free_result( $db_erg ); ?> It works - but only with the last entry in may DB - i townt know wat i can doo that all the entris in the DB cams out one after the oter in may HTML file - so that it loohs someting like this <div id='Nappi'><h3>'Nappi'</h3><p><div ><img style='float: left; padding: 5px; margin: 5px 5px 5px 5px; border: 2px solid black' src='/images/stories/'Nappi.jpg' alt='Nappi' width='400px' /></div><p><p>wenn das jetzt noch geht bin ich happy</p> <p><span style="font-size: 18pt;"><em><strong>oder so ähnlich</strong></em></span></p>'</p></div> i hope you can help me Nappi Link to comment https://forums.phpfreaks.com/topic/205077-write-html-file-with-php/ Share on other sites More sharing options...
severndigital Posted June 17, 2010 Share Posted June 17, 2010 looks to me like you need to add to the content where you replacing it each time... try this. while ($zeile = mysql_fetch_array($db_erg, MYSQL_ASSOC)) { $content = "<div id='".$zeile['imgname']."'><h3>'".$zeile['imgname']."'</h3><p><div ><img style='float: left; padding: 5px; margin: 5px 5px 5px 5px; border: 2px solid black' src='/images/stories/'".$zeile['imgfilename']."' alt='".$zeile['imgname']."' width='400px' /></div><p>'".$zeile['imgdescr']."'</p></div>"; } change that to $content = ''; while ($zeile = mysql_fetch_array($db_erg, MYSQL_ASSOC)) { $content .= "<div id='".$zeile['imgname']."'><h3>'".$zeile['imgname']."'</h3><p><div ><img style='float: left; padding: 5px; margin: 5px 5px 5px 5px; border: 2px solid black' src='/images/stories/'".$zeile['imgfilename']."'alt='".$zeile['imgname']."' width='400px' /></div><p>'".$zeile['imgdescr']."'</p></div>"; } using .= instead of = will add to the variable instead of replacing it. P Link to comment https://forums.phpfreaks.com/topic/205077-write-html-file-with-php/#findComment-1073524 Share on other sites More sharing options...
Nappi Posted June 17, 2010 Author Share Posted June 17, 2010 it works - thank you so muche - i was sitting on the problem one day and one night - thx again Nappi Link to comment https://forums.phpfreaks.com/topic/205077-write-html-file-with-php/#findComment-1073528 Share on other sites More sharing options...
severndigital Posted June 17, 2010 Share Posted June 17, 2010 no problem. just mark the topic as solved. thanks, Link to comment https://forums.phpfreaks.com/topic/205077-write-html-file-with-php/#findComment-1073529 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.