Jump to content

MySQL num rows based on two tables


CravenBW

Recommended Posts

I'm trying to get the number of rows based on two tables... it's not quite working right. Can anyone see anything wrong with the code below or give me another idea by any chance? The date stuff still needs some work but it works for right now. My main issue right now is getting active working which checks for usernames that are both signed up and validated then is supposed to take those usernames and see if they've logged in more then 1 time but that part isn't working. :-(

[code]<?php
print '<table cellspacing="5px" style="text-align: center;"><tr style="text-align: left;"><td><b>DATE</b></td><td><b>SIGNUP</b></td><td><b>VALIDATED</b></td><td><b>ACTIVE</b></td></tr>';

$link = mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("database", $link);

$date = date("mdY",strtotime("-10 day"));
$today = date("mdY:");

while($date < $today) {
  $sign = mysql_query("SELECT * FROM users WHERE signdate LIKE '$date%'");

  $validate = mysql_query("SELECT * FROM users WHERE validate != '' AND signdate LIKE '$date%'");
  $active = mysql_query("SELECT username FROM users WHERE validate LIKE '$today%' AND signdate LIKE '$today%'");
 
    print '<tr><td><b>'.substr($date,0,2).'/'.substr($date,2,2).'/'.substr($date,4).'</b></td>';

    print '<td>'.mysql_num_rows($sign).'</td>';

    print '<td>'.mysql_num_rows($validate).'</td>';
  while($row = mysql_fetch_array($active)) {
    $numrows = mysql_query("SELECT * FROM ftp WHERE username='$row[username]' AND ftp_logincount >= '2'");
    print '<td>'.mysql_num_rows($numrows).'</td></tr>';
  }

  if ($date < "".date("m",strtotime("-1 month"))."31".date("Y")."") {
    $date = $date + 10000;
  }
  elseif ($date > "".date("m")."00".date("Y")."") {
    $date = $date + 10000;
  }
  elseif ($date = "".date("m",strtotime("-1 month"))."31".date("Y")."") {
    $date = date("m");
    $date .= "01";
    $date .= date("Y");
  }
   
}
print '</table>';
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/26283-mysql-num-rows-based-on-two-tables/
Share on other sites

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.