使用php

时间:2016-05-06 06:18:32

标签: php mysql

我试图从数据库中获取月份和年份,当我从select选项中单击特定月份时,它应该显示月份和年份,结果应该从数据库中获取。 下面是我的代码

<?php 
    $mon_arr=array("Jan"=>"01","Feb"=>"02","Mar"=>"03","Apr"=>"04","May"=>"05","Jun"=>"06","Jul"=>"07","Aug"=>"08","Sep"=>"09","Oct"=>"10","Nov"=>"11","Dec"=>"12");     
?>

        <select name="month" id="monthr">
        <?php foreach($mon_arr as $x=>$xval){ ?>
        <option value="<?php echo $xval; ?>" <?php if($m == $xval) echo "selected=selected"; ?>><?php echo $x; ?></option>
        <?php } ?>
        </select>
        <?php //echo $xval; ?>
        <?php //echo $m; ?>
        <?php //echo $x; ?>
        <select name="year" id="yearr">
        <?php for($yi=2014;$yi<=2025;$yi++){ ?>
        <option value="<?php echo $yi; ?>" <?php if($y == $yi) echo "selected=selected"; ?>><?php echo $yi; ?></option>
        <?php } ?>
        </select>
    </div>
    <table class="table">
        <thead>
            <tr>
                <th>#</th>
                <th>Description</th>
                <th>File</th>
                <th>Submitted By</th>
                <th>Date</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        <?php $sel_month=mysql_query("SELECT * FROM ".TABLE_MONTHLY." WHERE pid='".$_GET['pid']."' ORDER BY m_date DESC "); 
        $f=new all_calls();
                while($res_month=mysql_fetch_array($sel_month))
                {
        ?>
            <tr>
                <td></td>
                <td><?php echo $res_month['m_desc']; ?></td>
                <td><?php $pathsi=explode(',',$res_month['m_file']); 
                for($ji=1;$ji<count($pathsi);$ji++) { 
                ?>
                <a href="<?php echo $pathsi[$ji]; ?>">Download</a><br />
                <?php
                }
                 ?></td>
                <td><?php echo $f->get_username($res_month['m_by']); ?></td>
                <td><?php echo $res_month['m_date']; ?></td>
                <td><a href="index.php?p=next&rel=mr&pid=<?php echo $_GET['pid']; ?>&mid=<?php echo $res_month['mid']; ?>&act=edit"><i class="fa fa-pencil"></i></a></td>
            </tr>
            <?php } ?>
                       </tbody>
    </table>


<?php
class monthly_report{

function validate_and_insert($data,$mid,$mfile)
{

    //var_dump($mid); die;
    if(empty($data['mdesc'])) $err='Description Required';

    if(empty($err))
    {
        //echo 'hello'; die;
        //var_dump($mid); die;
        if(strlen($mid)==0)
        {
            $insert=mysql_query("INSERT INTO ".TABLE_MONTHLY." SET pid='".$_POST['hide_pid']."', m_desc='".$data['mdesc']."', m_file='".$mfile."', m_by='".$_SESSION['ID']."', m_date=CURDATE()");

            if($insert)
            {
                return 0;
            }
        }
        else
        {
            $a=new all_calls();

            $paths=$a->get_monthly_file($mid);

            if(strlen($mfile)==0)
            {
                $newfile=$paths;
            }
            else
            {
                $newfile=$paths.','.$mfile;
            }
            //var_dump($mid);die; 
            $update=mysql_query("UPDATE ".TABLE_MONTHLY." SET m_desc='".$data['mdesc']."', m_file='".$newfile."' WHERE mid='".$mid."' ");

            if($update)
            {
                return 0;
            }
        }
    }
}
}
?>

任何人都可以帮我解决这个问题。

0 个答案:

没有答案