urtrivedi 276 Nearly a Posting Virtuoso
$sql8 = mysql_query("SELECT `orderlist_id`, `brandname`, `packsize`, `quantity`, `mrp`, `ourRate`, `Sum`,user_id,userName,`date` FROM `orderlist` WHERE `user_id`='$userid' AND `userName`='$usern' AND `date`>date_sub( current_date(),interval 3 month)");

No need to rename field, you can enquote field name with ` character (press key before 1 on keyboard)

I have removed = sign from query condition, so it will not display current date record, but it will only show last three month records.

What kind of monthly output you want.

urtrivedi 276 Nearly a Posting Virtuoso

i want to display last 3 months of data

When you say last 3 months, so by default it means last three months from current date (today).

urtrivedi 276 Nearly a Posting Virtuoso

You try following query, Your query may be not giving result because you are using equal to sign, so it is searching exact records for that particular single date.

Following query will give all result that happened in last 3 months.

Remove > sign if you want to equate only

$sql8 = mysql_query("SELECT `orderlist_id`, `brandname`, `packsize`, `quantity`, `mrp`, `ourRate`, `Sum`,user_id,userName,date FROM `orderlist` WHERE `user_id`='$userid' AND `userName`='$usern' AND date>=date_sub( current_date(),interval 3 month);
urtrivedi 276 Nearly a Posting Virtuoso
    $checked =  ($_POST['date']);
    $unchecked = ($_POST['nondate']);
    //$merge = array_merge($checked,$unchecked); // no need to merge as unchechk is your master array

    $diff = array_diff($unchecked,$checked);
urtrivedi 276 Nearly a Posting Virtuoso

Try with our original code and two more lines to find error

<?php
    error_reporting(E_ALL); 
    ini_set("display_errors", 1); 

    include('connect.php');
    $checked =  ($_POST['date']);
    $unchecked = ($_POST['nondate']);
    $diff = array_diff($unchecked,$checked);

            if(isset($_POST['date']))
            {
                foreach ($_POST['date'] as $dateValue)
                {
                $insert="INSERT INTO checked_table ($colm_ladate) VALUES ('$dateValue')";
                mysql_query($insert);
                }
                echo header("location:home.php");
        }
        if (isset($_POST['nondate']))
        {
        foreach ($diff as $dateValue2)
        {
            $insert2="INSERT INTO unchecked_table($colm_lrdate) VALUES ('$dateValue2')";
            mysql_query($insert2);
        }
            echo header("location:home.php");
            }

?>
urtrivedi 276 Nearly a Posting Virtuoso

You doing it correct. your unchecked array itself is master arrary
So you code must work

PUt two lines in begining of process page (where you write insert code)

error_reporting(E_ALL); 
ini_set("display_errors", 1); 

Check can you see any insert query error

urtrivedi 276 Nearly a Posting Virtuoso

As when you do not check check box, it is not posted.

So you must set master array while processing and find diff of master array and checked array.

$master = array(1,2,3,4,5,6,7,8,9,10,11);

$diff = array_diff($master,$checked);
urtrivedi 276 Nearly a Posting Virtuoso
echo "<input type='checkbox' name='date' value ='".date('d-m-Y', $date)."'>";
urtrivedi 276 Nearly a Posting Virtuoso
urtrivedi 276 Nearly a Posting Virtuoso

put follwing after line 31 and before line 32

if( $x < count($files) - 1 )
urtrivedi 276 Nearly a Posting Virtuoso
urtrivedi 276 Nearly a Posting Virtuoso

Change following
Line 21

$sql="SELECT username FROM admin WHERE username='".$myusername."' AND password='".$mypassword."'";

Line 25

if($row[0]!="")
urtrivedi 276 Nearly a Posting Virtuoso

what are sample records?
what output you expect from the query ?

urtrivedi 276 Nearly a Posting Virtuoso

1) what are table strutures of both tables?
2) You want to search fav of one particualar user or all users?
3) What query output you expect for your above sample records?

urtrivedi 276 Nearly a Posting Virtuoso

This is fulll working code,

If you have library file copy above function in that file

Or copy in the page you want to use directly

then call it in your html

Set mysql connection in variable $dblink before following code

<table>
<tr>
<td> Country </td>

<td> <?php 
echo fillcombo($dblink,"cmbcountry","200px","select id, desc from table","id","desc","25","select value"," style='attribute:value'")); 
?>
  </td>

</tr>
</table>
urtrivedi 276 Nearly a Posting Virtuoso

run this query in phpymyadmin for whom you are clicking on name link
and see how dob column appears in phpmyadmin result

SELECT * FROM contact1 WHERE contact_id = yournumber
urtrivedi 276 Nearly a Posting Virtuoso

I have my own library function to fill combo box

    function fillcombo($dblink,$cmbname,$width,$query,$keycolname,$desccolname,$defaultvalue="",$initialtext="",$othertags="")
    {

        $elementstring="";
        $elementstring ="\n<SELECT id={$cmbname} style='WIDTH: {$width}px' size=1 name={$cmbname} {$othertags}>";

        if (trim($initialtext)!="")
        {
              $elementstring .=  "\n<OPTION value=''";
            if (trim($defaultvalue)=="")
                $elementstring .= " selected";
            $elementstring .=">---{$initialtext}---</OPTION>";
         }           

         $results = mysqli_query($dblink,$query)or die("Query Failed..<hr>" . mysqli_error());
         if ($results)
         {
            while($row = mysqli_fetch_array( $results))
            {

                 $elementstring .= "\n";
                    $elementstring .=  "<OPTION value='".$row[$keycolname]."' title=\"".$row[$desccolname]."\" ";
                    if (trim($row[$keycolname])==$defaultvalue)
                       $elementstring .= " selected";
                    $elementstring .=">{$row[$desccolname]}</OPTION>";
            }
         }
         $elementstring .="\n</SELECT>";



            return $elementstring;


    }

It can be called like given below

echo fillcombo($dblink,"cmbcountry","200px","select id, desc from table","id","desc","25","select value"," style='attribute:value'"));
urtrivedi 276 Nearly a Posting Virtuoso

Now run combined version

If still record do not appear properly, then check spellings of values in all join columns

SELECT
c.contact_id,c.fullname,
s.spouse_id,s.s_fullname,s.sspouse_name,
ch.child_id,ch.c_fullname,ch.primaryparent,ch.secondaryparent
FROM contact1 c
left outer JOIN spouse1 s ON trim(c.fullname) = trim(s.sspouse_name)
LEFT JOIN child1 ch ON trim(c.fullname) = trim(ch.primaryparent)
urtrivedi 276 Nearly a Posting Virtuoso

Try with left outer join, and check whats missing

SELECT
c.contact_id,c.fullname,
s.spouse_id,s.s_fullname,s.sspouse_name,
ch.child_id,ch.c_fullname,ch.primaryparent,ch.secondaryparent
FROM contact1 c
left outer JOIN spouse1 s ON c.fullname = s.sspouse_name
LEFT JOIN child1 ch ON c.fullname = ch.primaryparent

Or check with trim

SELECT
c.contact_id,c.fullname,
s.spouse_id,s.s_fullname,s.sspouse_name,
ch.child_id,ch.c_fullname,ch.primaryparent,ch.secondaryparent
FROM contact1 c
INNER JOIN spouse1 s ON trim(c.fullname) = trim(s.sspouse_name)
LEFT JOIN child1 ch ON trim(c.fullname) = trim(ch.primaryparent)

But I feel table is not properly design. Joining on name is not a good idea

urtrivedi 276 Nearly a Posting Virtuoso
SELECT events.sensor_id, events.event_type, events.value
from events 
inner join (select sensor_id, event_type, max(time) maxtime 
            from tap.events group by sensor_id, event_time) t on 
            t.sensor_id=events.sensor_id and t.event_type=events.event_type and t.maxtime=events.time
ORDER BY events.sensor_id,events.event_type;
urtrivedi 276 Nearly a Posting Virtuoso

I am not sure, but can you give try to this

select * from MasterList inner join tblPositionLists on tblPositionLists.Position = case when @pRemarks='ALL' then MasterList.Position else tblPositionLists.Position end
and
tblPositionLists.PositionLevel = case when @pRemarks='LEVEL' then MasterList.PositionLevel else tblPositionLists.PositionLevel end

urtrivedi 276 Nearly a Posting Virtuoso

This kind of solution is useful where php mysql application is build for internal use like in intranet enviroment.

Some time operator at reception need to print receipts and bills directly for the customer, there this will help

urtrivedi 276 Nearly a Posting Virtuoso

1) your last 2 records transaction date is not in december so it is not in result
2) You can use having clause to check aggregate value instead of querying again

Two sample queries:

select duedt, count(*) cnt , sum(amtpd) from ln02rep2
               WHERE trndt BETWEEN '01-dec-2013' AND '31-dec-2013'
                AND duedt = '31-dec-2013'
group by duedt                






select duedt, count(*) cnt, sum(amtpd) from ln02rep2
               WHERE trndt BETWEEN '01-dec-2013' AND '31-dec-2013'
                AND duedt = '31-dec-2013'
group by duedt                
having sum(amtpd)>='10450.00'
urtrivedi 276 Nearly a Posting Virtuoso
urtrivedi 276 Nearly a Posting Virtuoso
<?php
$text1 = '00101';
echo "<br>$text1 -> Count 0 from begining (zeroth character) : ".substr_count($text1, '0'); 
echo "<br>$text1 -> Count 0 start after zeroth character : ".substr_count($text1, '0',1); 


?>

http://www.php.net/manual/en/function.substr-count.php

urtrivedi 276 Nearly a Posting Virtuoso
urtrivedi 276 Nearly a Posting Virtuoso
urtrivedi 276 Nearly a Posting Virtuoso

Urtrivedi is the master of understanding noobs. He seems to understand everyone of my posts easily as well :)

In my view key to get correct answer for any noob
is to know basics well
Problem explained precisely in short
Showing efforts done till that point of time

So Mark its not you or me but we collectively get success.

Not to forget Diafol, Pritaeas and Dani and so many others are always behind us.

urtrivedi 276 Nearly a Posting Virtuoso

How about this

$query = "Select coach_career.coach_career_id, coach_career.pid, coach_career.league_id, coach_career.club_id, coach_career.season, coach_career.pos, coach_career.games, coach_career.wins, coach_career.losses, coach_career.draws, coach_career.fingames, coach_career.finwins, coach_career.finlosses, coach_career.findraws, coach_career.gfgames, coach_career.gfwins, coach_career.gflosses, coach_career.gfdraws, coach_career.totgames, coach_career.totwins, coach_career.totlosses, coach_career.totdraws, coach_career.win_ratio, club.club, league.league From coach_career Inner Join club ON coach_career.club_id = club.club_id Inner Join league ON coach_career.league_id = league.league_id Where coach_career.pid = '$pid' Order By league.league,coach_career.season Asc, coach_career.league_id Asc";
$statement = $databaseConnection->prepare($query);
$statement->execute();
$statement->store_result();
$statement->bind_result($coach_career_id, $pid, $league_id, $club_id, $season, $pos, $games, $wins, $losses, $draws, $fingames, $finwins, $finlosses, $findraws, $gfgames, $gfwins, $gflosses, $gfdraws, $totgames, $totwins, $totlosses, $totdraws, $win_ratio, $club, $league);
if ($statement->error) {
die('Database query failed: ' . $statement->error);
}
$Exists = $statement->num_rows > 0;
if ($Exists) {

$alternate = "1"; 
$prevleague="";
$rownumber=0;
while ($statement->fetch()) {
    if ($alternate == "1") { 
        $tbrow = "tbrow2"; 
        $alternate = "2"; 
    } else { 
        $tbrow = "tbrow1"; 
        $alternate = "1"; 
    }

    if($rownumber>0 && $prevleague!=$league)
    {
        echo $sumhtml;
        echo "</table>";
    }



    if($prevleague!=$league)
    {
        echo"<br /></br><table width=\"98%\"><caption>$league</caption>";
echo"<tr><th width=\"31%\" colspan=\"4\">Coaching Career</th><th width=\"16%\" colspan=\"4\"><center>Home & Away</center></th><th width=\"16%\" colspan=\"4\"><center>Finals</center></th><th width=\"16%\" colspan=\"4\"><center>Grand Finals</center></th><th width=\"16%\" colspan=\"4\"><center>Total Games</center></th><th colspan=\"2\"></th></tr>";
echo"<th class=\"category\" width=\"4%\"><center>Year</center></th><th class=\"category\" width=\"10%\">League</th><th class=\"category\" width=\"10%\">Club</th><th class=\"category\" width=\"3%\"><center>Pos</center></th><th class=\"category\" width=\"3%\"><center>Gms</center></th><th class=\"category\" width=\"3%\"><center>W</center></th><th class=\"category\" width=\"3%\"><center>L</center></th><th class=\"category\" width=\"3%\"><center>D</center></th><th class=\"category\" width=\"3%\"><center>Gms</center></th><th class=\"category\" width=\"3%\"><center>W</center></th><th class=\"category\" width=\"3%\"><center>L</center></th><th class=\"category\" width=\"3%\"><center>D</center></th><th class=\"category\" width=\"3%\"><center>Gms</center></th><th class=\"category\" width=\"3%\"><center>W</center></th><th class=\"category\" width=\"3%\"><center>L</center></th><th class=\"category\" width=\"3%\"><center>D</center></th><th class=\"category\" width=\"3%\"><center>Gms</center></th><th class=\"category\" width=\"3%\"><center>W</center></th><th class=\"category\" width=\"3%\"><center>L</center></th><th class=\"category\" width=\"3%\"><center>D</center></th><th class=\"category\"width=\"5%\"><center>Edit</center></th><th class=\"category\"width=\"5%\"><center>Del</center></th>";


  $query = "Select Sum(coach_career.games) AS sumgames, Sum(coach_career.wins) AS sumwins, Sum(coach_career.losses) AS sumlosses, Sum(coach_career.draws) AS sumdraws, Sum(coach_career.fingames) AS sumfingames, Sum(coach_career.finwins) AS sumfinwins, Sum(coach_career.finlosses) AS sumfinlosses, Sum(coach_career.findraws) AS sumfindraws, Sum(coach_career.gfgames) AS sumgfgames, Sum(coach_career.gfwins) AS sumgfwins, Sum(coach_career.gflosses) AS sumgflosses, Sum(coach_career.gfdraws) AS sumgfdraws, Sum(coach_career.totgames) AS sumtotgames, …
urtrivedi 276 Nearly a Posting Virtuoso

forget it

please check following works or not

I have put your new summation code before closing table tag

$query = "Select coach_career.coach_career_id, coach_career.pid, coach_career.league_id, coach_career.club_id, coach_career.season, coach_career.pos, coach_career.games, coach_career.wins, coach_career.losses, coach_career.draws, coach_career.fingames, coach_career.finwins, coach_career.finlosses, coach_career.findraws, coach_career.gfgames, coach_career.gfwins, coach_career.gflosses, coach_career.gfdraws, coach_career.totgames, coach_career.totwins, coach_career.totlosses, coach_career.totdraws, coach_career.win_ratio, club.club, league.league From coach_career Inner Join club ON coach_career.club_id = club.club_id Inner Join league ON coach_career.league_id = league.league_id Where coach_career.pid = '$pid' Order By league.league,coach_career.season Asc, coach_career.league_id Asc";
$statement = $databaseConnection->prepare($query);
$statement->execute();
$statement->store_result();
$statement->bind_result($coach_career_id, $pid, $league_id, $club_id, $season, $pos, $games, $wins, $losses, $draws, $fingames, $finwins, $finlosses, $findraws, $gfgames, $gfwins, $gflosses, $gfdraws, $totgames, $totwins, $totlosses, $totdraws, $win_ratio, $club, $league);
if ($statement->error) {
die('Database query failed: ' . $statement->error);
}
$Exists = $statement->num_rows > 0;
if ($Exists) {

$alternate = "1"; 
$prevleague="";
$rownumber=0;
while ($statement->fetch()) {
    if ($alternate == "1") { 
        $tbrow = "tbrow2"; 
        $alternate = "2"; 
    } else { 
        $tbrow = "tbrow1"; 
        $alternate = "1"; 
    }

    if($rownumber>0 && $prevleague!=$league)
    {



        $query = "Select Sum(coach_career.games) AS sumgames, Sum(coach_career.wins) AS sumwins, Sum(coach_career.losses) AS sumlosses, Sum(coach_career.draws) AS sumdraws, Sum(coach_career.fingames) AS sumfingames, Sum(coach_career.finwins) AS sumfinwins, Sum(coach_career.finlosses) AS sumfinlosses, Sum(coach_career.findraws) AS sumfindraws, Sum(coach_career.gfgames) AS sumgfgames, Sum(coach_career.gfwins) AS sumgfwins, Sum(coach_career.gflosses) AS sumgflosses, Sum(coach_career.gfdraws) AS sumgfdraws, Sum(coach_career.totgames) AS sumtotgames, Sum(coach_career.totwins) AS sumtotwins, Sum(coach_career.totlosses) AS sumtotlosses, Sum(coach_career.totdraws) AS sumtotdraws From coach_career Where coach_career.pid = ? AND coach_career.league_id = ?";
        $statement2 = $databaseConnection->prepare($query);
        $statement2->bind_param('ii', $pid, $league_id);
        $statement2->execute();
        $statement2->store_result();
        if ($statement2->error) {
            die('Database query failed: ' . $statement2->error);
        }
        $statement2->bind_result($sumgames, $sumwins, $sumlosses, $sumdraws, $sumfingames, $sumfinwins, $sumfinlosses, $sumfindraws, $sumgfgames, $sumgfwins, $sumgflosses, $sumgfdraws, $sumtotgames, $sumtotwins, $sumtotlosses, $sumtotdraws);
        $statement2->fetch(); …
urtrivedi 276 Nearly a Posting Virtuoso

Dear Diafol, I learned from you. I always read your answers. Though I am still learning

urtrivedi 276 Nearly a Posting Virtuoso

To avoid complexity, You may also try with another approach

1) query list distinct leagus of partiular pid

2) loop through leagues found above

2.1) find deatils of coaching for pid for all leages on by one

    2.1.1) loop through details of coaching

2.2) here at the end you can show sum of coaching detail rows

3) if any more league left then go to step 2 else end

urtrivedi 276 Nearly a Posting Virtuoso

Change export.php as following

Problem is in your clean function, it expects database connection. so I have put connection first then function then rest of code.

<?php
    $host="localhost";
    $uname="root";
    $pass="Unknown";
    $database = "dcde"; 
    $connection=mysql_connect($host,$uname,$pass); 

    function clean($str)
    {
        $str = @trim($str);
        if(get_magic_quotes_gpc())
                {
                $str = stripslashes($str);
                }
        return mysql_real_escape_string($str);
    }

    if(isset($_POST['export']))
    {
         //sanitize the input
        $searchString = strtoupper(clean($_POST['searchString']));
        $by=clean($_POST['by']);
        if ($by=='Date')
        {
            echo mysql_error();
            //or die("Database Connection Failed");
            $selectdb=mysql_select_db($database) or 
                die("Database could not be selected"); 
            $result=mysql_select_db($database)
                or die("database cannot be selected <br>");
            // Fetch Record from Database
            $output = "";
            $table = "po"; // Enter Your Table Name 
            $sql = "Select poNo,date,supplier,tAmount,code from $table WHERE  date like '%$searchString%'";
            $columns_total = mysql_num_fields($sql);
            // Get The Field Name
            for ($i = 0; $i < $columns_total; $i++) {
                $heading = mysql_field_name($sql, $i);
                $output .= '"'.$heading.'",';
            }
            $output .="\n";
            // Get Records from the table
            while ($row = mysql_fetch_array($sql)) {
                for ($i = 0; $i < $columns_total; $i++) {
                   $output .='"'.$row["$i"].'",';
                }
                $output .="\n";
            }
            // Download the file
            $filename = "myfile.csv";
            header('Content-type: application/csv');
            header('Content-Disposition: attachment; filename='.$filename);
            echo $output;
            exit;           
        }
    }
 ?>
urtrivedi 276 Nearly a Posting Virtuoso

Pass values in hidden form elements
Post form to next page
make use of $_POST array to read values on next page

urtrivedi 276 Nearly a Posting Virtuoso

Kindly check following works or not
I have added league in order by and bring table heading rows inside loop with conditions

$query = "Select coach_career.coach_career_id, coach_career.pid, coach_career.league_id, coach_career.club_id, coach_career.season, coach_career.pos, coach_career.games, coach_career.wins, coach_career.losses, coach_career.draws, coach_career.fingames, coach_career.finwins, coach_career.finlosses, coach_career.findraws, coach_career.gfgames, coach_career.gfwins, coach_career.gflosses, coach_career.gfdraws, coach_career.totgames, coach_career.totwins, coach_career.totlosses, coach_career.totdraws, coach_career.win_ratio, club.club, league.league From coach_career Inner Join club ON coach_career.club_id = club.club_id Inner Join league ON coach_career.league_id = league.league_id Where coach_career.pid = '$pid' Order By league.league,coach_career.season Asc, coach_career.league_id Asc";
$statement = $databaseConnection->prepare($query);
$statement->execute();
$statement->store_result();
$statement->bind_result($coach_career_id, $pid, $league_id, $club_id, $season, $pos, $games, $wins, $losses, $draws, $fingames, $finwins, $finlosses, $findraws, $gfgames, $gfwins, $gflosses, $gfdraws, $totgames, $totwins, $totlosses, $totdraws, $win_ratio, $club, $league);
if ($statement->error) {
die('Database query failed: ' . $statement->error);
}
$Exists = $statement->num_rows > 0;
if ($Exists) {

$alternate = "1"; 
$prevleague="";
$rownumber=0;
while ($statement->fetch()) {
    if ($alternate == "1") { 
        $tbrow = "tbrow2"; 
        $alternate = "2"; 
    } else { 
        $tbrow = "tbrow1"; 
        $alternate = "1"; 
    }

    if($rownumber>0 && $prevleague!=$league)
    {
        echo "</table>";
    }
    if($prevleague!=$league)
    {
        echo"<br /></br><table width=\"98%\"><caption>$league</caption>";
echo"<tr><th width=\"31%\" colspan=\"4\">Coaching Career</th><th width=\"16%\" colspan=\"4\"><center>Home & Away</center></th><th width=\"16%\" colspan=\"4\"><center>Finals</center></th><th width=\"16%\" colspan=\"4\"><center>Grand Finals</center></th><th width=\"16%\" colspan=\"4\"><center>Total Games</center></th><th colspan=\"2\"></th></tr>";
echo"<th class=\"category\" width=\"4%\"><center>Year</center></th><th class=\"category\" width=\"10%\">League</th><th class=\"category\" width=\"10%\">Club</th><th class=\"category\" width=\"3%\"><center>Pos</center></th><th class=\"category\" width=\"3%\"><center>Gms</center></th><th class=\"category\" width=\"3%\"><center>W</center></th><th class=\"category\" width=\"3%\"><center>L</center></th><th class=\"category\" width=\"3%\"><center>D</center></th><th class=\"category\" width=\"3%\"><center>Gms</center></th><th class=\"category\" width=\"3%\"><center>W</center></th><th class=\"category\" width=\"3%\"><center>L</center></th><th class=\"category\" width=\"3%\"><center>D</center></th><th class=\"category\" width=\"3%\"><center>Gms</center></th><th class=\"category\" width=\"3%\"><center>W</center></th><th class=\"category\" width=\"3%\"><center>L</center></th><th class=\"category\" width=\"3%\"><center>D</center></th><th class=\"category\" width=\"3%\"><center>Gms</center></th><th class=\"category\" width=\"3%\"><center>W</center></th><th class=\"category\" width=\"3%\"><center>L</center></th><th class=\"category\" width=\"3%\"><center>D</center></th><th class=\"category\"width=\"5%\"><center>Edit</center></th><th class=\"category\"width=\"5%\"><center>Del</center></th>";
    }

    echo"<tr><td width=\"4%\" class=\"$tbrow\"><center>$season</center></td><td width=\"10%\" class=\"$tbrow\">$league</td><td width=\"10%\" class=\"$tbrow\">$club</td><td width=\"3%\" class=\"$tbrow\"><center>$pos</center></td><td width=\"3%\" class=\"$tbrow\"><center>$games</center></td><td width=\"3%\" class=\"$tbrow\"><center>$wins</center></td><td width=\"3%\" class=\"$tbrow\"><center>$losses</center></td><td width=\"3%\" class=\"$tbrow\"><center>$draws</center></td><td width=\"3%\" class=\"$tbrow\"><center>$fingames</center></td><td width=\"3%\" class=\"$tbrow\"><center>$finwins</center></td><td width=\"3%\" class=\"$tbrow\"><center>$finlosses</center></td><td …
urtrivedi 276 Nearly a Posting Virtuoso

so on the top of table, you want to show league name, and details will follow right?

urtrivedi 276 Nearly a Posting Virtuoso

I dont think when you add records then you need to create separate code for new records.

League_id is from another table wich is likely to be added to over time I would have to cintinually update the page adding extra code and queries every time. Is there a way I can code this to display them otherwise.

Can you post another piece of code that you modify and for new league added, so that we can compare your code and give suggestions

urtrivedi 276 Nearly a Posting Virtuoso

One way is to
keep 2 separate files
one part line number 1-16
1) export.html

<html>
     <head><title>Exports</title>           
     <link rel="stylesheet" href="css/css.css" />
      <h2>EXPORT DATE/YEAR</h2></head>
<form action="export.php" method="post" target='_blank'>
    <table>
        <tr>
            <td><input size="40"  name="searchString" type="text"class="ed"  />
                <select name="by" class="ed">
                        <option>Date</option>
                        <option>Year</option>
                </select>
                <input type="submit" name="export" value="Export" id="button2" /></td>
        </tr>
    </table>
</form>

</html>

2) export.php (dont keep any blank lines before <?php or after ?>

<?php
  if(isset($_POST['export']))
    {
         //sanitize the input
                function clean($str)
                {
                        $str = @trim($str);
                        if(get_magic_quotes_gpc())
                                {
                                $str = stripslashes($str);
                                }
                        return mysql_real_escape_string($str);
                }
        $searchString = strtoupper(clean($_POST['searchString']));
        $by=clean($_POST['by']);


        if ($by=='Date')
        {
        $host="localhost";
        $uname="root";
        $pass="Unknown";
        $database = "dcde"; 

        $connection=mysql_connect($host,$uname,$pass); 
        echo mysql_error();
        //or die("Database Connection Failed");
        $selectdb=mysql_select_db($database) or 
        die("Database could not be selected"); 
        $result=mysql_select_db($database)
        or die("database cannot be selected <br>");

        // Fetch Record from Database
        $output = "";
        $table = "po"; // Enter Your Table Name 
        $sql = "Select poNo,date,supplier,tAmount,code from $table WHERE  date like '%$searchString%'";
        $columns_total = mysql_num_fields($sql);
        // Get The Field Name
        for ($i = 0; $i < $columns_total; $i++) {
        $heading = mysql_field_name($sql, $i);
        $output .= '"'.$heading.'",';
        }
        $output .="\n";
        // Get Records from the table
        while ($row = mysql_fetch_array($sql)) {
        for ($i = 0; $i < $columns_total; $i++) {
        $output .='"'.$row["$i"].'",';
        }
        $output .="\n";
        }
        // Download the file
        $filename = "myfile.csv";
        header('Content-type: application/csv');
        header('Content-Disposition: attachment; filename='.$filename);
        echo $output;
        exit;           
    }
    }
 ?>
urtrivedi 276 Nearly a Posting Virtuoso

your method is post (see line no. 3) so changed line number 49,50

$myusername=mysqli_real_escape_string($con,$_POST['name']); 
$mypassword=mysqli_real_escape_string($con,$_POST['password']); 

change line 62 (if $row[0] has some value of id, means not blank)

if($row[0]!="")
urtrivedi 276 Nearly a Posting Virtuoso

I assume you mean code reusability.

If so, you need to learn to develop class and use them as and when required in muliple pages

urtrivedi 276 Nearly a Posting Virtuoso

Try this way

<textarea name="newscontent"  cols="30" rows="10" id="newscontent">

<?php echo $row['newscontent']; ?>

</textarea>
urtrivedi 276 Nearly a Posting Virtuoso

I am writing sample query

select a.id_customer, b.firstname,b.lastname, count(*) total_orders from orders a inner join customer b on a.id_customer=b.id_customer group by a.id_customer b.firstname,b.lastname
urtrivedi 276 Nearly a Posting Virtuoso

put all require php in the begning of page together, with out any line or space

also include phpgraphlib.php in the begninng too

urtrivedi 276 Nearly a Posting Virtuoso

You need to put whole code here
so that we can find problem

urtrivedi 276 Nearly a Posting Virtuoso

I suggest to create one master table say, total slots
slot_master

slot_id
1
2
3
4
5
6
7
8
9

another table is the one you are using
allocated_slot
alloc_slot_id
1
2
3
5

Now you can easily join both table to find free slots

select slot_id from slot_master a left outer join allocated_slot b
on a.slot_id=b.alloc_slot_id
where b.alloc_slot_id is null

Only you need to insert/delete records to /from allocated_slot table as and when it happens

urtrivedi 276 Nearly a Posting Virtuoso

write your common function in one .js file

say you have written your javascript code in project a like

/webroot/projecta/js/myfuction.js

Now you want to access that same file in another projectb which is I assume that it is stored at same level. So you can include your main javascript file as follwoing

<script language="javascript" src='../projecta/js/myfunction.js'></script>

So now in your code page where you add above line, You can use the fuction and javascript variables declared in myfunction.js

urtrivedi 276 Nearly a Posting Virtuoso

I changed your if condition at line 22 , if row count == 0 then means record does not exists with number, so show insert when $row[0]==0 , otherwise show "already exits" message

   if ($row[0] == 0)
urtrivedi 276 Nearly a Posting Virtuoso

Use following clause update when duplicate

http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

urtrivedi 276 Nearly a Posting Virtuoso

I assume your database is mysql

select str_to_date(string_date_col, '%M %d, %Y') from tblTransaction

Str_to_date function will change string to date type

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date

diafol commented: snap! +0
urtrivedi 276 Nearly a Posting Virtuoso

You can also try directly using pure mysql query without php

$result = mysqli_query($connection, "SELECT os_no, total, balance, discount, date_order, date_pickup, time_pickup FROM order_customer 
WHERE DATE( date_pickup  ) 
BETWEEN DATE_SUB( current_date, INTERVAL 7 DAY ) AND current_date");
diafol commented: good suggestion +14
prateeksha commented: yes...right +1