Jump to content

Recommended Posts

Hello! I'm super stoked I found you guys, this is the quickest, least amount of crap php site I have been able to find and I hope you can help me out. I am running PHP 5.2.4 and connecting to an Access database generated by our phone switch (I would prefer MySql, but the switch software creates and maintains the database, I'm just tapping into it).

 

I am fairly new to PHP and looking to get some help with a large query I set up for our phone system. Basically, what I want to do, is make the huge hand-coded query more dynamic and smaller so that it returns results faster and I don't have to edit a bunch of code every time something changes (which is often!).

 

Here is the query:

 

          $sqlCJB = "SELECT Count(*) AS TotalNumberOfCallsCJB FROM AllInfo WHERE Extension = '3911' AND Date=#".$id."#";
		$timeCJB = "SELECT Date, Extension, sum(DurationS) AS CountOfDurationCJB
			FROM AllInfo 
			WHERE Extension = '3911' 
				AND IO = 'Out' 
				AND Date=#$id#
			GROUP BY Date, Extension, IO 
		   ";	

            $queryCJB = odbc_exec($odbc,$sqlCJB) or die(odbc_errormsg());
					$timequeryCJB = odbc_exec($odbc,$timeCJB) or die(odbc_errormsg());

/*		***	Query Carrie J Boreham*** */
		            while($row = odbc_fetch_array($queryCJB)) {
               
		      echo "<tr>";
                  echo "<td class=\"borderTable\"><center>3911</center></td class=\"borderTable\">";
                  echo "<td class=\"borderTable\"><center>Carrie Boreham</center></td class=\"borderTable\">"; 
                  echo "<td class=\"borderTable\"><center>".$row['TotalNumberOfCallsCJB']."</center></td class=\"borderTable\">";

			  		while($row = odbc_fetch_array($timequeryCJB)){

			  echo "<td class=\"borderTable\"><center>".minutestoHours($row["CountOfDurationCJB"])."</center></td class=\"borderTable\">";	}
			  
            } // end while

 

Then I have this in the file 50 times under different query and sql names for all the employees. What I would like to do is figure out how to make this loop on itself based on another file that I can edit on the fly to simple add or remove someone from the list, then have the output sortable by column ( I don't know how to make this sortable. )

 

            echo "<center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"borderTable\">
<tr><th class=\"borderTable\">   Extension   </th><th class=\"borderTable\">     Username     </th><th class=\"borderTable\">Total Dials</th><th class=\"borderTable\">Total Talk Time</th></tr>";

 

Think maybe someone can help me out on this? I know it's probably pretty simple for someone who does this all the time, I just can't figure it out.

Link to comment
https://forums.phpfreaks.com/topic/111873-loops-and-arrays-help/
Share on other sites

For the users list, you could simply create a text file that you edit.  Search the board on handling files or look at the manual under http://us.php.net/manual/en/function.file.php.  That should get you started.

 

Then you just feed the extension into the query as a variable in a loop.  file() will split the contents of the file into an array already so you can just use foreach() or a while() loop to run through the array.

 

As far as sorting by column, simply pass a variable to the query and use an "ORDER BY" clause (this works in any DB).

Wow, you make it sound so simple!! I've never used any of these functions before!

 

I know it's asking a lot, but think you might be able to hepl me with coding this part:

 

Then you just feed the extension into the query as a variable in a loop.  file() will split the contents of the file into an array already so you can just use foreach() or a while() loop to run through the array.

 

I'm so new at this I feel like I'm trying to speak French and I only understand how to say yes, and no, and ask where the bathroom is at! I can usually look at examples and logically figure it out then try to adapt it to my own purposes, but I've been trying to do that for this now for a couple months (as I find the time) and just can't seem to figure it out!

From your query you posted it looks like all you need to query the DB for a user is their phone extension, right?  If so, I'd create a text file with the following (just a list of extension numbers):

 

1234

1343

2345

 

Then:

$exts = file('/home/user/phones.txt');
foreach ($exts as $num => $ext) {
    $query = "SELECT * FROM table WHERE ext = $ext";
    // do whatever else needs to be done here
}

 

Or if you want to just do one query where you grab all of the records at once:

 

$exts = file('/home/user/phones.txt');
$str .= "SELECT * FROM table WHERE ext IN (".implode(",",$exts.)")";
    // do whatever else needs to be done here
}

 

Does that help?

Oh... well I wasn't clear on the intent.  You can still get totals within one query.  You should be able to use a combination of DISTINCT, COUNT and GROUP BY to get what you need.  I'd suggest posting in the database boards to get that information.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.