Jump to content

return values to page from function


denoteone

Recommended Posts

I have a function that gets info from a DB and assigns the data to a variable. I then want to use the variable on the page that called the function. something like

Function in my common.php file:

function popUpData($type,$id){

								$sql  = ("SELECT dr_node.title AS Title, 

							   dr_content_type_readmore.field_readmore_text_value AS Body			
							   
								FROM dr_content_type_readmore, dr_node

								WHERE dr_content_type_readmore.nid = dr_node.nid

							    And dr_content_type_readmore.nid =  '$id' 

								And dr_node.type =  'readmore'  ORDER BY Title ASC"); 

				$result = mysql_query($sql) or die ("Error in query: $query. ".mysql_error());
  
				while($row = mysql_fetch_assoc($result)){
				$title = $row['Title'] ;
				$story =  $row['Body'] ;
				}				
}

 

And here is the code on the page:


<html>
  <head>
      	<?PHP 
        include("includes/common.php"); 
        $db = new connection_tim();
$type = $_GET['type'];
$id = $_GET['id'];
      	popUpData($type,$id);
        ?>

   </head>
<body>
                <div id="header"><?PHP echo $title; ?></div>
                 <div id="body"><?PHP echo $story; ?></div>
  </body>
</html>

 

Any help would be awesome. Not sure what I am missing.

Link to comment
https://forums.phpfreaks.com/topic/187614-return-values-to-page-from-function/
Share on other sites

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.