SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Values not selecting properly from DB

    Hi all,

    I'm working with Shawngo's donation script and am having some problems reading the db field values.

    my DB reports 1 row with values present for both 'goal' and 'actual.' when I change $num_rows from == 1 to == 0 all negative values appear. so it's kinda working :/ there must be something wrong with my code below.

    here is everything i'm working with. any help would be appreciated!

    Code:
    <?
    	/* insert your own connection info here */
    	$database="progress";  
    	mysql_connect ("localhost", "root", "admin");  
    	@mysql_select_db($database) or die( "Unable to select database");  
    	$sql = "SELECT * FROM sales_rep";
    	$results = mysql_query($sql);
    	$num_rows = @mysql_num_rows($results);
    	if($num_rows == 1){
    		$pm_data = @mysql_fetch_assoc($results);
    		$upper_bound = $pm_data['goal'];
    		$progress_amount = $pm_data['actual'];
    		$median = $upper_bound / 2;
    		/* if our upper bound is greater than the goal,
    		   we need to display that somehow to our user */
    		$class = ($progress_amount >= $upper_bound) ? ' class="beyond"' : '';
    		$percent_complete = ($progress_amount / $upper_bound) * 100;
    		$percent_complete = $percent_complete > 100 ? 100 : $percent_complete;
    
    		$median = '$'.number_format($median,0,'',',');
    		$upper_bound = '$'.number_format($upper_bound,0,'',',');
    		$progress_amount = '$'.number_format($progress_amount,0,'',',');
    		$show_progress_meter = true;
    
    	}
    
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>  
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    	<meta name="MSSmartTagsPreventParsing" content="true" /> 
    	<title>Dwight Donation Progress</title>  
    	<link rel="stylesheet" href="css/style.css" type="text/css" /> 	
    	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
    	<link rel="shortcut icon" href="ico/favicon.ico">
    	<style type="text/css"> 
    		* {margin:0pt;padding:0pt;}
    		body {font-family:Arial,Helvetica,sans-serif;font-size:12px;}
    		#progress {height:34px;margin-bottom:11px;}
    		.pad {margin:0pt auto;width:900px;}
    		#progress h3 {float:left;height:22px;margin:6px 6px 0pt 0pt;width:106px;}
    		.hide {float:left;margin-left:-999em;}
    		#progressBar {background:transparent url(progressBg.gif) repeat-x scroll left top;border:1px solid #000000;float:left;height:16px;margin-top:7px;width:608px;}
    		#progressBar #mercury {width:0&#37;;}#progressBar #mercury {background:transparent url(mercuryBg.gif) repeat-x scroll left top;border-right:1px solid #AC7B00;height:16px;}
    		#progressBar #mercury span {display:block;float:right;font-size:10px;height:16px;line-height:16px;padding:0pt 5px 0pt 0pt;text-align:right;width:95px;}
    		#progress #key div {float:left;font-size:10px;width:22%;}
    		#progress #center {text-align:center;}
    		#progress #right {text-align:right;width:23.9% !important;}
    		#progressBar #mercury .beyond {background:transparent url(beyond.gif) no-repeat scroll right top;font-size:11px;font-weight:bold;}
    		p{ width:auto !important;}
    	</style> 
    	<script type="text/javascript">
    		$(document).ready(function(){ // on document load
    			// Using multiple unit types within one animation.
    			$("#mercury").animate({width: "<?=$percent_complete?>%"}, 1000 ); // animate a div
    		});
    	</script>
    </head>  
    <body>  
    <div id="progress"> 
    	<div class="pad"> 
            <h3><span class="hide">Progress Meter</span></h3> 
            <div id="progressBar"> 
             	<div id="mercury"><span><?=$progress_amount?></span></div> 
            </div> 
            <div id="seasonal"> </div> 
            <div id="key"> 
                <div id="left">$0</div> 
                <div id="center"><?=$median?></div> 
                <div id="right"><?=$upper_bound?></div> 
            </div>         
        </div> 
    </div> 
    </body>
    </html>

  2. #2
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    opps. looks like I'm ok. I had forgotten to include LIMIT 0,1
    sry for the waste of space


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •