473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using variables from the global scope inside a function.

I have the following php code, at the top I am pulling a piece of data from a query and I echo the results with no problem, I am using Ajax with this page as well and further down the page when I try to reference the same $radio it dosnt show anything.

Line 7 is where i get the current radio number assigned to the person that is loged in. and line 80 is where I try to use it again.

Thanks


[php]<?
include('../application.php');
include('../includes/xajax/xajax.inc.php');
set_time_limit(0);
if ($myID==0) goto('../index.php');

$radio = sql::getval('use_rnumber', 'user', "WHERE `use_id`='$myID'");

echo "$radio";


$xajax = new xajax();
$xajax -> regf('updata');
$xajax -> processRequest();
$ajax = $xajax -> getJavascript("", "../includes/xajax/xajax_js/xajax_uncompressed.js");

function updata()
{
$objResponse = new xajaxResponse();
$objResponse -> assign('dinf', "innerHTML", get_mydata());
return $objResponse;
}

function get_mydata()
{

$code = "<table border=0 width=100% cellpadding=2 cellspacing=1 bgcolor=000000>";
$code .= '<tr class="header">
<td align=left width=10 valign=top>#</TD>
<td align=left valign=top>DATE</TD>
<td align=left valign=top>REC</TD>
<td align=left valign=top>DISP</TD>
<td align=left valign=top>ARR</TD>
<td align=left valign=top>COMP</TD>
<td align=left valign=top>NATURE</TD>
<td width=250 align=left valign=top>LOCATION</TD>
<td align=left valign=top>UNIT</TD>
<td align=left valign=top>BACKUP</TD>
<td align=left valign=top>ZONE</TD>
<td align=left valign=top>OCA #</TD>
<td align=left valign=top>DISPR</TD>
<td align=left valign=top>D</TD></tr>';
$number=1;
$qc = mysql_query("SELECT * FROM `cad_cad` ORDER BY `soc_id` ASC");
while ($rc = mysql_fetch_assoc($qc))
{
extract($rc);
$soc_Date = trim($soc_Date);
$soc_Received = trim($soc_Received);
$soc_Dispatched = trim($soc_Dispatched);
$soc_Arrived = trim($soc_Arrived);
$soc_Completed = trim($soc_Completed);
$soc_Nature = trim($soc_Nature);
$soc_Cfs = trim($soc_Cfs);
$soc_Location = trim($soc_Location);
$soc_Unit = trim($soc_Unit);
$soc_Backup = trim($soc_Backup);
$soc_Zone = trim($soc_Zone);
$soc_Case = trim($soc_Case);
$soc_Dispatcher = trim($soc_Dispatcher);
$soc_Disposition = trim($soc_Disposition);
$b1 = '';
$b2 = '';
$radio = '';
$sound = '';
if (empty($soc_Received) && empty($soc_Dispatched) && empty($soc_Arrived))
{
$tdclass = "tdrec";
$b1 = '<blink>';
$b2 = '</blink>';
}
if ($soc_Received != "" && empty($soc_Dispatched) && empty($soc_Arrived))
{
$tdclass = "tdrec";
$b1 = '<blink>';
$b2 = '</blink>';
}


if ($soc_Received != "" && empty($soc_Dispatched) && empty($soc_Arrived) && $soc_Unit == $radio) $sound = "123454";


if ($soc_Received != "" && $soc_Dispatched !="" && empty($soc_Arrived)) $tdclass = "tdyel";
if ($soc_Received != "" && $soc_Dispatched !="" && $soc_Arrived != "") $tdclass = "tdgreen";
if (ltrim($soc_Status)=='Completed') $tdclass="tdcompl";


$code .= "<tr>
<td align=left valign=top class='".$tdclass."'><span class='text'>".$number."</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Date{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Received{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Dispatched{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Arrived{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Completed{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Nature{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$sound}$soc_Location{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Unit{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Backup{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Zone{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'><a href=\"?oca=$soc_Cfs\">$soc_Case</a></span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Dispatcher{$b2}</span></td>
<td align=left valign=top class='".$tdclass."'><span class='text'>{$b1}$soc_Disposition{$b2}</span></td>{$sound}
</tr> ";
$number++;
}
$code .= "</table>";
return $code;
}

?>
<HTML>
<HEAD>
<TITLE>Cad Calls</TITLE>
<style>
.header {font-size: 14px; font-family: "Tahoma, Arial"; color:#ffffff; background-color: #719ece; }
#results TD { font-size:14px; font-family: \"Tahoma, Arial\"; }
.td1{font-size: 14px; font-family: "Tahoma, Arial"; color:#ffffff; background-color: #000000; padding: 2px; }
.td2{font-size: 14px; font-family: "Tahoma, Arial"; color:#000000; background-color: #eeeeee; padding: 2px; }
.td3{font-size: 14px; font-family: "Tahoma, Arial"; color:#dcdcdc; background-color: #000000; padding: 2px; }
.td_zone{font-size: 14px; font-family: "Tahoma, Arial"; color:#000000; background-color: #eeeeee; color:#cc0000 }
.text1{font-size: 14px; font-family: "Tahoma, Arial"; color:#000000; background-color: #ffffff;}
.text2{font-size: 14px; font-family: "Tahoma, Arial"; color:#000000; background-color: #ececec;}
.text{font-size: 14px; font-family: "Tahoma, Arial";}
.tdcompl{font-size: 14px; font-family: "Tahoma, Arial"; color:#000000; background-color: #ffffff; padding: 2px; }
.tdrec{font-size: 14px; text-decoration: blink; font-family: "Tahoma, Arial"; color:#ffffff; background-color: #ff3300; padding: 2px; }
.tdyel{font-size: 14px; font-family: "Tahoma, Arial"; color:#000000; background-color: #ffff00; padding: 2px; }
.tdgreen{font-size: 14px; font-family: "Tahoma, Arial"; color:#ffffff; background-color: #66cc00; padding: 2px; }
.bttn { font-size:12px; font-family:Arial,sans-serif; height:25px; background-color:#ffffff; background-image:url(/images/back03.gif); border-style:solid; border: 1 solid #aaaaaa; }
</style>

<meta http-equiv="imagetoolbar" content="no" />
<script type="text/javascript">
function blinkIt() {
if (!document.all) return;
else {
for(i=0;i<document.all.tags('blink').length;i++){
s=document.all.tags('blink')[i];
s.style.visibility=(s.style.visibility=='visible') ?'hidden':'visible';
}
}
}
</script>

</HEAD>
<BODY BGCOLOR="#ffffff" alink='#000000' vlink='#000000' link='#000000' leftmargin=0 rightmargin=0 bottommargin=0 topmargin=0 oncontextmenu="return false" onload="setInterval('blinkIt()',500)">

<?php
echo $ajax;
if (isset($_GET['oca']))
{

echo '
<table border=0 width=100% cellpadding=2 cellspacing=1 bgcolor=000000>
<tr class="header">
<td align=left width=25% valign=top>Caller Information</TD>
<td align=left valign=top>Call Notes</TD>
</tr>';

$oca = $_GET['oca'];
$qc = mysql_query("SELECT * FROM `cad_cad` WHERE `soc_Cfs` = '$oca'");
if (mysql_num_rows($qc) > 0)
{
while ($rc = mysql_fetch_assoc($qc))
{
extract($rc);
echo "
<tr>
<td align=left width=25% valign=top class='td1'>
Last Name: <font color=yellow>$soc_Last<br><font color=000000>
First Name: <font color=yellow>$soc_First<p><font color=000000>

Address:<br>
<font color=yellow>$soc_Address<br>
$soc_City, $soc_State. $soc_ZipCode<p>

<font color=white>
Phone: <font color=yellow>$soc_Phone<p>
<Font color=white>
10-15 Time: <font color=yellow>$soc_InCustodyTime<p>

<Font color=white>
CFS: <font color=yellow>$soc_Cfs
</td>

<td align=left valign=top class='td1'>$soc_Notes</td>
</tr>";
}
}
echo "</table>";
echo "<br><br><input type=button value=\"Back To CAD\" class='bttn' onclick=\"location.replace('caddisplay1.php')\"><b r><br>";
}
else
{
echo "<div id='dinf'>". get_mydata() . "</div>";
echo "
<script type=\"text/javascript\">
function timeupdate()
{
t = setTimeout(\" timeupdate()\", 15000);
xajax_updata();
}
timeupdate();
</script>";
}
?>
</table></BODY></HTML>
[/php]
Aug 19 '08 #1
3 1777
r035198x
13,262 8TB
Read up on global
Aug 19 '08 #2
Markus
6,050 Expert 4TB
Functions have 'local scope' and won't access the 'global' scope unless you tell it to.

Adding on to Ro's post:
inside the function set your variables with the keyword 'global'
Expand|Select|Wrap|Line Numbers
  1. func...
  2.     global $a, $x, $y;
  3.  
EDIT: I'm an idiot and all the above is on php.net

-_-
Aug 19 '08 #3
Atli
5,058 Expert 4TB
I've changed the title of this thread to better describe it's contents.

Please remember to provide a meaningful Title for any threads started (see Use a Good Thread Title).
This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR.
Aug 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
5
by: A | last post by:
Hi, Consider this code: //Header File - Foo.h int i = 0; // non-static global variable class Foo{ ...
2
by: katekukku | last post by:
HI, Could anyone please tell me what are static variables and what exactly are there features. I am a little bit confused. Thank You
15
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone...
9
by: DesignerNut | last post by:
Can a javascript array value be used in an onclick event? I haven't been successful in getting it to work so I'm wondering if it even can be done. onclick="calculate('some array value'); I've...
12
by: knocte | last post by:
Hello. I have always thought that the eval() function was very flexible and useful. If I use it, I can define functions at runtime!! However, I have found a case where eval() does not work...
13
by: Andy Baxter | last post by:
Can anyone recommend a good online guide to using objects in javascript? The book I bought (DHTML Utopia) suggests using objects to keep the code clean and stop namespace clashes between different...
10
by: Charles O'Flynn | last post by:
As a complete newcomer (2-3 days) to PHP, although not to programming in general, I have 'dived in' to start a small project to read and parse an XML data stream. I have already worked out most of...
6
by: Harris Kosmidhs | last post by:
Hello, I try to develop an application with a controller (which acts as the model also, meaning it performs calls to db and all this) and a view. For example, there's a controller called...
26
by: optimistx | last post by:
A variable in global scope var a1 = 'contents of global variable a1'; can be references (with some limitations) as window; // or window.a1; // or even window;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.