Jump to content

Problem writing database content into a styled div


icue

Recommended Posts

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&#8230;</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&#8230;</span></div></a>";
	echo "</div>";
	}

	?>
</div>

 

everything formatted correctly.

 

Could someone tell me where I am going wrong.

 

Thanks in advance,

James

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.