Jump to content

How to use the same div to display different data from database


chauhanRohit

Recommended Posts

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

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).

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.