TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-07-2009, 11:42 AM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2009
Posts: 19
Thanks: 9
shankar is on a distinguished road
Default Unable to list all the month names and mont values

<form action="stud_attendance_report_month.php" name="select_date" method="POST">
View results of &nbsp;&nbsp;&nbsp;
<select name = "year" >
<option value = "0">Select one</option>
<?php
include("connect.php");

$query1 = mysql_query("SELECT * FROM attendance WHERE Stud_ID = '1'");
$numrows1 = mysql_num_rows($query1);
if ($numrows1!=0)
{
$row1 = mysql_fetch_assoc($query1);
$thing = $row1['att_date'];

$set_year_name = date("Y",strtotime(".$thing."));
$set_year_value = date("y",strtotime(".$thing."));

$set_year_prev_name = $set_year_name - 1;
$set_year_prev_value = $set_year_value - 1;


?>
<option value ="<?php echo $set_year_value;?>"><?php echo $set_year_prev_name." - ".$set_year_name; ?></option>
<?php
}
?>
</select>
&nbsp;&nbsp;&nbsp;
<select name = "month" >
<option value = "0">Select one</option>
<?php
$query2 = mysql_query("SELECT * FROM attendance WHERE Stud_ID = '1'");
$numrows2 = mysql_num_rows($query2);
if ($numrows2!=0)
{
$row2 = mysql_fetch_assoc($query2);
$thing = $row2['att_date'];

$get_rows = mysql_query("SELECT att_date FROM attendance");
$month_rows = mysql_query("SELECT MONTHNAME('".$thing."') FROM attendance");
$set_month_name = date("M",strtotime(".$thing."));
$set_month_value = date("m",strtotime(".$thing."));
$assis_count = mysql_num_rows($get_rows);
$month_count = mysql_num_rows($month_rows);



switch ($set_month_value)
{
case 01:$load_year = $set_year_name; break;
case 02:$load_year = $set_year_name; break;
case 03:$load_year = $set_year_name; break;
case 04:$load_year = $set_year_name; break;
case 05:$load_year = $set_year_name; break;
case 06:$load_year = $set_year_prev_name; break;
case 07:$load_year = $set_year_prev_name; break;
case 08:$load_year = $set_year_prev_name; break;
case 09:$load_year = $set_year_prev_name; break;
case 10:$load_year = $set_year_prev_name; break;
case 11:$load_year = $set_year_prev_name; break;
case 12:$load_year = $set_year_prev_name; break;
}

?>
<option value ="<?php echo $set_month_value;?>"><?php echo $month_name." - ".$load_year; ?></option>
<?php
}
?>
</select>
&nbsp;&nbsp;&nbsp;
<input id='button' type='submit' name='select_date' value='Submit' />
</form>
</center><hr>

There are 3 month names added in the table of attendance, but in the dropdown there is only May that is displayed but not the actual names that are available in the database, help me..
__________________
--
Regards
Shankar
shankar is offline  
Reply With Quote
Old 06-08-2009, 03:16 PM   #2 (permalink)
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
Runar is on a distinguished road
Default

I believe you have to use while() or something similar when dealing with more than one result (more than one month). Try this:

PHP Code:
<?php
$query2 
mysql_query("SELECT * FROM attendance WHERE Stud_ID = '1'");
$numrows2 mysql_num_rows($query2);

while(
$numrows2!=0)
{
    
$row2 mysql_fetch_assoc($query2);
    
$thing $row2['att_date'];

    
$get_rows mysql_query("SELECT att_date FROM attendance");
    
$month_rows mysql_query("SELECT MONTHNAME('".$thing."') FROM attendance");
    
$set_month_name date("M",strtotime(".$thing."));
    
$set_month_value date("m",strtotime(".$thing."));
    
$assis_count mysql_num_rows($get_rows);
    
$month_count mysql_num_rows($month_rows);

    switch (
$set_month_value)
    {
        case 
01:$load_year $set_year_name; break;
        case 
02:$load_year $set_year_name; break;
        case 
03:$load_year $set_year_name; break;
        case 
04:$load_year $set_year_name; break;
        case 
05:$load_year $set_year_name; break;
        case 
06:$load_year $set_year_prev_name; break;
        case 
07:$load_year $set_year_prev_name; break;
        case 
08:$load_year $set_year_prev_name; break;
        case 
09:$load_year $set_year_prev_name; break;
        case 
10:$load_year $set_year_prev_name; break;
        case 
11:$load_year $set_year_prev_name; break;
        case 
12:$load_year $set_year_prev_name; break;
    }

    echo 
'<option value="' $set_month_value '">' $month_name '" - "' $load_year '</option>';

}
?>
Send a message via MSN to Runar
Runar is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:50 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design