debuitls Posted September 8, 2009 Share Posted September 8, 2009 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 Link to comment https://forums.phpfreaks.com/topic/173542-help-needed-printing-db-output-into-a-div/ Share on other sites More sharing options...
methodman Posted September 8, 2009 Share Posted September 8, 2009 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. Link to comment https://forums.phpfreaks.com/topic/173542-help-needed-printing-db-output-into-a-div/#findComment-914761 Share on other sites More sharing options...
debuitls Posted September 8, 2009 Author Share Posted September 8, 2009 Thanks methodman. Ill give that a try now. Link to comment https://forums.phpfreaks.com/topic/173542-help-needed-printing-db-output-into-a-div/#findComment-914764 Share on other sites More sharing options...
Jibberish Posted September 8, 2009 Share Posted September 8, 2009 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>"; Link to comment https://forums.phpfreaks.com/topic/173542-help-needed-printing-db-output-into-a-div/#findComment-914772 Share on other sites More sharing options...
cbolson Posted September 8, 2009 Share Posted September 8, 2009 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 Link to comment https://forums.phpfreaks.com/topic/173542-help-needed-printing-db-output-into-a-div/#findComment-914777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.