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

Link to comment
Share on other sites

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

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.