Page 1 of 1

multiple function query

Posted: Mon May 12, 2003 4:17 am
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

Posted: Mon May 12, 2003 5:39 am
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.

my mistake

Posted: Mon May 12, 2003 5:44 am
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")
);

Posted: Mon May 12, 2003 5:47 am
by volka
ah, then it's much clearer ;)
info() does not return the contents as string, it echos it

Posted: Mon May 12, 2003 9:25 am
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 ? :?

Posted: Mon May 12, 2003 9:33 am
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;
}

thanks

Posted: Tue May 13, 2003 2:41 am
by ridwan
htanks a lot for that I should be on my way now :D