Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Aug 2013
    Posts
    196
    Thanks
    14
    Thanked 0 Times in 0 Posts

    This is urgent fo rexpert php and my sql

    I have this code which if it is only one date or two or more differents dates change the color.I need if it is in database 3 same dates to start change the color in red.
    $unavailable[] = $row["date"]; is now to change the color i need $unavailable[] = $row["date"];(same dates 3 times)How can write that code.

    PHP Code:


    <?php
    ###########################################################

    include("config.php");

       
      
      
          
      

    /// get current month and year and store them in $cMonth and $cYear variables
    (intval($_REQUEST["month"])>0) ? $cMonth $_REQUEST["month"] : $cMonth date("n");
    (
    intval($_REQUEST["year"])>0) ? $cYear $_REQUEST["year"] : $cYear date("Y");

    if (
    $cMonth<10$cMonth '0'.$cMonth;
    // generate an array with all unavailable dates
    $sql "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    $sql_result mysql_query ($sql$connection ) or die ('request "Could not execute SQL query" '.$sql);
    while (
    $row mysql_fetch_assoc($sql_result)) {
        
        
        
    $unavailable[] = $row["date"];
    }

    // generate an array with all unavailable dates
    $sql "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    $sql_result mysql_query ($sql$connection ) or die ('request "Could not execute SQL query" '.$sql);
    while (
    $row mysql_fetch_assoc($sql_result)) {
        
    $unavailable[] = $row["date2"];
    }

    // calculate next and prev month and year used for next / prev month navigation links and store them in respective variables
    $prev_year $cYear;
    $next_year $cYear;
    $prev_month intval($cMonth)-1;
    $next_month intval($cMonth)+1;

    // if current month is Decembe or January month navigation links have to be updated to point to next / prev years
    if ($cMonth == 12 ) {
        
    $next_month 1;
        
    $next_year $cYear 1;
    } elseif (
    $cMonth == ) {
        
    $prev_month 12;
        
    $prev_year $cYear 1;
    }
    ?>
      <table width="100%">
      <tr>
          <td class="mNav"><a href="javascript:LoadMonth('<?php echo $prev_month?>', '<?php echo $prev_year?>')">&lt;&lt;</a></td>
          <td colspan="5" class="cMonth"><?php echo date("F, Y",strtotime($cYear."-".$cMonth."-01")); ?></td>
          <td class="mNav"><a href="javascript:LoadMonth('<?php echo $next_month?>', '<?php echo $next_year?>')">&gt;&gt;</a></td>
      </tr>
      <tr>
      
          <td class="wDays">M</td>
          <td class="wDays">T</td>
          <td class="wDays">W</td>
          <td class="wDays">T</td>
          <td class="wDays">F</td>
          <td class="wDays">S</td>
          <td class="wDays">S</td>
     
     
     </tr>
    <?php 
    $first_day_timestamp 
    mktime(0,0,0,$cMonth,1,$cYear); // time stamp for first day of the month used to calculate 
    $maxday date("t",$first_day_timestamp); // number of days in current month
    $thismonth getdate($first_day_timestamp); // find out which day of the week the first date of the month is
    $startday $thismonth['wday'] ; // 0 is for Sunday and as we want week to start on Mon we subtract 1
    if (!$thismonth['wday']) $startday 7;
    for (
    $i=1$i<($maxday+$startday); $i++) {
        
        if ((
    $i 7) == ) echo "<tr>";
        
        if (
    $i $startday) { echo "<td>&nbsp;</td>"; continue; };
        
        
    $current_day $i $startday 1;
        
        (
    in_array($cYear."-".$cMonth."-".$current_day,$unavailable)) ? $css='booked' $css='available'// set css class name based on date availability
        
        
    echo "<td class='".$css."'>"$current_day "</td>";
        
        if ((
    $i 7) == ) echo "</tr>";
    }
    ?> 
    </table>


    I tried this code
    if($row['COUNT(date)'] > 2 ){
    echo "Date ".$row['date']."</br> Date".$row['date2']."</br> Is occupied " .$row['COUNT(date)']. "times " ;
    echo "<br />";
    }else {
    echo " ";
    }

    and $unavailable[] = ($row['COUNT(date)'] > 3 ); did not work.

  • #2
    Regular Coder
    Join Date
    Aug 2013
    Posts
    196
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Pearl_9 View Post
    I have this code which if it is only one date or two or more differents dates change the color.I need if it is in database 3 same dates to start change the color in red.
    $unavailable[] = $row["date"]; is now to change the color i need $unavailable[] = $row["date"];(same dates 3 times)How can write that code.

    PHP Code:


    <?php
    ###########################################################

    include("config.php");

       
      
      
          
      

    /// get current month and year and store them in $cMonth and $cYear variables
    (intval($_REQUEST["month"])>0) ? $cMonth $_REQUEST["month"] : $cMonth date("n");
    (
    intval($_REQUEST["year"])>0) ? $cYear $_REQUEST["year"] : $cYear date("Y");

    if (
    $cMonth<10$cMonth '0'.$cMonth;
    // generate an array with all unavailable dates
    $sql "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    $sql_result mysql_query ($sql$connection ) or die ('request "Could not execute SQL query" '.$sql);
    while (
    $row mysql_fetch_assoc($sql_result)) {
        
        
        
    $unavailable[] = $row["date"];
    }

    // generate an array with all unavailable dates
    $sql "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    $sql_result mysql_query ($sql$connection ) or die ('request "Could not execute SQL query" '.$sql);
    while (
    $row mysql_fetch_assoc($sql_result)) {
        
    $unavailable[] = $row["date2"];
    }

    // calculate next and prev month and year used for next / prev month navigation links and store them in respective variables
    $prev_year $cYear;
    $next_year $cYear;
    $prev_month intval($cMonth)-1;
    $next_month intval($cMonth)+1;

    // if current month is Decembe or January month navigation links have to be updated to point to next / prev years
    if ($cMonth == 12 ) {
        
    $next_month 1;
        
    $next_year $cYear 1;
    } elseif (
    $cMonth == ) {
        
    $prev_month 12;
        
    $prev_year $cYear 1;
    }
    ?>
      <table width="100%">
      <tr>
          <td class="mNav"><a href="javascript:LoadMonth('<?php echo $prev_month?>', '<?php echo $prev_year?>')">&lt;&lt;</a></td>
          <td colspan="5" class="cMonth"><?php echo date("F, Y",strtotime($cYear."-".$cMonth."-01")); ?></td>
          <td class="mNav"><a href="javascript:LoadMonth('<?php echo $next_month?>', '<?php echo $next_year?>')">&gt;&gt;</a></td>
      </tr>
      <tr>
      
          <td class="wDays">M</td>
          <td class="wDays">T</td>
          <td class="wDays">W</td>
          <td class="wDays">T</td>
          <td class="wDays">F</td>
          <td class="wDays">S</td>
          <td class="wDays">S</td>
     
     
     </tr>
    <?php 
    $first_day_timestamp 
    mktime(0,0,0,$cMonth,1,$cYear); // time stamp for first day of the month used to calculate 
    $maxday date("t",$first_day_timestamp); // number of days in current month
    $thismonth getdate($first_day_timestamp); // find out which day of the week the first date of the month is
    $startday $thismonth['wday'] ; // 0 is for Sunday and as we want week to start on Mon we subtract 1
    if (!$thismonth['wday']) $startday 7;
    for (
    $i=1$i<($maxday+$startday); $i++) {
        
        if ((
    $i 7) == ) echo "<tr>";
        
        if (
    $i $startday) { echo "<td>&nbsp;</td>"; continue; };
        
        
    $current_day $i $startday 1;
        
        (
    in_array($cYear."-".$cMonth."-".$current_day,$unavailable)) ? $css='booked' $css='available'// set css class name based on date availability
        
        
    echo "<td class='".$css."'>"$current_day "</td>";
        
        if ((
    $i 7) == ) echo "</tr>";
    }
    ?> 
    </table>


    I tried this code
    if($row['COUNT(date)'] > 2 ){
    echo "Date ".$row['date']."</br> Date".$row['date2']."</br> Is occupied " .$row['COUNT(date)']. "times " ;
    echo "<br />";
    }else {
    echo " ";
    }

    and $unavailable[] = ($row['COUNT(date)'] > 3 ); did not work.


    Any help pleaeee

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,348
    Thanks
    23
    Thanked 618 Times in 617 Posts
    Do you realize your doing the same select twice in a row?
    PHP Code:
    if ($cMonth<10$cMonth '0'.$cMonth;
    // generate an array with all unavailable dates

    $sql "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    $sql_result mysql_query ($sql$connection ) or die ('request "Could not execute SQL query" '.$sql);
    while (
    $row mysql_fetch_assoc($sql_result)) {
        
    $unavailable[] = $row["date"];
    }

    // generate an array with all unavailable dates
    $sql "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    $sql_result mysql_query ($sql$connection ) or die ('request "Could not execute SQL query" '.$sql);
    while (
    $row mysql_fetch_assoc($sql_result)) {
        
    $unavailable[] = $row["date2"];

    And that your asking for everything in the DB when you only need the date? :
    Code:
    SELECT * FROM
    And I am surprised you never got an error from
    PHP Code:
    $unavailable[] = $row["date"]; 
    All that aside $row['COUNT(date)'] in
    PHP Code:
    $unavailable[] = ($row['COUNT(date)'] > ); 
    is wrong.
    Try:
    $sql = "SELECT `date`, COUNT(`date`) as amount FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    Last edited by sunfighter; 06-27-2014 at 04:08 PM.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    Pearl_9 (06-28-2014)

  • #4
    Regular Coder
    Join Date
    Aug 2013
    Posts
    196
    Thanks
    14
    Thanked 0 Times in 0 Posts

    unavailable days

    Quote Originally Posted by sunfighter View Post
    Do you realize your doing the same select twice in a row?
    PHP Code:
    if ($cMonth<10$cMonth '0'.$cMonth;
    // generate an array with all unavailable dates

    $sql "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    $sql_result mysql_query ($sql$connection ) or die ('request "Could not execute SQL query" '.$sql);
    while (
    $row mysql_fetch_assoc($sql_result)) {
        
    $unavailable[] = $row["date"];
    }

    // generate an array with all unavailable dates
    $sql "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    $sql_result mysql_query ($sql$connection ) or die ('request "Could not execute SQL query" '.$sql);
    while (
    $row mysql_fetch_assoc($sql_result)) {
        
    $unavailable[] = $row["date2"];

    And that your asking for everything in the DB when you only need the date? :
    Code:
    SELECT * FROM
    And I am surprised you never got an error from
    PHP Code:
    $unavailable[] = $row["date"]; 
    All that aside $row['COUNT(date)'] in
    PHP Code:
    $unavailable[] = ($row['COUNT(date)'] > ); 
    is wrong.
    Try:
    $sql = "SELECT `date`, COUNT(`date`) as amount FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
    I tried won't work.








    This url where is calendar and code for counting.http://alooot.com/Kalendar%203-%20Co...mple-page2.php





    php code []



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sample calendar page</title>
    <link href="calendar.css" rel="stylesheet" type="text/css" />
    </head>

    <body>

    <div id="Calendar"> </div>
    <script language="javascript" src="calendar.js"></script>
    <?php
    include("config.php");

    if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
    $start_from = ($page-1) * 20;
    $sql = "SELECT * FROM calendar2 ORDER BY date ASC LIMIT $start_from, 20";
    $rs_result = mysql_query ($sql, $connection);



    ?>
    <table>
    <tr><td></td>
    <?php
    while ($row = mysql_fetch_assoc($rs_result)) {
    ?>
    <tr>

    <td><? //echo $row["date"]; ?></td>
    </tr>
    <?php
    //if
    //($rowdate>10);

    //echo"Those dates are occupied";



    };
    ?>
    </table>

    </body>
    </html>


    <?php
    // Make a MySQL Connection



    // Print out result
    //while($row = mysql_fetch_array($result)){
    //echo "ima ". $row['COUNT(date)'] ." ". $row['date'] ." .";
    //echo "<br />";


    // Make a MySQL Connection

    //$query = "SELECT date, COUNT(date) FROM calendar GROUP BY date";
    //
    //$result = mysql_query($query) or die(mysql_error());
    //
    //// Print out result
    //while($row = mysql_fetch_array($result))
    //{
    // if($row['COUNT(date)'] > 2 ){
    // echo "Datum ".$row['date']." je rezervisan " .$row['COUNT(date)']. "puta" ;
    // echo "<br />";
    // }else {
    // echo " ";
    // }
    //}
    //// $query = "SELECT date2, COUNT(date) FROM calendar GROUP BY date";

    // $result = mysql_query($query) or die(mysql_error());
    // Ovo je dobroooooooooo
    // Print out result
    // while($row = mysql_fetch_array($result))
    // {
    // if($row['COUNT(date)'] > 2 ){
    // echo "Datum ".$row['date2']." je rezervisan " .$row['COUNT(date)']. "puta" ;
    // echo "<br />";
    // }else {
    // echo " ";
    // }
    // }






    $query = "SELECT date, date2 FROM calendar GROUP BY date, date2";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result))
    {
    $x1=$row['date'];
    $x2=$row['date2'];
    $i=$i+1;
    // echo "x1= ".$x1. " ------> x2= ".$x2 ;
    echo "<br />";
    echo $x1."<br>";
    $dateArray = getAllDatesBetweenTwoDates($x1, $x2);

    echo $sanel;
    //echo"<br>";
    }

    function getAllDatesBetweenTwoDates($strDateFrom,$strDateTo)
    {
    $aryRange=array();

    $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));
    $iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));

    if ($iDateTo>=$iDateFrom)
    {
    array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
    while ($iDateFrom<$iDateTo)
    {
    $iDateFrom+=86400; // add 24 hours
    array_push($aryRange,date('Y-m-d',$iDateFrom));
    $sanel = date('Y-m-d',$iDateFrom)."<br>";
    echo $sanel; //samo cisti datumi
    $sql="INSERT INTO calendar2 (date) VALUES ('$sanel')";
    $result=mysql_query($sql);
    }
    }
    return $aryRange;
    return $sanel;
    }

    $query = "SELECT date, COUNT(date) FROM calendar2 GROUP BY date";

    $result = mysql_query($query) or die(mysql_error());

    // Print out result
    while($row = mysql_fetch_array($result))
    {
    if($row['COUNT(date)'] > 2 ){
    echo "Date ".$row['date']." is occupied " .$row['COUNT(date)']. "times" ;
    echo "<br />";
    }else {
    echo " ";
    }
    }




    ?>












    php code []
    Last edited by Pearl_9; 06-27-2014 at 05:31 PM.

  • #5
    Regular Coder
    Join Date
    Aug 2013
    Posts
    196
    Thanks
    14
    Thanked 0 Times in 0 Posts
    This is code for counting days unavailable


    Php code[]



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sample calendar page</title>
    <link href="calendar.css" rel="stylesheet" type="text/css" />
    </head>

    <body>

    <div id="Calendar"> </div>
    <script language="javascript" src="calendar.js"></script>
    <?php
    include("config.php");

    if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
    $start_from = ($page-1) * 20;
    $sql = "SELECT * FROM calendar2 ORDER BY date ASC LIMIT $start_from, 20";
    $rs_result = mysql_query ($sql, $connection);



    ?>
    <table>
    <tr><td></td>
    <?php
    while ($row = mysql_fetch_assoc($rs_result)) {
    ?>
    <tr>

    <td><? //echo $row["date"]; ?></td>
    </tr>
    <?php
    //if
    //($rowdate>10);

    //echo"Those dates are occupied";



    };
    ?>
    </table>

    </body>
    </html>


    <?php
    // Make a MySQL Connection



    // Print out result
    //while($row = mysql_fetch_array($result)){
    //echo "ima ". $row['COUNT(date)'] ." ". $row['date'] ." .";
    //echo "<br />";


    // Make a MySQL Connection

    //$query = "SELECT date, COUNT(date) FROM calendar GROUP BY date";
    //
    //$result = mysql_query($query) or die(mysql_error());
    //
    //// Print out result
    //while($row = mysql_fetch_array($result))
    //{
    // if($row['COUNT(date)'] > 2 ){
    // echo "Datum ".$row['date']." je rezervisan " .$row['COUNT(date)']. "puta" ;
    // echo "<br />";
    // }else {
    // echo " ";
    // }
    //}
    //// $query = "SELECT date2, COUNT(date) FROM calendar GROUP BY date";

    // $result = mysql_query($query) or die(mysql_error());
    // Ovo je dobroooooooooo
    // Print out result
    // while($row = mysql_fetch_array($result))
    // {
    // if($row['COUNT(date)'] > 2 ){
    // echo "Datum ".$row['date2']." je rezervisan " .$row['COUNT(date)']. "puta" ;
    // echo "<br />";
    // }else {
    // echo " ";
    // }
    // }






    $query = "SELECT date, date2 FROM calendar GROUP BY date, date2";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result))
    {
    $x1=$row['date'];
    $x2=$row['date2'];
    $i=$i+1;
    // echo "x1= ".$x1. " ------> x2= ".$x2 ;
    echo "<br />";
    echo $x1."<br>";
    $dateArray = getAllDatesBetweenTwoDates($x1, $x2);

    echo $sanel;
    //echo"<br>";
    }

    function getAllDatesBetweenTwoDates($strDateFrom,$strDateTo)
    {
    $aryRange=array();

    $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));
    $iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));

    if ($iDateTo>=$iDateFrom)
    {
    array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
    while ($iDateFrom<$iDateTo)
    {
    $iDateFrom+=86400; // add 24 hours
    array_push($aryRange,date('Y-m-d',$iDateFrom));
    $sanel = date('Y-m-d',$iDateFrom)."<br>";
    echo $sanel; //samo cisti datumi
    $sql="INSERT INTO calendar2 (date) VALUES ('$sanel')";
    $result=mysql_query($sql);
    }
    }
    return $aryRange;
    return $sanel;
    }

    $query = "SELECT date, COUNT(date) FROM calendar2 GROUP BY date";

    $result = mysql_query($query) or die(mysql_error());

    // Print out result
    while($row = mysql_fetch_array($result))
    {
    if($row['COUNT(date)'] > 2 ){
    echo "Date ".$row['date']." is occupied " .$row['COUNT(date)']. "times" ;
    echo "<br />";
    }else {
    echo " ";
    }
    }




    ?>










    Php code[]








    Sample calendar page This url where is that code and calendar.Hope so that will help.Sunfighter really appreciate your help.

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,348
    Thanks
    23
    Thanked 618 Times in 617 Posts
    I responded to this in the AM. Don't know what happened to it.
    I had said this
    PHP Code:
    $row['COUNT(date)'
    was wrong
    Try this:
    PHP Code:
    $query "SELECT date, COUNT(date) AS amount FROM calendar2 GROUP BY date";
    $result mysql_query($query) or die(mysql_error());
    // Print out result
    while($row mysql_fetch_array($result)){
        if(
    amount ){
            echo 
    "Date ".$row['date']." is occupied " .$row['COUNT(date)']. "times" ;
            echo 
    "<br />";
        }else {
            echo 
    " ";
        }

    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    Pearl_9 (06-28-2014)

  • #7
    Regular Coder
    Join Date
    Aug 2013
    Posts
    196
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Didn't work any another suggestions.I tried my self couple of the options didn't work

  • #8
    Regular Coder
    Join Date
    Aug 2013
    Posts
    196
    Thanks
    14
    Thanked 0 Times in 0 Posts

    I fix it all.

    I fix it all.


  •  

    Posting Permissions

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