Jump to content

[SOLVED] Variable shows, but not for all


timmah1

Recommended Posts

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

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/

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;

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.

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'];
                        }

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.