Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7774589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:25:01+00:00 2026-06-01T17:25:01+00:00

I have spent many days on this problem but I couldn’t fix it, and

  • 0

I have spent many days on this problem but I couldn’t fix it, and am looking for help.
Lets say I have this php-sql:

$sql2= mysql_query("SELECT * FROM jos_comprofiler WHERE id = ".$userid."");
$row2 = mysql_fetch_array($sql2) ;
$bdate= $row2['cb_birthday']; // 2012-03-01 year/month/day

and this function:

function _weeks($date) { 
  global $bdate ;
  $month = substr($date, 0, 2) ;
  $day = substr($date, 3, 2);
  $year = substr($date, 6, 4) ;
  $bmonth = substr($bdate, 5, 2) ;
  $bday = substr($bdate, 8, 2);
  $byear = substr($bdate, 0, 4) ;
  $birthday = gmmktime(0, 0, 0, $bmonth, $bday, $byear);
  $eventdate = gmmktime(0, 0, 0, $month, $day, $year);

  $weeknumber = (int)(($eventdate - $birthday) / (7 * 24 * 60 * 60)) + 1 ;
  return $weeknumber ;
}

and i have 10 submit buttoms to submit dates

if (isset($_POST['submit0'])){
  if ($userid !=0 ){
    $date0 = $_POST['date0'];
    $func_date= _weeks($date0);
    mysql_query(" UPDATE data SET w_dd = '".$func_date."' WHERE id_user= '".$userid."' ");
    $sql= mysql_query("SELECT id_user FROM data WHERE id_user='".$userid."' ");
    $result= mysql_num_rows($sql);
    mysql_query(" UPDATE data SET dd = '".$date0."' WHERE id_user= '".$userid."' ");
  }

  if (isset($_POST['submit1'])){
    if ($userid !=0 ){
      $date1 = $_POST['date1'];
      $func_date= _weeks($date1);
      mysql_query(" UPDATE data SET w_dd = '".$func_date."' WHERE id_user= '".$userid."' ");
      $sql= mysql_query("SELECT id_user FROM data WHERE id_user='".$userid."' ");
      $result= mysql_num_rows($sql);
      mysql_query(" UPDATE data SET dd = '".$date1."' WHERE id_user= '".$userid."' ");
    }

…and so on till submit9 button.

The problem is $bdate in the function , it doesn’t work $bdate like that, but if I try to make a specific date like below, it works like a charm the $func_date.

function _weeks($date){
  $bdate = "2012-03-01";

I even put the $bdate inside function but that didn’t work either.
How can I make this work? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:25:03+00:00Added an answer on June 1, 2026 at 5:25 pm

    Try this

    $userid = ""; // Nuot sure where this is form ;
    $date = "";
    $mysql = new mysqli ( "localhost", "root", "", "db" );
    
    if ($mysql->connect_errno) {
        printf ( "Connect failed: %s\n", $mysql->connect_error );
        exit ();
    }
    
    $result = $mysql->query ( sprintf ( "SELECT cb_birthday FROM jos_comprofiler id = '%s'", $userid ) );
    
    if (! $result) {
        die ( "Error Runing jos_comprofiler query" );
    }
    
    $josProfile = $result->fetch_assoc ();
    
    $_POST ["date0"] = "03/22/2012 "; // Sample
    $_POST ["submit0"] = "oK"; // Sample
    
    for($i = 0; $i < 10; $i ++) {
        if (! isset ( $_POST ["submit$i"] ) || ! isset ( $_POST ["date$i"] )) {
            continue;
        }
        $date = $_POST ["date$i"];
        $weekNumber = weekNumber ( $josProfile ['cb_birthday'], $date );
        if ($userid != 0) {
            $this->query ( sprintf ( "UPDATE data SET w_dd = '%s' ,  dd = '%s'  WHERE id_user= '%s' ", $weekNumber, $date, $userid ) );
        }
    }
    
    function weekNumber($birthDay,$postDate) {
        $postDate = trim($postDate);
        $birthDay = trim($birthDay);
        $postDate = DateTime::createFromFormat('m/d/Y', $postDate);
        $birthDay = DateTime::createFromFormat('Y-m-d', $birthDay);
        $sec = (int) $postDate->format("U") - $birthDay->format("U");   
        return ceil($sec / (60 * 60 * 24 * 7));
    }
    

    You you are having issue with DateTime::createFromFormat and mysqli you can use

    $userid = ""; // Nuot sure where this is form ;
    $date = "";
    
    $result = mysql_query( sprintf ( "SELECT cb_birthday FROM jos_comprofiler id = '%s'", $userid ) );
    $josProfile = mysql_fetch_array($result);
    
    $_POST ["date0"] = "03/22/2012 "; // Sample
    $_POST ["submit0"] = "oK"; // Sample
    
    for($i = 0; $i < 10; $i ++) {
        if (! isset ( $_POST ["submit$i"] ) || ! isset ( $_POST ["date$i"] )) {
            continue;
        }
        $date = $_POST ["date$i"];
        $weekNumber = weekNumber ( $josProfile ['cb_birthday'], $date );
        if ($userid != 0) {
           mysql_query( sprintf ( "UPDATE data SET w_dd = '%s' ,  dd = '%s'  WHERE id_user= '%s' ", $weekNumber, $date, $userid ) );
        }
    }
    
    
    
    
    function weekNumber($birthDay, $postDate) {
        $postDate = trim ( $postDate );
        $birthDay = trim ( $birthDay );
    
        list($postMonth,$postD,$postYear) = explode("/", $postDate);
        list($birthYear,$birthMonth,$birthD) = explode("-", $birthDay);
    
        $postTime = mktime(0, 0, 0, $postMonth, $postD, $postYear);
        $birthTime =  mktime(0, 0, 0, $birthMonth, $birthD, $birthYear);
    
        $sec = ( int )$postTime - $birthTime;
        return ceil ( $sec / (60 * 60 * 24 * 7) );
    }
    

    Let me know if you have any additional issues

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent many hours looking into this and I still can't find a
I have spent too much time on this problem and am beginning to think
I have asked this question before - but I have spent some time thinking
I have spent the past couple of days working on this and am going
I have spent many hours working on this program that is supposed to play
I realize that this is probably a very basic question, but I have spent
I'm sure this is a common problem for many web applications these days. What
I have spent all Friday and Saturday on this and I am running out
I have spent some time now to solve a problem for which i have
I have spent about half a day searching for an answer to this question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.