Page 1 of 1

PHP substr function problems

Posted: Fri Jul 13, 2007 9:56 am
by Suraski
I'm having trouble getting substr(); to display the data from a mysql database.

here's my code:

Code: Select all

$news2 = $row['news'];

include('includes/head.php');
$date = date('Y-m-d H:i:s');
mysql_select_db("news", $con);
$result = mysql_query("SELECT * FROM news ORDER BY date DESC  LIMIT 10");
while($row = mysql_fetch_array($result))
{
if ( $row['cat'] == News){
echo "				<table bgcolor=\"#FFF7CA\" width=\"500\" height=\"100\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: 1px solid #FFD460; margin: 10px; padding: 0;\" >
					<tr>
          				<td valign=\"top\" height=\"15\" style=\"padding: 3px 3px 3px 5px ; border-bottom: 1px solid #FFD460\">
							<d1head> News: &nbsp;" . $row['title'] . "</d1head>
		  				</td>
					</tr>
					<tr>
						<td valign=\"top\" height=\"20\" style=\"padding: 10px\"
							<t2> " . substr($news2,0,10) ." </t2><t2><br /> 
							<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row['name'] . "</t2>										
						</td>
					</tr>
					<tr>
						<td valign=\"top\" height=\"20\" style=\"border-top: 1px solid #FFD460\">
							<t2>" . $row['date'] . "</t2>						
						</td>
					</tr>
				</table>
		";
}
else{}
}

Posted: Fri Jul 13, 2007 9:58 am
by purinkle
Instead of

Code: Select all

if ( $row['cat'] == News){
Have you tried

Code: Select all

if ( $row['cat'] == 'News'){

Posted: Fri Jul 13, 2007 10:02 am
by Suraski
Ok, thanks that was the trick, I guess I'm still a noob when it comes to PHP