am i displaying the date right?

if (isset($_POST['submit']))  {
$YEAR = $_POST['YEAR']; 
$MONTH = $_POST['MONTH']; 
$DAY = $_POST['DAY'];
}


if (isset($Submit))
{
$query = "SELECT * FROM tracker WHERE timespan LIKE 'YEAR-MONTH-DAY%'";

    brett, im totally lost 🙁...
    here is my attempt to mysql_num_row... not looking very good. i have no clue where to start. i've never used this command before.

    <?php
    
    require('sql.php');
    
    if (isset($_POST['submit']))  {
    $YEAR = $_POST['YEAR']; 
    $MONTH = $_POST['MONTH']; 
    $DAY = $_POST['DAY'];
    }
    
    
    if (isset($Submit))
    {
    $result=mysql_query("SELECT * FROM tracker WHERE start = '1' ORDER BY id DESC LIMIT 1") or die ("Cannot execute the query");
    //$query = "SELECT * FROM tracker WHERE timespan LIKE 'YEAR-MONTH-DAY %'";
    $result = mysql_query($query);
    
    }
    echo "<table border='1'>\n 
    \t<tr><th>id</th><th>home</th><th>start</th><th>end</th><th>timespan</th></tr>\n";
    if (mysql_num_rows($result)>0) { 
        while($row=mysql_fetch_array($result)) { 
    	echo " 
    \t<tr>\n 
    \t\t<td>".$row['id']."</td>\n 
    \t\t<td>".$row['home']."</td>\n
    \t\t<td>".$row['start']."</td>\n 
    \t\t<td>".$row['end']."</td>\n  
    \t\t<td>".$row['timespan']."</td>\n \t</tr>\n\n"; echo " </table>"; } } ?>

      This:

      "SELECT * FROM tracker WHERE timespan LIKE 'YEAR-MONTH-DAY%'";

      should be:

      "SELECT * FROM tracker WHERE timespan LIKE '".$YEAR."-".$MONTH."-".$DAY."%'";

        i still get the error msg even with the SELECT update...
        i dont see what im doing wrong... 😕

          add an "or die(mysql_error())" statement to the query call.

            awesome everything is working! 🙂
            but can you further explain to me how to get the "mysql_num_rows" command to work?
            so that i dont have a big list of 0-1-0's?

            here is my current code

            <?php
            
            require('sql.php');
            
            if (isset($_POST['submit']))  {
            $YEAR = $_POST['YEAR']; 
            $MONTH = $_POST['MONTH']; 
            $DAY = $_POST['DAY'];
            }
            
            
            if (isset($submit))
            {
            $query = "SELECT * FROM tracker WHERE timespan LIKE '".$YEAR."-".$MONTH."-".$DAY."%'"; 
            $res = mysql_query($query) or die("couldn't perform $query");
            }
            echo "<table border='1'>\n 
            \t<tr><th>id</th><th>home</th><th>start</th><th>end</th><th>timespan</th></tr>\n";
            
            while($r=mysql_fetch_array($res)) { 
                echo " 
            \t<tr>\n 
            \t\t<td>".$r['id']."</td>\n 
            \t\t<td>".$r['home']."</td>\n
            \t\t<td>".$r['start']."</td>\n 
            \t\t<td>".$r['end']."</td>\n  
            \t\t<td>".$r['timespan']."</td>\n \t</tr>\n\n"; } echo " </table>"; ?>

              I'd love to!

              One question:
              Where are you using it, and how are you using it?

                well basically, my current code counts the amount of clicks on my flash site.
                so when someone clicks a link, it keeps record and displays in a table, like this:
                (id:1)(home=0) (start=1) (end=0) 2006-01-26
                (id:2)(home=1) (start=0) (end=0) 2006-01-26

                (id:3)(home=0) (start=1) (end=0) 2006-01-26

                (id:4)(home=0) (start=0) (end=1) 2006-01-26

                but, i want to have it so it displays all the clicks of a certain section of that day
                in one row, like this instead:
                (id:1)(home=23) (start=0) (end=0) 2006-01-26
                (id:2)(home=0) (start=12) (end=0) 2006-01-26

                from my research mysql_num_rows seems to be the solution to this... but i dont know where to input that command in my code.
                let me know if i'm being unclear.

                any ideas?

                  SELECT COUNT(home) AS c_home, COUNT(start) AS c_start, COUNT(end) AS c_end
                  FROM tracker
                  WHERE timespan LIKE '$year-$month-$day'

                  Then reference each as:
                  c_home = 23
                  c_start = 12
                  c_end = 0

                  So you'd say:

                  <?php
                  $query = "SELECT COUNT(home) AS c_home, COUNT(start) AS c_start, COUNT(end) AS c_end
                  FROM tracker
                  WHERE timespan LIKE '".$year."-".$month."-".$day."'";
                  
                  $result = mysql_query($query) or die(mysql_error());
                  $row = mysql_fetch_array($result);
                  echo 'Home: '.$row['c_home'].'<br>Start: '.$row['c_start'].'<br>End: '.$row['c_end'];
                  ?>
                    <?php
                    
                    $start = 0;
                    $home = 0;
                    $end = 0;
                    
                    while($row = mysql_fetch_array($results))
                    {
                      $start = ($row['start']>0)?$start+$row['start']:$start;
                      $end = ($row['end']>0)?$end+$row['end']:$end;
                      $home = ($row['home']>0)?$home+$row['home']:$home;
                    }
                    
                    echo 'Start: '.$start.'<br>End: '.$end.'<br>Home: '.$home;
                    ?>

                      am i suppose to replace my old count code?

                      <?php 
                      $query = "SELECT COUNT(home) AS c_home, COUNT(start) AS c_start, COUNT(end) AS c_end 
                      FROM tracker 
                      WHERE timespan LIKE '".$year."-".$month."-".$day."'"; 
                      
                      $result = mysql_query($query) or die(mysql_error()); 
                      $row = mysql_fetch_array($result); 
                      echo 'Home: '.$row['c_home'].'<br>Start: '.$row['c_start'].'<br>End: '.$row['c_end']; 
                      ?> 

                      am i on the right track?

                       $start = 0; 
                      $home = 0; 
                      $end = 0; 
                      
                      { 
                        $start = ($row['c_start']>0)?$start+$row['c_start']:$start; 
                        $end = ($row['c_end']>0)?$end+$row['c_end']:$end; 
                        $home = ($row['c_home']>0)?$home+$row['c_home']:$home; 
                      } 
                      
                      echo 'Start: '.$start.'<br>End: '.$end.'<br>Home: '.$home; 

                        Yes, you should replace the old code with what I posted.

                          are there anymore hints you can give me, please? 😕

                            ive been playing with it but i still cant figure it out.... 🙁

                              No, you're not on the right track.... do this:

                              <?php
                              
                              // Include database connection stuff here
                              $home = $start = $end = 0; // Default to 0
                              
                              $query = "SELECT * FROM tracker WHERE timespan LIKE '".$year."-".$month."-".$day."'";
                              $result = mysql_query($query) or die('Oh My Gosh!!! mySQL threw an error!! Here you go!!<br>'.mysql_error());
                              while($row = mysql_fetch_array($result))
                              {
                                $start = ($row['start']>0)?$start+$row['start']:$start;
                                $end = ($row['end']>0)?$end+$row['end']:$end;
                                $home = ($row['home']>0)?$home+$row['home']:$home;
                              }
                              
                              echo 'Home: '.$home.'<br>End: '.$end.'<br>Start: '.$start;
                              ?>

                                Thank You Soooooooo much Brett!
                                I seriously can't thank you enough, thanks for having patients with me.

                                  Write a Reply...