Jump to content

Help needed printing db output into a div.


debuitls

Recommended Posts

Hello all,

 

I have the following code

 

echo "<table id='myTable' cellpadding='0'>
<thead>
<th axis='string'>Booking Reference</th>
<th axis='string'>Hotel Name</th>
<th axis='number'>Hotel Star Rating</th>
</thead>";


while($row = mysql_fetch_array($result))
{
echo "<tr onclick=\"window.location='bookview.php?id=" . $row['bookingref'] ."'\">";
echo "<td>" . $row['bookingref'] . "</td>";
echo "<td>" . $row['hotelname'] . "</td>";
echo "<td>" . $row['starrating'] . "</td>";
echo "</tr>";
echo "</tbody>";
}
echo "</table>";

 

As you can see the output is currently printing into a table.

 

However rather than printing it into a table id like to print it into a div

 

So basically each table row will have its own div say for example

<div class="mydiv">.

 

I've tried

echo "<div class = mydiv"> . $row['bookingref'] . "</div>";

 

But this does not seem to be working.

 

I'm looking for an effect similar to http://www.rent.ie/houses-to-let/renting_dublin/south-dublin-city/

 

Does anyone know how this is done from the perspective of printing into a div.

 

Any suggestions would be appreciated

 

you can switch in and out of PHP, then place the div tag.. hard to explain heres an example:

 

<div id="mainContent">

<?php echo '<p>' . $whateverYouArePrinting . '</p>'; ?>

</div>

<div id="otherContent">

<?php echo '<p>' . $whateverYouArePrinting . '</p>'; ?>

</div>

 

So on and so forth. It's great to keep away from those tables when possible. entering and exiting PHP will definately accomplish your task.

also your mising a " and they will also break the opening one arround mydiv so you will need to escape them, which why it might not be working correctly

 

echo "<div class = mydiv"> . $row['bookingref'] . "</div>";

 

echo "<div class = \"mydiv\">"  . $row['bookingref']  . "</div>";

 

 

Hi,

Worth noting that your only problem with the snippet that you had posted was that the " (double quote) was in the wrong place.

You had:

echo "<div class = mydiv"> . $row['bookingref'] . "</div>";

it should have been:

echo "<div class = mydiv>" . $row['bookingref'] . "</div>";

Personally I would do it like this to maintain the correct double quotes in the html that is displayed:

echo '<div class ="mydiv">' . $row['bookingref'] . '</div>';

ie wrap the php in single quotes and use the double quotes for the html.

 

Chris

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.