Forum Moderators: coopster

Message Too Old, No Replies

its something simple

or the hour is late ...

         

jackson

3:26 pm on Feb 26, 2004 (gmt 0)

10+ Year Member



Hi,

Seem to have got myself knotted here and I know this should be easy.

While rehacking a piece of code - the purpose of which is to put some data into a cell in a calendar - I have this. This is the original piece of code and it seems to work:

echo "\n<td align=center valign=top>".$holidayfont ;
showhols($weekhols,"cal_pophols.php?id=",true);
echo $closefont."</td>\n" ;

and am trying to convert it to the following:

$text .= "<td style='text-align: center; vertical-align: top'>";
$text .= showhols($weekhols,"evm_pophols.php?id=",true);
$text .="</td>" ;

which doesn't work. The data "floats" to the top of page.

The issue seems to be with the showhols function. Don't seem to have it nested properly.

Sort of lost sight of where I'm going here. Any suggestions would be appreciated?

coopster

4:54 pm on Feb 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What are you doing in your
showhols
function? echoing data? For example:

function showhols($weekhols,$php_script_name,$true_or_false) {
echo 'some data';
}

What will be happening is you will be writing the data to output and it isn't going to be concatenated to your $text variable back in the main flow when you return from this user-defined function. The value returned is more than likely going to be
true
since the function completes normally and that will be concatenated to the $text variable. You may need to go about things this way:

function showhols($weekhols,$php_script_name,$true_or_false) {
global $test;
$text .= 'some data';
return $text;
}

I'm merely speculating here since I don't know what your
showhols
function is doing...

jackson

2:45 am on Feb 27, 2004 (gmt 0)

10+ Year Member



Thanks for your reply. This is the function in question
function showhols($hols,$hyperlink,$pop){

$cnt = 0 ;
while ($row = mysql_fetch_object($hols)){
if ($cnt>0) echo "<br>" ;
if ($hyperlink=="")
echo "<u>" ;
else if ($pop)
echo "<a href='#' onclick=\"Javascript:window.open('".$hyperlink.$row->id."','popholswin','toolbar=no,location=no,status=no,
menubar=no,scrollbars=yes,resizable=no,width=300,height=300');\">" ;//all on one line
else
echo "<a href='".$hyperlink.$row->id."'>" ;
echo stripslashes($row->title) ;
if ($hyperlink!="")
echo "</a>";
else
echo "</u>";
$cnt++ ;
}
}

as mentioned, I'm hacking my way through someone else's code - learning as I go. I'd been inclined to just do a loop to collect and drop in the data. However, this function would serve the purpose of dropping in this data at other points in the app.

I'll work through your suggestion and see how we go.

coopster

2:49 am on Feb 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I speculated correctly by the looks of it, jackson. I have a typo in my snippet there, too. The variable I am declaring as a global is supposed to be $text, not $test.

Your function is writing out html and not appending it to your variable in your mainline loop. See what I mean? Change your echo's to

[b]$text .=[/b]
and return the $text variable at the end of your function...

jackson

5:41 am on Feb 27, 2004 (gmt 0)

10+ Year Member



Coopster, thanks a ton.

Noticed the test/text thing. Where I lost it was on the "return" item.

So simple. Knew I had been looking at this thing too long ...

Thanks again.