PDA

View Full Version : Help With PHP Script


Pee-H-Pee
08-30-2004, 07:22 PM
I am trying to generate a text field with the html code that people can use to copy and paste to show the exact same thing my php script generated. The user fills out a form to get the data for itemsperrow, LIMIT, description, category, length, etc...Here is the PHP script that generates the code. I am trying to get an example to show at the top of the page (which is already done by this script) and then a text area box under the example to show the html code for copying and pasting. Hope that made sense :D


<?
include("config.php");
echo "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 width=100% bgcolor=#FFFFFF>\n";
$itemsperrow = 3;
$i = 1;
echo "<tr>";
$result = mysql_query("select * from TABLE WHERE CatName='$category' ORDER by name ASC LIMIT 9") or die (mysql_error());
while ($row = mysql_fetch_array($result)) {

$row[description]=substr($row[description], 0, 75);

if (is_int($i / $itemsperrow)) {

echo "<td align=center><b>$row[name]</b><br><img src=\"$row[image]\" border=\"0\" alt=\"$row[name]\"><br><div align=left>$row[description]</div><a href=\"http://www.site.com/product.asp?pid=$row[skew]\">Click Here >></A>";
echo "</td></tr><tr>";

}
else {
echo "<td align=center><b>$row[name]</b><br><img src=\"$row[image]\" border=\"0\" alt=\"$row[name]\"><br><div align=left>$row[description]</div><a href=\"http://www.site.com/product.asp?pid=$row[skew]\">Click Here >></A>";
echo "</td>";
}
$i++;
}
echo "</tr></table><br>";
?>

4xz
08-30-2004, 08:00 PM
Same code (within a <textarea> container), but replace :
all <'s with &lt;
all >'s with &gt;

etc. in other words, use HTML entities.

Pee-H-Pee
08-30-2004, 08:55 PM
Thanks for that... didn't realize how easy it was :)
BTW, you don't need to use the all &lt; and &gt; stuff, the "<" and ">" will work inside text areas :thumbsup:

4xz
08-30-2004, 09:40 PM
Glad to hear u worked it out :)

AaronW
08-30-2004, 09:46 PM
Thanks for that... didn't realize how easy it was :)
BTW, you don't need to use the all &lt; and &gt; stuff, the "<" and ">" will work inside text areas :thumbsup:

Is that so? What if someone puts </textarea> into it?

Nightfire
08-31-2004, 12:44 AM
To advance on the previous reply, use http://uk.php.net/manual/en/function.htmlentities.php

Pee-H-Pee
08-31-2004, 11:40 PM
Is that so? What if someone puts </textarea> into it? Who cares?

AaronW
09-01-2004, 02:56 AM
You will, when you encounter it. It's simple to prevent, so why not add it in?