multiple function query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

multiple function query

Post by ridwan »

I have created two functions which will work in connection with each other I dont know if it's silly to do this but I thought it was worth the try:

One function creates the html page and the other calls info from a db and lays it out neatly.

I have placed the second function within the first one to display the info correctly. All the info is displayed but in the incorrect order, it seems to be displaying the second functions info first and then the first one. Why would this happen ?? The code is as follows:
(mod edit: changed

Code: Select all

to

Code: Select all

, easier to read )

Code: Select all

include ("scripts/conf.php");

//this function will create the basic outlay for the html section of the page
function html_page_content($infofill)
{
	echo "<html><head><title>page filler info</title></head>
             <body topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>
			<table width='329' border='0' cellspacing='0' cellpadding='0'>
			  <tr>
				<td width='21'><img src='../images/spacer.gif' width='21' height='8'></td>
				<td width='379' colspan='2'><img src='images/mustek%20big%20logo.gif' width='270' height='81'></td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td colspan='2'>&nbsp;</td>
			  </tr>
			  <tr>
				<td valign='top'>&nbsp;</td>
				<td colspan='2' align='center' valign='top'>&nbsp;</td>
			  </tr>
			  <tr>
				<td colspan='3'>" . $infofill .
				"</td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td colspan='2'>&nbsp;</td>
			  </tr>
			</table>
			</body>
			</html>";
}

//this function places the specifics of the page within the table
function info($block_type, $arrow_type)
{
        //Query requested info from the table
		global $result, $query, $pageType;
        $query = "SELECT * FROM sitecontent WHERE section = '$pageType' ORDER BY contentid";
        $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

        $row = mysql_fetch_object($result);

	      echo "<table width='329' border='0' cellpadding='0' cellspacing='0'><tr>
	            <td width='21' valign='top'><img src='images/" . $block_type ."' width='21' height='9'></td>
	            <td width='308' colspan='2' align='center' valign='top'>
                 <table width='95%' border='0' cellspacing='0' cellpadding='0'>
	                <tr><td>" . $row->SubSection . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <img src='images/" . $arrow_type . "' width='10' height='10'></td>
	                </tr><tr>
	                  <td><br>";
                      	while (mysql_fetch_object($result))
                        {
                            //$subheading =
                             echo $row->SubSection . "<p>" . $row->Body . "</p>";
                        	//echo $subheading;
                         }
            echo "</td></tr></table></td></tr></table>";
}

html_page_content(1);

info("about_block.gif", "about_arrow.gif")
THanks all
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

not sre about it but the output of html_page_content() is a complete html-document. Calling both functions you get something like

Code: Select all

<html>
	<head><title>page filler info</title></head>
	<body topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>
		<table width='329' border='0' cellspacing='0' cellpadding='0'>
			...
		</table>
	</body>
</html>
<table width='329' border='0' cellpadding='0' cellspacing='0'>
...
that's not a valid html-document anymore and the browser is free to display in any order it likes.
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

my mistake

Post by ridwan »

:oops: Sorry about that but I seem to have posted it incorrectly it was supposed to go like this:

Code: Select all

html_page_content(info("about_block.gif", "about_arrow.gif")
);
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ah, then it's much clearer ;)
info() does not return the contents as string, it echos it
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

Post by ridwan »

is that why it doesn't order it correctly and then how would i get it to return it as a string or must i just define html_page_content as a variable ? :?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

html_page_content(info("about_block.gif", "about_arrow.gif"));
that's almost (not completely) the same as

Code: Select all

$argument = info("about_block.gif", "about_arrow.gif");
html_page_content($argument);
so info() is called first and the return value is passed to html_page_content() that uses it as parameter.
But info() doesn't return anything, it immediatly displays what it supposed to be the return value.

Code: Select all

function funcA()
{ // this function does not return anything but writes something to the output-stream
	echo 'something';
}

function funcA()
{ // this function returns a string instead ot printing it
	$retval = 'something';
	$retval .= ' to be returned';
	return $retval;
}
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

thanks

Post by ridwan »

htanks a lot for that I should be on my way now :D
Post Reply