chauhanRohit Posted March 23, 2014 Share Posted March 23, 2014 Hi guys, can i use a single div to display different data from the database and how to display the output from a php into the html page, THis is the php file how do i output the results back to index.php <?php include 'php_includes/connection.php'; $C_output = ''; //collect //query $query = mysql_query("SELECT * FROM authors WHERE fname LIKE 'Aardema' ") or die("could not search"); $count = mysql_num_rows($query); if($count == 0){ $C_output = '<div>"there was no search result!"</div>'; }else{ $C_output = '<div>'; while($row = mysql_fetch_array($query)){ $C_output .= '<div class="content"> '.$row['fname'].' '.$row['lname'].'<br /> '.$row['content'].' <br /><br /></div>'; } $C_output .= '</div>'; } echo($C_output); mysql_close(); ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/287195-how-to-use-the-same-div-to-display-different-data-from-database/ Share on other sites More sharing options...
Ch0cu3r Posted March 23, 2014 Share Posted March 23, 2014 THis is the php file how do i output the results back to index.php Can you explain further what you mean by this? Is this code not in index.php? Quote Link to comment https://forums.phpfreaks.com/topic/287195-how-to-use-the-same-div-to-display-different-data-from-database/#findComment-1473599 Share on other sites More sharing options...
ginerjm Posted March 23, 2014 Share Posted March 23, 2014 What you want to do is certainly a common enough thing. Simply create your html wrapper with the div and css stylings and then place your php var in the html. Then let the html be output along with that var and you'll have what you want. I usually do this kind of thing by having all of my html in one function (DisplayPage) and then let all my php code happen before calling that function to send all my output - html and php vars that I have created. You can pass the vars into the function with args i.e.: DisplayPage($var1,$var2,$var3), or use global vars (which many are totally against, but they work just fine for me). Quote Link to comment https://forums.phpfreaks.com/topic/287195-how-to-use-the-same-div-to-display-different-data-from-database/#findComment-1473600 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.