Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 118,659 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 867 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



2 tables/forms 1 page

 
Reply to this topicStart new topic

2 tables/forms 1 page, trying to get 2 table queries to work on one page

ozziffied
post 24 Jun, 2008 - 10:50 PM
Post #1


New D.I.C Head

Group Icon
Joined: 12 Mar, 2008
Posts: 6


My Contributions


CODE
<?php
    $dbhost = 'xxx.xxx.xxx.net';    // MySQL Server
    $dbuser = 'xxxx';        // Username
    $dbpass = 'xxxx';        // Password
    $dbroot = 'xxxx';        // DB Name

    session_start();
echo $_SESSION ['list']; // first session
    $host = mysql_connect($dbhost, $dbuser, $dbpass);
    if (mysql_select_db($dbroot,$host))
    {
        if (isset($_REQUEST["submit"]))
        {
            $sql = "SELECT * FROM `shifts` WHERE `id` = '" . $_REQUEST["shift"] . "'";
            $Result = mysql_query($sql);
            if (mysql_num_rows($Result) == 1)
            {
                $row = mysql_fetch_array($Result);
                $sql2 = "UPDATE `extensions` SET `appdata` = '" . $row["appdata"] . "' WHERE `context` = 'ivr-1' AND `exten` = 'tod-support' AND `priority` = '1';";
                $Result2 = mysql_query($sql2);
//                print '<font color=red>Updated ' . date('H:i:s m/d/Y') . ' </font><br>';
                header('location:index.php');
            } else {
                print 'A problem has occurred.  Something is broke.';
            }

        }

        
        print '<form method=POST>';
        print '<table align=center style="border: 1px solid #DDD; border-collapse: collapse;">';
        print '<tr><th style="background: #ABC; padding: 5px;" colspan=2>Update the PBX Routing</th></tr>';
        $sql = "SELECT * FROM `shifts` WHERE 1;";
        $Result = mysql_query($sql);
        while ($row = mysql_fetch_array($Result))
        {
            $sql2 = "SELECT * FROM `extensions` WHERE `appdata` = '" . $row["appdata"] . "'";
            $Result2 = mysql_query($sql2);
            print '<tr><td style="padding: 0 0 0 1em;"><input type=radio name=shift value="' . $row["id"] . '"';
            if (mysql_num_rows($Result2) == 1) { echo ' CHECKED'; }
            print '></td><td style="padding: 0 1em 0 0;">' . $row["description"] . '</td></tr>';
            
        }
echo $_SESSION ['last 24']; // second session
if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        if (preg_match('/^[1-9][0-9]?[0-9]?$/',$_POST["howfarback"]))
        {
            $howfarback = $_POST["howfarback"] * 24;
        } else
        {
            die('Number of days must be 1 - 999.');
        }
    } else $howfarback = 24;


    $cdr_start_time = time() - ($howfarback*60*60); // how far back to display
    $cdr_start_time_formatted = date('n/j/y g:i:sA',$cdr_start_time);
    $cdr_start_time_mysql = date(YmdHis,$cdr_start_time);
        
        print '<tr><td colspan=2 align=center style="padding: 1em;">';
        print '<input type=submit name=submit value="Submit">';
        print '</td></tr>';
        print '</table>';
        print '</form>';
        print '<table id="table_cdr" align="center" border="0" cellpadding="2" cellspacing="1">';
        print '<tr><center><th style="background: #ABC; padding: 5px;" colspan=2>Call Log - From ';
        echo $cdr_start_time_formatted;
        print '</th></tr></center>'; print "\n";
        print '<tr><th>Date</th><th>CallerID</th><th>Destination Context</th><th>Destination Extension</th><th colspan=2>Last Command</th><th>Duration Seconds</th><th>Status</th></tr>'; print "\n";

        $sql1 = "SELECT calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,disp
osition,accountcode FROM `cdr` WHERE calldate >=$cdr_start_time_mysql;";
        $Result1 = mysql_query($sql1);
        
        {
            print '<tr>';
            print '<td bgcolor="#E5E5E5" style="padding: 2px;">' . $row["calldate"] . '</td>';
            print '<td bgcolor="#E5E5E5" style="padding: 2px;">' . $row["clid"] . '</td>';
            print '<td bgcolor="#E5E5E5" style="padding: 2px;">' . $row["dcontext"] . '</td>';
            print '<td bgcolor="#E5E5E5" style="padding: 2px;">' . $row["dst"] . '</td>';
            print '<td bgcolor="#E5E5E5" style="padding: 2px;">' . $row["lastapp"] . '</td>';
            print '<td bgcolor="#E5E5E5" style="padding: 2px;">' . $row["lastdata"] . '</td>';
            print '<td bgcolor="#E5E5E5" style="padding: 2px;">' . $row["duration"] . '</td>';
            print '<td bgcolor="#E5E5E5" style="padding: 2px;">' . $row["disposition"] . '</td>';
            print '</tr>'; print "\n";
        }

        print '<tr><td colspan=2 align=center style="padding: 1em;">';
        print '</td></tr>';
        print '</table>';
        print '<center>';
        print '<form method="POST" action="cdr.php">';
        print 'Display <input maxlength=3 size=2 name=howfarback value=""> ';
        print '<input type="submit" name="submit" value="days back"></form>';

        print '<A HREF="cdr.php">Call Log</A>';
        print '</center>';
    }
    else
    {
        print 'Cannot connect to the database server.';
    }

?>
<!-- vim:ts=4:sw=4
--!>



When I try to get the second for to display the last 24 hours of calls it does not do it?? The table shows and everything!
User is offlineProfile CardPM

Go to the top of the page


no2pencil
post 25 Jun, 2008 - 01:45 AM
Post #2


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 5,512



Thanked 36 times

Dream Kudos: 2350

Expert In: Goofing Off

My Contributions


QUOTE
CODE

        $Result1 = mysql_query($sql1);
        
        {
            print '<tr>';

Uhm, I think you are missing your for statement. Whatever conditional testing you are wanting to perform here is missing.
User is offlineProfile CardPM

Go to the top of the page

ozziffied
post 26 Jun, 2008 - 09:57 PM
Post #3


New D.I.C Head

Group Icon
Joined: 12 Mar, 2008
Posts: 6


My Contributions


These were 2 separate pages that I have cut and pasted together and now they do not work, When they were separate they worked fine...
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/12/08 03:59AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month