2013-10-04 46 views
0
<?php 
$sql = 'SELECT gamedate, gametime, homeschool, visitorschool FROM my_table WHERE WEEKOFYEAR(gamedate)=WEEKOFYEAR(NOW()) ORDER BY gamedate'; 
$result = mysql_query($sql, $link); 

if (!$result) { 
echo "DB Error, could not query the database\n"; 
echo 'MySQL Error: ' . mysql_error(); 
exit; 
if(mysql_num_rows($result)>0) { 
?> 

<table style="width: 300px; padding: 0; margin-left: -16px;" cellpadding="7px"> 
<tbody> 
<tr><td valign="top"><img src="images/cobrasschedule.png"/></td></tr> 
<?php 
    mysql_data_seek($result, 0); 
    $day = ' '; 
    while ($row = mysql_fetch_assoc($result)) { 
    if (date('l, F d, Y', strtotime($row['gamedate'])) !== $day) { 
    $day=date('l, F d, Y', strtotime($row['gamedate'])); 

?> 
<tr> 
    <td colspan="2" style="background-color:#D3BC9A; color:white;text-transform:uppercase; padding-left:25px;"><strong><?= $day?></strong></td> 
</tr> 
<?php } ?> 
<tr> 
<?php if ($row['sporttype'] == 'Baseball'): ?> 
<td colspan="2" style="background-color:#D3BC9A; color:white;text-transform:uppercase; padding-left:25px;"><strong>BASEBALL</strong></td> 
<?php elseif ($row['sporttype'] == 'MBasketball'): ?> 
<td colspan="2" style="background-color:#D3BC9A; color:white;text-transform:uppercase; padding-left:25px;"><strong>MEN'S BASKETBALL</strong></td> 
<?php elseif ($row['sporttype'] == 'Equine'): ?> 
<td colspan="2" style="background-color:#D3BC9A; color:white;text-transform:uppercase; padding-left:25px;"><strong>EQUINE</strong></td> 
<?php endif; ?> 
</tr> 
<tr> 
<?php if ($row['homeschool'] == 'Virginia Intermont College - VA'): ?> 
<td><p style="text-shadow: none; margin-bottom: -7px;"><strong><?php echo $row['homeschool'];?>vs.</strong><br ><?php echo $row['visitorschool'];?></p></td> 
<?php else: ?> 
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['visitorschool'];?>@<br ><?php echo $row['homeschool'];?></p></td> 
<?php endif; ?> 
<?php if ($row['homescore'] != ' ' and $row['homeschool'] == 'Virginia Intermont College - VA'): ?> 
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['homescore'];?><br ><?php echo $row['visitorscore'];?></p></td> 
<?php elseif ($row['homescore'] != ' ' and $row['homeschool'] != 'Virginia Intermont College - VA'): ?> 
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['visitorscore'];?><br ><?php echo $row['homescore'];?></p></td> 
<?php elseif ($row['score'] != ' '): ?> 
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['score'];?></p></td> 
<?php elseif ($row['score'] == ' ' and $row['homescore'] == ' '): ?> 
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['gametime'];?></p></td> 
<?php endif; ?> 
</tr> 
<?php 
$day=date('l, F d, Y', strtotime($row['gamedate'])); 
} 
} 
?> 
</tbody> 
</table> 

<?php 
} else {?> 
<span style="vertical-align:top;margin-left:-16px;padding:0;"><img src="images/cobrasschedule.png" border="0"/></span> 
<?php 
echo "Schedule is not available."; 
} 
mysql_free_result($result); 
?> 

我有这个相同的代码在另一个地方工作,当我在phpMyAdmin中运行查询它返回5行。但是,当我在网站上运行它时,它总是说“计划不可用”。不知道为什么这不工作...返回没有结果我猜

任何帮助将不胜感激。谢谢!

+0

你连接到正确的数据库的权利? 'echo mysql_db_name($ result);' – immulatin

+0

没有错误?完全相同的数据库连接和查询? –

+0

您确定要连接到同一个数据库吗?尝试检查错误报告并最终将其设置为E_ALL。另外,mysql已被弃用,请改用mysqli! – briosheje

回答

2

你没有关闭掉错误检查:

if (!$result) { 
    echo "DB Error, could not query the database\n"; 
    echo 'MySQL Error: ' . mysql_error(); 
    exit; 
} // <-- This is missing 
if(mysql_num_rows($result)>0) { 

所以的“时间表不可用”的elseelseif(!result) {。换句话说,如果查询成功,它将打印“计划不可用”

+0

非常感谢!我一直在努力构建两周,睡眠很少,只是错过了......完全! – user2833089

2

是不是只是在这里错过了}

if (!$result) { 
echo "DB Error, could not query the database\n"; 
echo 'MySQL Error: ' . mysql_error(); 
exit; // <-- expected `}` here 
if(mysql_num_rows($result)>0) { 

你应该真的改善你的代码风格。使用适当的IDE。

相关问题