Page 1 of 1

PHP and Dreamweaver Snippets??

Posted: Thu Jan 22, 2004 4:50 am
by bmak
Hello,

I'm new to PHP and am still trying to get my head round the programming style.

I have a PHP page which confirms the upload of a file to my site and then displays a list of currently uploaded files. This list is displayed in table format and I want to make it less boring!

I have a "snippet" created for Dreamweaver MX which changes the background colour of each row in the table as your cursor passes over it. Problem is I can't figure out the ground rules on how this might be incorporated into the PHP page/script.

Can anyone tell me if it can be done?

Do I have to insert the code into the relevant places in the PHP code or can I get the snippet code to be incorporated by using an "include" statement which references the snippet code and incorporates it in the PHP code?

Can anyone lend a hand please?

-------------- PHP Code ----------------
<?PHP

//set counter to 0
$tfiles = 0;

//open directory for reading files
$dh = opendir( $ufolder ) or die("Could not open directory");

//read files
while ( ! ( ( $file = readdir( $dh ) ) === false ) ) {
//make sure file isn't in the don't read list
if ( is_file( "$ufolder/$file" ) and (!in_array($file,$not_include)) )
{
//add 1 to counter
$tfiles++;
//print through all files add each to the table
print " ";
print "<TR>";
print "<TD align=\"right\" bgcolor=\"#B4B4B4\">($tfiles)</TD>";
print "<TD bgcolor=\"#B4B4B4\">";
print "&nbsp;<a href=\"$url$file\" target=\"_blank\"><font face=\"arial\" color=\"#000000\" size=\"2\">$file</font></A>&nbsp;<BR>\n";
print "</TD>";
print "<TD bgcolor=\"#B4B4B4\">";
$size = "".filesize ("$ufolder$file")."";
$size = "".round(($size/1024), 2)."";
print "<font face=\"arial\" color=\"#000000\" size=\"2\">&nbsp;$size KB&nbsp;</font>";
print "</TD>";
print "</TR>";
}
}
print "</table>";
print "<P>";
print "<table border=\"0\">";
print "<tr><td>";
print "Total files: $tfiles";
print "</td></tr>";
print "</table>";
//close directory
closedir( $dh );

print "</div>";
?>

---------- END PHP CODE ----------------------

---------- START SNIPPET CODE --------------

<!-- START OF SNIPPET -->
<table width="100%" border="0" cellspacing="1"

cellpadding="3">
<tr bgcolor="#e8e8e8" onMouseOver="this.bgColor =

'#FFBC58'"
onMouseOut="this.bgColor = '#e8e8e8'">
<td>WebThang</td>
<td>Snippets</td>
<td>JavaScript, ASP-VBScript, HTML, PHP, CSS,

...</td>
<td><a

href="http://www.webthang.co.uk/codebank/codebank.asp"
target="_top"

onFocus="if(this.blur)this.blur()">more...</a></td>
</tr>
<tr bgcolor="#e8e8e8" onMouseOver="this.bgColor =

'#FFBC58'"
onMouseOut="this.bgColor = '#e8e8e8'">
<td>WebThang</td>
<td>Resources</td>
<td>Dreamweaver, Databases & SQL, Paintshop Pro,

...</td>
<td><a

href="http://www.webthang.co.uk/resources/resource.asp"
target="_top"

onFocus="if(this.blur)this.blur()">more...</a></td>
</tr>
</table>
<!-- END OF SNIPPET -->
---------- END SNIPPET CODE --------------

Thanks in advance for any help you can give.

bmak
:?:

Posted: Thu Jan 22, 2004 5:58 am
by malcolmboston
i always do it like this in plain HTML

Code: Select all

<td bgcolor="black" onmouseover="red" onmouseout="green"</td>
etc etc

Posted: Thu Jan 22, 2004 6:23 am
by bmak
malcolmboston wrote:i always do it like this in plain HTML

Code: Select all

<td bgcolor="black" onmouseover="red" onmouseout="green"</td>
etc etc
Thanks for this info. Unfortunatetly it does not fit into the PHP script. PHP does not seem to recognise "onmouseover" or "onmouseout". I think that the prerequisite here is that the HTML you kindly provided must be embedded into the existing code, and then i am back where I started.

Any ideas?

bmak

Posted: Thu Jan 22, 2004 6:27 am
by malcolmboston
technically it should work exactly the same if you are using the print command

Code: Select all

<?php
print "
<td bg color=red onmouseout=black onmouseover=green><spacer></td>";
?>
if it doesnt i have no idea why

Posted: Thu Jan 22, 2004 6:51 am
by twigletmac
bmak wrote:Thanks for this info. Unfortunatetly it does not fit into the PHP script. PHP does not seem to recognise "onmouseover" or "onmouseout".
PHP doesn't recognise HTML or Javascript - it just sees these as strings and is simply echoing what you ask it to the screen, so any issues will be related to the HTML or Javascript and have nothing to do with PHP.

So you can just copy and paste the snippet code into the relevant places, eg.

Code: Select all

echo "<TR>";
and

Code: Select all

&lt;tr bgcolor="#e8e8e8" onMouseOver="this.bgColor = '#FFBC58'" onMouseOut="this.bgColor = '#e8e8e8'"&gt;
becomes

Code: Select all

echo '<tr bgcolor="#e8e8e8" onMouseOver="this.bgColor =''#FFBC58''" onMouseOut="this.bgColor = ''#e8e8e8''">';
Mac

Posted: Thu Jan 22, 2004 10:28 am
by McGruff
Or don't embed html in php: embed php in html.

Make a template in Dreamweaver. Add <?php eho $var; ?> wherever you need to.

Back in php, define all the vars then include the template.

This allows you to work on the formatting with Dreamweaver (if that's what you're used to) and code in php.

Posted: Thu Jan 22, 2004 10:31 am
by malcolmboston
i thought that is what everyone does?

it is only in extreme circumstance that PHP is used to create HTML