timmah1 Posted May 6, 2009 Share Posted May 6, 2009 I have a script that grab everything from the database depending on a package type, then shows everything according to the package type. There are 6 packages, everything shows perfect for package 1-5, but for the 6th package, the $hint part does not show. The hint is actually a rollover Can anybody look at the code and tell me why this part of the code don't show the hint? case "6-spl": $Ddate = date("Y-m-d"); $firstDate = date("Y-m-01"); $lastDate = date("Y-m-d", strtotime("-1 Day")); $Dtime = date("H:i"); $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start = '".date("Y-m-d")."'"; $w1 = mysql_query($query1); $numrows = mysql_num_rows($w1); if($numrows == 0 ){ //echo "No special for today"; $query3 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start BETWEEN '$firstDate' AND '$lastDate' ORDER BY id DESC LIMIT 1"; $w3 = mysql_query($query3); while($b3 = mysql_fetch_array($w3)){ $id = $b3['id']; $end = date("Y-m-d h:i:s", strtotime($b3['exp'])); $id = $b3['id']; $name = $b3['name']; $package = $b3['package']; $start = date("Y-m-d h:i:s"); $hint = $b2['hint']; $price = $b3['price']; } } elseif($numrows > 0){ //echo "There is a special for today<br />"; $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start = '".date("Y-m-d")."' AND '".date("H:i")."' >= starttime ORDER BY starttime DESC LIMIT 1"; $w1 = mysql_query($query1); $numrows = mysql_num_rows($w1); if($numrows == 0 ) { //echo "Special for today hasn't started yet<br />"; $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start BETWEEN '$firstDate' AND '$lastDate' ORDER BY id DESC LIMIT 1"; $w1 = mysql_query($query1); } while($b2 = mysql_fetch_array($w1)){ //echo "Start time: $b2[starttime]<br />Current time: $Dtime<br />Special for current time"; $id = $b2['id']; $end = date("Y-m-d h:i:s", strtotime($b2['exp'])); $id = $b2['id']; $name = $b2['name']; $package = $b2['package']; $start = date("Y-m-d h:i:s"); $hint = $b2['hint']; $price = $b2['price']; } } break; Here is the entire code <?php $sport = "nba"; //$sport = "nfl"; //$sport = "ncaaf"; //$sport = "ncaab"; switch($sport){ case "nba": $title = "NBA Basketball"; break; case "nfl": $title = "NFL Football"; break; case "ncaaf": $title = "NCAA Football"; break; case "ncaab": $title = "NCAA Basketball"; break; } ?> <!--start NCAA Football table--> <table width="100%" cellpadding="3" border="1" cellspacing="0" height="175"> <tr> <td align="center" height="15" bgcolor="#000000" class="orderHeader"><?=$title;?></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="25" align="left" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <?php $sql = "SELECT * FROM packages1 WHERE sport = '$sport' ORDER BY package LIMIT 6"; $q = mysql_query($sql); $numrows = mysql_num_rows($q); if($numrows == 0){ echo "nothing"; } while($a = mysql_fetch_assoc($q)){ //put variables into easily read $id = $a['id']; $name = $a['name']; $package = $a['package']; $start = date("Y-m-d h:i:s"); $price = $a['price']; switch($package){ case "1-sngl": $end = date("Y-m-d 23:59:59"); $hint = $a['hint']; break; case "2-ult": $end = date("Y-m-d 23:59:59", strtotime('+7 days')); $hint = $a['hint']; break; case "3-mnth": $end = date("Y-m-d 23:59:59", strtotime('+30 days')); $hint = $a['hint']; break; case "4-ssn": $end = date("Y-m-d h:i:s", strtotime($a['exp'])); $hint = $a['hint']; break; case "5-po": $end = date("Y-m-d h:i:s", strtotime($a['exp'])); $hint = $a['hint']; break; case "6-spl": $Ddate = date("Y-m-d"); $firstDate = date("Y-m-01"); $lastDate = date("Y-m-d", strtotime("-1 Day")); $Dtime = date("H:i"); $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start = '".date("Y-m-d")."'"; $w1 = mysql_query($query1); $numrows = mysql_num_rows($w1); if($numrows == 0 ){ //echo "No special for today"; $query3 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start BETWEEN '$firstDate' AND '$lastDate' ORDER BY id DESC LIMIT 1"; $w3 = mysql_query($query3); while($b3 = mysql_fetch_array($w3)){ $id = $b3['id']; $end = date("Y-m-d h:i:s", strtotime($b3['exp'])); $id = $b3['id']; $name = $b3['name']; $package = $b3['package']; $start = date("Y-m-d h:i:s"); $hint = $b2['hint']; $price = $b3['price']; } } elseif($numrows > 0){ //echo "There is a special for today<br />"; $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start = '".date("Y-m-d")."' AND '".date("H:i")."' >= starttime ORDER BY starttime DESC LIMIT 1"; $w1 = mysql_query($query1); $numrows = mysql_num_rows($w1); if($numrows == 0 ) { //echo "Special for today hasn't started yet<br />"; $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start BETWEEN '$firstDate' AND '$lastDate' ORDER BY id DESC LIMIT 1"; $w1 = mysql_query($query1); } while($b2 = mysql_fetch_array($w1)){ //echo "Start time: $b2[starttime]<br />Current time: $Dtime<br />Special for current time"; $id = $b2['id']; $end = date("Y-m-d h:i:s", strtotime($b2['exp'])); $id = $b2['id']; $name = $b2['name']; $package = $b2['package']; $start = date("Y-m-d h:i:s"); $hint = $b2['hint']; $price = $b2['price']; } } break; } ?> <tr> <td height="25" align="left" valign="middle"> <span class="purchase"> <?php if($a['price'] == "") { $price = ""; $price_box = "<input name='package_[$name]' type='checkbox' value='$package,$price,$end,$sport' disabled/>"; $dollar = ""; echo $price_box." ".$name; } else { $price1 = number_format ($price, 2); $price = $price1; $price_box = "<input name='package_[$name]' type='checkbox' value='$package,$price,$end,$sport,$id'/>"; $dollar = "$"; echo $price_box." ".$name; } if($hint == "") { } else { ?> <a href="#" onMouseOver="showhint('<?=$hint; ?>', this, event, '200px')">[?]</a> <?php } ?> <br /> </span></td> <td width="55" align="right" valign="middle"><span class="purchase"><?=$dollar;?><?=$price;?> </span></td> </tr> <?php }; ?> </table> <span class="purchase"></span></td> </tr> </table> </td> </tr> </table> <br /> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2009 Share Posted May 6, 2009 When you did a "view source" of the page in your browser to check it, was there data everywhere you expected? Does the data possibly contain any HTML characters <, >, ", or ' that could break the HTML on your page? Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827622 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 $hint = $b2['hint']; Did you mean $b3['hint']? Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827624 Share on other sites More sharing options...
timmah1 Posted May 6, 2009 Author Share Posted May 6, 2009 If I echo everything out, it shows with no problem. When you mouseover the [?] on the page, it shows the hint It does that with the top 5, but not the last You can see what I mean here if you want https://www.secure.vegasdsports.com/test/ Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827626 Share on other sites More sharing options...
timmah1 Posted May 6, 2009 Author Share Posted May 6, 2009 I correct that Ken2k7, but it's still not showing Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827627 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Which is the last one? Wednesday's NBA Basketball 2 Games Playoff Special [?] ^ Is that it? Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827630 Share on other sites More sharing options...
timmah1 Posted May 6, 2009 Author Share Posted May 6, 2009 Correct That one is this code case "6-spl": $Ddate = date("Y-m-d"); $firstDate = date("Y-m-01"); $lastDate = date("Y-m-d", strtotime("-1 Day")); $Dtime = date("H:i"); $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start = '".date("Y-m-d")."'"; $w1 = mysql_query($query1); $numrows = mysql_num_rows($w1); if($numrows == 0 ){ //echo "No special for today"; $query3 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start BETWEEN '$firstDate' AND '$lastDate' ORDER BY id DESC LIMIT 1"; $w3 = mysql_query($query3); while($b3 = mysql_fetch_array($w3)){ $id = $b3['id']; $end = date("Y-m-d h:i:s", strtotime($b3['exp'])); $id = $b3['id']; $name = $b3['name']; $package = $b3['package']; $start = date("Y-m-d h:i:s"); $hint = $b3['hint']; $price = $b3['price']; } } elseif($numrows > 0){ //echo "There is a special for today<br />"; $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start = '".date("Y-m-d")."' AND '".date("H:i")."' >= starttime ORDER BY starttime DESC LIMIT 1"; $w1 = mysql_query($query1); $numrows = mysql_num_rows($w1); if($numrows == 0 ) { //echo "Special for today hasn't started yet<br />"; $query1 = "SELECT * FROM packages1 WHERE sport = '$sport' AND start BETWEEN '$firstDate' AND '$lastDate' ORDER BY id DESC LIMIT 1"; $w1 = mysql_query($query1); } while($b2 = mysql_fetch_array($w1)){ //echo "Start time: $b2[starttime]<br />Current time: $Dtime<br />Special for current time"; $id = $b2['id']; $end = date("Y-m-d h:i:s", strtotime($b2['exp'])); $id = $b2['id']; $name = $b2['name']; $package = $b2['package']; $start = date("Y-m-d h:i:s"); $hint = $b2['hint']; $price = $b2['price']; } } break; Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827631 Share on other sites More sharing options...
timmah1 Posted May 6, 2009 Author Share Posted May 6, 2009 I echoed out the hints on that page so if you go to it, you'll see that it does show Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827634 Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2009 Share Posted May 6, 2009 Does the data possibly contain any HTML characters <, >, ", or ' that could break the HTML on your page? Well it does. You must use htmlentities() with the second parameter ENT_QUOTES when you output content that could contain HTML special characters. Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827637 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 ^ read above. To explain why - the single quote in Wednesday's is killing your single quote in your JavaScript. Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827640 Share on other sites More sharing options...
timmah1 Posted May 6, 2009 Author Share Posted May 6, 2009 ok, I have this now <a href="#" onMouseOver="showhint('<?=htmlentities($hint, ENT_QUOTES); ?>', this, event, '200px')">[?]</a><br />THIS IS THE HINT<br /><?=$hint; ?> And it still doesn't show Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827644 Share on other sites More sharing options...
Brian W Posted May 6, 2009 Share Posted May 6, 2009 Theory, 'hint' isn't the name of the field... idk, maybe way off. (remember, if its 'Hint', 'hint' wont work) while($b3 = mysql_fetch_array($w3)){ die(nl2br(print_r($b3, TRUE)));//This will kill the application and feed out the variables, copy and paste the output into a reply. $id = $b3['id']; $end = date("Y-m-d h:i:s", strtotime($b3['exp'])); $id = $b3['id']; $name = $b3['name']; $package = $b3['package']; $start = date("Y-m-d h:i:s"); $hint = $b3['hint']; $price = $b3['price']; } Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827646 Share on other sites More sharing options...
timmah1 Posted May 6, 2009 Author Share Posted May 6, 2009 hint is the field name, all lowercase Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827649 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Oops, I thought ... nevermind. Overlooked his function. Use htmlspecialchars($hint, ENT_QUOTES). Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827653 Share on other sites More sharing options...
timmah1 Posted May 6, 2009 Author Share Posted May 6, 2009 ok, I figured it out When it's being put in, it's inputting it normal in the database Wednesday's 2 Game Playoff Special Now, when I echo it out, I did this $hint = addslashes($b3['hint']); htmlentities($hint, ENT_QUOTES); And it works now. Thank you for your help Link to comment https://forums.phpfreaks.com/topic/157102-solved-variable-shows-but-not-for-all/#findComment-827656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.