Forum Moderators: open
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT Name, date_FORMAT(Start_date, '%a, %b %e, %Y') as Start_date, Start_time, County, State, Website, Description, Venue_name, Category, User_hosted, nUser_Id FROM tbl_events
ORDER BY EventID DESC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$Name=mysql_result($result,$i,"Name");
$Start_date=mysql_result($result,$i,"Start_date");
$Start_time=mysql_result($result,$i,"Start_time");
$County=mysql_result($result,$i,"County");
$State=mysql_result($result,$i,"State");
$Website=mysql_result($result,$i,"Website");
$Description=mysql_result($result,$i,"Description");
$Venue_name=mysql_result($result,$i,"Venue_name");
$Category=mysql_result($result,$i,"Category");
$User_hosted=mysql_result($result,$i,"User_hosted");
$nUser_Id=mysql_result ($result,$i,"nUser_Id");
if ($User_hosted=="Y")
{
echo '<div style="font-family:Arial; font-size:18px; color:black; padding-bottom:10px;">';
echo "$Name";
echo '<div style="font-family:Arial; font-size:14px; color:black; padding-left:10px; padding-bottom:10px; margin-bottom:25px; border-bottom:1px solid #000000; line-height:1.55em;">';
echo "$Start_date  "; echo " $Start_time<br>";
echo "@ $Venue_name "; echo "in $County, "; echo "$State<br>";
echo "<a href='http://$Website' target='_blank'>$Website</a><br>";
echo "$Description<br>";
echo "User hosted?: $User_hosted  "; echo "By <a href='http://example.com/profile.php?id=$nUser_Id&pageFromWhere=pageFromWhere' target='_blank'>this user";
echo '</div>';
}
if ($User_hosted=="N")
{
echo '<div style="font-family:Arial; font-size:18px; color:black; padding-bottom:10px;">';
echo "$Name";
echo '<div style="font-family:Arial; font-size:14px; color:black; padding-left:10px; padding-bottom:10px; margin-bottom:25px; border-bottom:1px solid #000000; line-height:1.55em;">';
echo "$Start_date  "; echo " $Start_time<br>";
echo "@ $Venue_name "; echo "in $County, "; echo "$State<br>";
echo "<a href='http://$Website' target='_blank'>$Website</a><br>";
echo "$Description<br>";
echo '</div>';
}
$i++;
}
?>
[edited by: coopster at 3:21 pm (utc) on Feb. 4, 2009]
[edit reason] please use example.com in code [/edit]
Also outputting semantic html might be a better solution. It will also make it easier to see what's going on by clearing out the markup in your output:
<style type="text/css">
.container {
font-family:Arial;
color:black;
padding-bottom:10px;
}
.container h4 { font-size:18px; padding:0; margin: 0; }
.container ul {
font-size:14px;
padding-left:10px;
padding-bottom:10px;
margin-bottom:25px;
border-bottom:1px solid #000000;
line-height:1.55em;
}
.container ul li { list-style: none; }
</style>
....
echo "<div class=\"container\">\n";
echo "<h4>$Name</h4>\n";
echo "<ul>\n";
echo "<li>$Start_date $Start_time</li>\n";
echo "<li>@ $Venue_name in $County, $State</li>\n";
echo "<li><a href=\"http://$Website\" target=\"_blank\">$Website</a></li>\n";
echo "<li>$Description</li>\n";
echo "</ul>\n</div>\n\n";
....
$nUser_Id=htmlentities(mysql_result ($result,$i,"nUser_Id"));
htmlentities("By <a href='http://example.com/profile.php?id=$nUser_Id&pageFromWhere=pageFromWhere' target='_blank'>this user")
I'm very new to this so if what I've tried is completely ridiculous would you mind explaining to me why?
As far as htmlentities goes, there isn't much more that I can tell you than what is on the manual page that I offered. You don't use it on exiting html (unless you want to show the html in your browser page as opposed to allowing the browser to render the html). htmlentities should be used on text or data that you are outputting to the browser so that it can be embedded in your existing html. If I tried to write out something from my database that contained html entities it would screw up the browser. For example,
$dataFromDB = $row['myText']; // myText contains: Is p2<p1?
// try to use that in some html ...
print "<p>$dataFromDB</p> // renders as: <p>Is p2<p1?<p>
// and your browser will not display it properly!
<into it's html entity equivalent
<so that the browser will render the output correctly.