10, January 2009

What am I doing wrong??? - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: What am I doing wrong???
« previous next »
Pages: [1] Print

Author Topic: What am I doing wrong???  (Read 610 times)
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« on: Feb 28, 2006, 11:28:16 PM »

I've added a calendar to a site, first requirement was 2 colors, so I created a database with dates. If the date is found the day on the calendar will show red, if it isn't in the table it shows green. All working great.
Now the requirements have changed and I need 3 colors, so I added a field to the database to indicate state (a,b or blank) how do I get it to fillthe color based on that extra field, I've tried everything and just cant get it to work... once I change the code it keeps looping to infinity instead of showing just one month...

Code:
<?php
## print only the number of weeks needed
for($row=1;$row<$wim+1;$row++)
{  
  echo 
"<tr height='60'>";  

  
## prints week (Sun to Sat)
  
for($week=1;$week<8;$week++)  
  {  
    
$ct++;  
    
$value=mktime(0,0,0,$month,$ct-$dow,$year);  
    
    
## if $value is part of current month
    
if (date("m",$value)==$month)  
    {  
      echo 
"
      <td align='center' class='body' width='85' valign='top'"
;
    
## check if current date is available
$dag date("j",$value);
$query=mysql_query("select * from $db_table where YEAR = $year AND MONTH = $month AND DAY = $day");
## run query

$total mysql_num_rows($query);

if ($total )
{
echo " bgcolor='#CC0000'";
}
else
{
   echo " bgcolor='#00AA00'";
}
  echo " >
        <div align='right'><b>"
.date("j",$value)."</a></b></div><br>
      </td>"

    }  
    
## print previous and next month dates, but grayed out
    
else 
    { 
      echo 
"<td align='center' class='body' width='85' valign='top' 
bgcolor='#CCCCCC'><div 
align='right'><b>"
.date("j",$value)."</a></b></div><br></td>";
    }  
  }
  
  echo 
"</tr>";
}  


echo 
"</table>";  
?>

« Last Edit: Feb 28, 2006, 11:31:48 PM by Mind_nl »


Last blog : Are You Stumbling Yet?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8363
43165 credits
Members referred : 3



« Reply #1 on: Mar 01, 2006, 12:17:07 AM »

If I understand what you ask you may change this :

Code:
<?php

$query
=mysql_query("select * from $db_table where YEAR = $year AND MONTH = $month AND DAY = $day");
## run query

$total mysql_num_rows($query);

if (
$total )
{
echo 
" bgcolor='#CC0000'";
}
else
{
   echo 
" bgcolor='#00AA00'";
}
?>


to this :

Code:
<?php
$query
=mysql_query("select `state` from $db_table where YEAR = $year AND MONTH = $month AND DAY = $day LIMIT 1");
## run query

if (mysql_num_rows($query) > )
{
$rec mysql_fetch_array($query);
if ( $rec'state' ] == 'a' )
{
echo " bgcolor='#CC0000'";
} else {
echo " bgcolor='#xxxxxx'";
}
}
else
{
   echo 
" bgcolor='#00AA00'";
}

Change the `state` field in the mySql statement to whatever you have named the field that keeps the state indicator.

I've also added a LIMIT to your statement which will make the query faster Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #2 on: Mar 01, 2006, 11:00:30 AM »

Thats exactly what I needed! Thanks Nikolas!


Last blog : Are You Stumbling Yet?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8363
43165 credits
Members referred : 3



« Reply #3 on: Mar 01, 2006, 11:01:06 AM »

You are welcome Wink

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=1601
Tags : mysql databases Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: What am I doing wrong???
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jan 10, 2009, 04:13:48 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 38.670
Total Topics: 7.775
Total Members: 4.665
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: mosesbradford

27 Guests, 5 Users online :

14 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2009 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.