SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    While after While is Empty

    Hi

    Im am trying to get a chart from Fusion Charts to diplay correctly.

    Il try here, since the support on fusion Charts page is lacking..

    Im selecting to dates and showing the bodyweight variation between the dates.

    I can create the array of dates in the while, but the bodyweight does return anything.

    HTML
    Code HTML4Strict:
    <form method="post" action="index.php?action=profile&sub=stats_bw&id=<?php echo $USER_PROFILE->getId(); ?>"> 
     
    	<table border="0">
        <tr>
        <td>
        <b><?php echo translate('from'); ?></b>	<select id="day" name="fromday">
                <option value=""><?php echo ucfirst(translate('day')); ?></option>
                <?php
                for($i=1; $i<=31; $i++)
                {
                    if($i == $blog['fromday'])
                    {
                        echo "<option value=\"" . $i . "\" selected=\"selected\">" . $i . "</option>\n";
                    }
                    else
                    {
                        echo "<option value=\"" . $i . "\">" . $i . "</option>\n";
                    }
                }
                ?>
            </select>
     
            <select id="month" name="frommonth">
                <option value=""><?php echo ucfirst(translate('month')); ?></option>
                <?php
                foreach($MONTHS as $k => $v)
                {
                    if(($k+1) == $blog['frommonth'])
                    {
                        echo "<option value=\"" . ($k+1) . "\" selected=\"selected\">" . ucfirst(translate($v)) . "</option>\n";
                    }
                    else
                    {
                        echo "<option value=\"" . ($k+1) . "\">" . ucfirst(translate($v)) . "</option>\n";
                    }
                }
                ?>
            </select>
     
            <select id="year" name="fromyear">
                <option value=""><?php echo ucfirst(translate('year')); ?></option>
                <?php
                for($i=date('Y', $time_now); $i>=(date('Y', $time_now) - 11); $i--)
                {
                    if($i == $blog['fromyear'])
                    {
                        echo "<option value=\"" . $i . "\" selected=\"selected\">" . $i . "</option>\n";
                    }
                    else
                    {
                        echo "<option value=\"" . $i . "\">" . $i . "</option>\n";
                    }
                }
                ?>
            </select> 
        </td>
            <td>
            <b><?php echo translate('to'); ?></b>
            <select id="day" name="today">
            <option value=""><?php echo ucfirst(translate('day')); ?></option>
            <?php
            for($i=1; $i<=31; $i++)
            {
                if($i == $blog['today'])
                {
                    echo "<option value=\"" . $i . "\" selected=\"selected\">" . $i . "</option>\n";
                }
                else
                {
                    echo "<option value=\"" . $i . "\">" . $i . "</option>\n";
                }
            }
            ?>
        	</select>
     
            <select id="month" name="tomonth">
                <option value=""><?php echo ucfirst(translate('month')); ?></option>
                <?php
                foreach($MONTHS as $k => $v)
                {
                    if(($k+1) == $blog['tomonth'])
                    {
                        echo "<option value=\"" . ($k+1) . "\" selected=\"selected\">" . ucfirst(translate($v)) . "</option>\n";
                    }
                    else
                    {
                        echo "<option value=\"" . ($k+1) . "\">" . ucfirst(translate($v)) . "</option>\n";
                    }
                }
                ?>
            </select>
     
            <select id="year" name="toyear">
                <option value=""><?php echo ucfirst(translate('year')); ?></option>
                <?php
                for($i=date('Y', $time_now); $i>=(date('Y', $time_now) - 11); $i--)
                {
                    if($i == $blog['toyear'])
                    {
                        echo "<option value=\"" . $i . "\" selected=\"selected\">" . $i . "</option>\n";
                    }
                    else
                    {
                        echo "<option value=\"" . $i . "\">" . $i . "</option>\n";
                    }
                }
                ?>
            </select>     
            <td>
            <input type="hidden" name="user_id" value="<?php echo $USER_PROFILE->getId(); ?>"  />
            <input type="submit" style="font-weight:bold;" name="select" value=" <?php echo ucf(translate('show')); ?> "  />
            </td>
        </table>
    </form>


    Here is the code after the submit...
    PHP Code:
    if(isset($_POST['select']))
    {
        
        
    $blog['fromday']=$_POST['fromday'];
        
    $blog['frommonth']=$_POST['frommonth'];
        
    $blog['fromyear']=$_POST['fromyear'];
        
    $fromdate mktime(date('H'$time_now), date('i'$time_now), date('s'$time_now), $blog['frommonth'], $blog['fromday'], $blog['fromyear']);
        
        
    $blog['today']=$_POST['today'];
        
    $blog['tomonth']=$_POST['tomonth'];
        
    $blog['toyear']=$_POST['toyear'];
        
    $todate mktime(date('H'$time_now), date('i'$time_now), date('s'$time_now), $blog['tomonth'], $blog['today'], $blog['toyear']);

        
    $user_id $_POST['user_id'];

    echo 
    "<br />";
        
        
    // Get all the data
        
    $result mysql_query("SELECT 
        training.date, 
        training.training_id,
        training.place,
        training.bodyweight
        FROM lifts, training
        WHERE training.training_id=lifts.training_id AND training.user_id ="
    $user_id ." AND training.date > " $fromdate " AND training.date < " $todate "
        ORDER BY training.date"
    ) or die(mysql_error());

    $num mysql_num_rows($result);
    $i=1;
    $strXML "<chart caption='" ucf(translate('bodyweight')) . "' subCaption='" ucf(translate('for')) . " " getNameFromId($USER_PROFILE->getId()) . "' showBorder='1' formatNumberScale='0' numberSuffix='"$w_metric ."' baseFont='Arial' exportEnabled='1' exportAtClient='0' exportHandler='Charts/ExportHandlers/PHP/FCExporter.php' exportAction='download' exportTargetWindow='_blank' exportFileName='" ucf(translate('bodyweight')) . "'>";
    $row mysql_fetch_array($result);

    if(
    $i <= $num)


            
    $strXML .= "<categories>";
            while(
    $row mysql_fetch_array($result))
            {
                if(
    $w_metric == "kg")
                    {
                     
    $strXML .= "<category label='" formatDate($row['date'], $dateformat) . "' />";
                    }
                    else
                    {
                    
    $strXML .= "<category label='" formatDate($row['date'], $dateformat) . "' />";
                    }
            }
            
    $strXML .= "</categories>";
            
            
    $strXML .= "<dataset seriesName='Bw'>";
            while(
    $row mysql_fetch_array($result)) // Is empty :(
            
    {
                if(
    $w_metric == "kg")
                    {
                     
    $strXML .= "<set value='" $row['bodyweight'] . "' />";
                     echo 
    "teste";
                    }
                    else
                    {
                    
    $strXML .= "<set value='" r_nr(calcFromKg($row['bodyweight'])) . "' />";
                    }
            }
            
    $strXML .= "</dataset></chart>"//</dataset> doesnt show, strange..
                
            
            
    echo renderChart("Charts/ZoomLine.swf"""$strXML"".ucf(translate('bodyweight')).""90040011);
            echo 
    "<div class='fixed'>
                                </div>
                            </div>
                            </div>
                        <div class='fixed'>
                        </div>
                        <div id='footer'>
                        <a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" 
    translate('top') . "</a>
                            <div align='center' id='copyright'>&copy; " 
    translate('copyrightyear') . " " translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" translate('contact') ."</a> - <a href='index.php?action=about'>" translate('about') . "</a> - " translate('onlineusers'). ": " getActiveUsers() . "<br />
                            </div>"
    ;
                exit;
                

    XML debug, as you can see the <dataset> tag return empty
    Code XML:
    <chart caption="Kroppsvekt" subCaption="For Stian Walgermo" showBorder="1" formatNumberScale="0" numberSuffix="kg" baseFont="Arial" exportEnabled="1" exportAtClient="0" exportHandler="Charts/ExportHandlers/PHP/FCExporter.php" exportAction="download" exportTargetWindow="_blank" exportFileName="Kroppsvekt"><categories><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /><category label="21.02.2011" /></categories><dataset seriesName="Bw" /></chart>

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your second while is returning zero because you have already passed through the array in with the first while statement.

    You can only parse through the result array once
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    Your second while is returning zero because you have already passed through the array in with the first while statement.

    You can only parse through the result array once
    Is there some other ways to do this?

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,075
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Use mysql_data_seek to reset the pointer on the result to the first row.

    PHP Code:
    while( $row=mysql_fetch_assoc($result) )
    {
       
    // ...
    }
    mysql_data_seek($result0);
    while( 
    $row=mysql_fetch_assoc($result) )
    {
       
    // ...

    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OR

    just tidy your code.

    PHP Code:
    if(isset($_POST['select'])) 

     
        
    $blog['fromday']=$_POST['fromday']; 
        
    $blog['frommonth']=$_POST['frommonth']; 
        
    $blog['fromyear']=$_POST['fromyear']; 
        
    $fromdate mktime(date('H'$time_now), date('i'$time_now), date('s'$time_now), $blog['frommonth'], $blog['fromday'], $blog['fromyear']); 
     
        
    $blog['today']=$_POST['today']; 
        
    $blog['tomonth']=$_POST['tomonth']; 
        
    $blog['toyear']=$_POST['toyear']; 
        
    $todate mktime(date('H'$time_now), date('i'$time_now), date('s'$time_now), $blog['tomonth'], $blog['today'], $blog['toyear']); 
     
        
    $user_id $_POST['user_id']; 
     
    echo 
    "<br />"
     
        
    // Get all the data 
        
    $result mysql_query("SELECT  
        training.date,  
        training.training_id, 
        training.place, 
        training.bodyweight 
        FROM lifts, training 
        WHERE training.training_id=lifts.training_id AND training.user_id ="
    $user_id ." AND training.date > " $fromdate " AND training.date < " $todate 
        ORDER BY training.date"
    ) or die(mysql_error()); 
     
    $strXML "<chart caption='" ucf(translate('bodyweight')) . "' subCaption='" ucf(translate('for')) . " " getNameFromId($USER_PROFILE->getId()) . "' showBorder='1' formatNumberScale='0' numberSuffix='"$w_metric ."' baseFont='Arial' exportEnabled='1' exportAtClient='0' exportHandler='Charts/ExportHandlers/PHP/FCExporter.php' exportAction='download' exportTargetWindow='_blank' exportFileName='" ucf(translate('bodyweight')) . "'>"
     
    if(
    mysql_num_rows($result) > 0
    {  
            
    $catstrXML "<categories>";  // make category substring
            
    $datastrXML "<dataset seriesName='Bw'>"// make dataset substring
     
            
    while($row mysql_fetch_array($result)){  // loop through data
                   
    $catstrXML .= "<category label='" formatDate($row['date'], $dateformat) . "' />";   // category always same so no need to be within if KG statements
                   
    if($w_metric == "kg"){ 
                       
    $datastrXML .= "<set value='" $row['bodyweight'] . "' />"
                   }else{ 
                       
    $datastrXML .= "<set value='" r_nr(calcFromKg($row['bodyweight'])) . "' />"
                   } 
    // end if
            
    // end while
            
    $catstrXML .= "</categories>"// finish substring
            
    $datastrXML .= "</dataset>"// finish substring
            
    $strXML .= $catstrXML $datastrXML "</chart>";  // add substrings to main string
     
     
            
    echo renderChart("Charts/ZoomLine.swf"""$strXML"".ucf(translate('bodyweight')).""90040011); 
            echo 
    "<div class='fixed'> 
                                </div> 
                            </div> 
                            </div> 
                        <div class='fixed'> 
                        </div> 
                        <div id='footer'> 
                        <a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" 
    translate('top') . "</a> 
                            <div align='center' id='copyright'>&copy; " 
    translate('copyrightyear') . " " translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" translate('contact') ."</a> - <a href='index.php?action=about'>" translate('about') . "</a> - " translate('onlineusers'). ": " getActiveUsers() . "<br /> 
                            </div>"

                exit; 
     

    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    OR

    just tidy your code.

    PHP Code:
    if(isset($_POST['select'])) 

     
        
    $blog['fromday']=$_POST['fromday']; 
        
    $blog['frommonth']=$_POST['frommonth']; 
        
    $blog['fromyear']=$_POST['fromyear']; 
        
    $fromdate mktime(date('H'$time_now), date('i'$time_now), date('s'$time_now), $blog['frommonth'], $blog['fromday'], $blog['fromyear']); 
     
        
    $blog['today']=$_POST['today']; 
        
    $blog['tomonth']=$_POST['tomonth']; 
        
    $blog['toyear']=$_POST['toyear']; 
        
    $todate mktime(date('H'$time_now), date('i'$time_now), date('s'$time_now), $blog['tomonth'], $blog['today'], $blog['toyear']); 
     
        
    $user_id $_POST['user_id']; 
     
    echo 
    "<br />"
     
        
    // Get all the data 
        
    $result mysql_query("SELECT  
        training.date,  
        training.training_id, 
        training.place, 
        training.bodyweight 
        FROM lifts, training 
        WHERE training.training_id=lifts.training_id AND training.user_id ="
    $user_id ." AND training.date > " $fromdate " AND training.date < " $todate 
        ORDER BY training.date"
    ) or die(mysql_error()); 
     
    $strXML "<chart caption='" ucf(translate('bodyweight')) . "' subCaption='" ucf(translate('for')) . " " getNameFromId($USER_PROFILE->getId()) . "' showBorder='1' formatNumberScale='0' numberSuffix='"$w_metric ."' baseFont='Arial' exportEnabled='1' exportAtClient='0' exportHandler='Charts/ExportHandlers/PHP/FCExporter.php' exportAction='download' exportTargetWindow='_blank' exportFileName='" ucf(translate('bodyweight')) . "'>"
     
    if(
    mysql_num_rows($result) > 0
    {  
            
    $catstrXML "<categories>";  // make category substring
            
    $datastrXML "<dataset seriesName='Bw'>"// make dataset substring
     
            
    while($row mysql_fetch_array($result)){  // loop through data
                   
    $catstrXML .= "<category label='" formatDate($row['date'], $dateformat) . "' />";   // category always same so no need to be within if KG statements
                   
    if($w_metric == "kg"){ 
                       
    $datastrXML .= "<set value='" $row['bodyweight'] . "' />"
                   }else{ 
                       
    $datastrXML .= "<set value='" r_nr(calcFromKg($row['bodyweight'])) . "' />"
                   } 
    // end if
            
    // end while
            
    $catstrXML .= "</categories>"// finish substring
            
    $datastrXML .= "</dataset>"// finish substring
            
    $strXML .= $catstrXML $datastrXML "</chart>";  // add substrings to main string
     
     
            
    echo renderChart("Charts/ZoomLine.swf"""$strXML"".ucf(translate('bodyweight')).""90040011); 
            echo 
    "<div class='fixed'> 
                                </div> 
                            </div> 
                            </div> 
                        <div class='fixed'> 
                        </div> 
                        <div id='footer'> 
                        <a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" 
    translate('top') . "</a> 
                            <div align='center' id='copyright'>&copy; " 
    translate('copyrightyear') . " " translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" translate('contact') ."</a> - <a href='index.php?action=about'>" translate('about') . "</a> - " translate('onlineusers'). ": " getActiveUsers() . "<br /> 
                            </div>"

                exit; 
     

    Yes, thanks Works perfect now

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems like it creates dublicate values for date and bodyweight..

  8. #8
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Show me whats in your database table and a sample XML output for that data

    Confirm that you using my code above if you have modified it post the current version
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    Show me whats in your database table and a sample XML output

    Are you using my code above or have you modified it ?
    I figured it out

    Had to add DISTINCT to this query

    // Get all the data
    $result = mysql_query("SELECT DISTINCT <-- Here
    training.date,
    training.training_id,
    training.place,
    training.bodyweight
    FROM lifts, training
    WHERE training.training_id=lifts.training_id AND training.user_id =". $user_id ." AND training.date > " . $fromdate . " AND training.date < " . $todate . "
    ORDER BY training.date") or die(mysql_error());

  10. #10
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, but I wouldnt have thought youd have need that, perhaps youve a problem with your database layout ?
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •