icue Posted June 21, 2012 Share Posted June 21, 2012 Hi, I am quite new to PHP so could someone please offer some advice as I am having problems writing the contents of a mysql database into a div. My css is setup to style the content into 2 div's a light blue bg 'textBlock_club' and a darker blue bg textBlock2_club. The entire content should then be contained inside the div "venContent". At the the moment, only one item from the database is written into the div, the rest it seems is being written into the body of the page. This is the code I am using. <div id="venContent"> <?php require_once 'login.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); $result = mysql_query("SELECT * FROM search"); if (!$result) die ("Database access failed: " . mysql_error()); $rows = mysql_num_rows($result); for ($i = 0 ; $i < $rows ; ++$i) { $img = mysql_result($result,$i,'img'); $name = mysql_result($result,$i,'name'); $address = mysql_result($result,$i,'address'); $desc = mysql_result($result,$i,'desc'); $info = mysql_result($result,$i,'info'); if($i % 2 == 0) { echo "<div class='textBlock_club'>"; }else{ echo "<div class='textBlock2_club'>"; } echo "<img width='95' height='95' src=images/all/" .$img."' alt=$name /> <p><span class=\"add_bold\">$name</span> <br /> <span class=\"add_colorClubs\">$address</span> <br /> $desc <br /> $info</p><a class=\"fancybox fancybox.iframe\" href=slide-div-test-2.html><div class=\"more\"><span class=\"more_color\">more info…</span></div></a></div>"; echo "</div>"; } ?> </div> I originally used an xml file to store the data and using the following code: <div id="venContents"> <?php $xml = simplexml_load_file('all.xml'); $data = $xml->venue; for ($i = 0; $i < sizeof($data); $i++) { $images = $data[$i]->image; $restname = $data[$i]->name; $add = $data[$i]->address; $desc = $data[$i]->description; $inform = $data[$i]->info; if($i % 2 == 0) { echo "<div class='textBlock_club'>"; }else{ echo "<div class='textBlock2_club'>"; } echo "<a href=#.php><img src='" .$images . "'alt='name' /></a> <p><span class=\"add_bold\">$restname</span> <br /> <span class=\"add_colorClubs\">$add</span> <br /> $desc <br /> $inform</p> <a class=\"fancybox fancybox.iframe\" href=#.php><div class=\"more\"><span class=\"more_color\">more info…</span></div></a>"; echo "</div>"; } ?> </div> everything formatted correctly. Could someone tell me where I am going wrong. Thanks in advance, James Quote Link to comment Share on other sites More sharing options...
Barand Posted June 21, 2012 Share Posted June 21, 2012 check you don't have too many </div>s Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 21, 2012 Share Posted June 21, 2012 And in the future, when posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment Share on other sites More sharing options...
icue Posted June 21, 2012 Author Share Posted June 21, 2012 Hi, Thanks for your help. I removed the last echoed div and all is well now. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.