473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using variables from the global scope inside a function.

39 New Member
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('us e_rnumber', 'user', "WHERE `use_id`='$myID '");

echo "$radio";


$xajax = new xajax();
$xajax -> regf('updata');
$xajax -> processRequest( );
$ajax = $xajax -> getJavascript(" ", "../includes/xajax/xajax_js/xajax_uncompres sed.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>NATU RE</TD>
<td width=250 align=left valign=top>LOCA TION</TD>
<td align=left valign=top>UNIT </TD>
<td align=left valign=top>BACK UP</TD>
<td align=left valign=top>ZONE </TD>
<td align=left valign=top>OCA #</TD>
<td align=left valign=top>DISP R</TD>
<td align=left valign=top>D</TD></tr>';
$number=1;
$qc = mysql_query("SE LECT * FROM `cad_cad` ORDER BY `soc_id` ASC");
while ($rc = mysql_fetch_ass oc($qc))
{
extract($rc);
$soc_Date = trim($soc_Date) ;
$soc_Received = trim($soc_Recei ved);
$soc_Dispatched = trim($soc_Dispa tched);
$soc_Arrived = trim($soc_Arriv ed);
$soc_Completed = trim($soc_Compl eted);
$soc_Nature = trim($soc_Natur e);
$soc_Cfs = trim($soc_Cfs);
$soc_Location = trim($soc_Locat ion);
$soc_Unit = trim($soc_Unit) ;
$soc_Backup = trim($soc_Backu p);
$soc_Zone = trim($soc_Zone) ;
$soc_Case = trim($soc_Case) ;
$soc_Dispatcher = trim($soc_Dispa tcher);
$soc_Dispositio n = trim($soc_Dispo sition);
$b1 = '';
$b2 = '';
$radio = '';
$sound = '';
if (empty($soc_Rec eived) && empty($soc_Disp atched) && empty($soc_Arri ved))
{
$tdclass = "tdrec";
$b1 = '<blink>';
$b2 = '</blink>';
}
if ($soc_Received != "" && empty($soc_Disp atched) && empty($soc_Arri ved))
{
$tdclass = "tdrec";
$b1 = '<blink>';
$b2 = '</blink>';
}


if ($soc_Received != "" && empty($soc_Disp atched) && empty($soc_Arri ved) && $soc_Unit == $radio) $sound = "123454";


if ($soc_Received != "" && $soc_Dispatched !="" && empty($soc_Arri ved)) $tdclass = "tdyel";
if ($soc_Received != "" && $soc_Dispatched !="" && $soc_Arrived != "") $tdclass = "tdgreen";
if (ltrim($soc_Sta tus)=='Complete d') $tdclass="tdcom pl";


$code .= "<tr>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>". $number."</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Date{$b 2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Receive d{$b2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Dispatc hed{$b2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Arrived {$b2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Complet ed{$b2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Nature{ $b2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ sound}$soc_Loca tion{$b2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Unit{$b 2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Backup{ $b2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Zone{$b 2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'><a href=\"?oca=$so c_Cfs\">$soc_Ca se</a></span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Dispatc her{$b2}</span></td>
<td align=left valign=top class='".$tdcla ss."'><span class='text'>{$ b1}$soc_Disposi tion{$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,sa ns-serif; height:25px; background-color:#ffffff; background-image:url(/images/back03.gif); border-style:solid; border: 1 solid #aaaaaa; }
</style>

<meta http-equiv="imagetoo lbar" content="no" />
<script type="text/javascript">
function blinkIt() {
if (!document.all) return;
else {
for(i=0;i<docum ent.all.tags('b link').length;i ++){
s=document.all. tags('blink')[i];
s.style.visibil ity=(s.style.vi sibility=='visi ble')?'hidden': 'visible';
}
}
}
</script>

</HEAD>
<BODY BGCOLOR="#fffff f" alink='#000000' vlink='#000000' link='#000000' leftmargin=0 rightmargin=0 bottommargin=0 topmargin=0 oncontextmenu=" return false" onload="setInte rval('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>Call er Information</TD>
<td align=left valign=top>Call Notes</TD>
</tr>';

$oca = $_GET['oca'];
$qc = mysql_query("SE LECT * FROM `cad_cad` WHERE `soc_Cfs` = '$oca'");
if (mysql_num_rows ($qc) > 0)
{
while ($rc = mysql_fetch_ass oc($qc))
{
extract($rc);
echo "
<tr>
<td align=left width=25% valign=top class='td1'>
Last Name: <font color=yellow>$s oc_Last<br><fon t color=000000>
First Name: <font color=yellow>$s oc_First<p><fon t color=000000>

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

<font color=white>
Phone: <font color=yellow>$s oc_Phone<p>
<Font color=white>
10-15 Time: <font color=yellow>$s oc_InCustodyTim e<p>

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

<td align=left valign=top class='td1'>$so c_Notes</td>
</tr>";
}
}
echo "</table>";
echo "<br><br><i nput type=button value=\"Back To CAD\" class='bttn' onclick=\"locat ion.replace('ca ddisplay1.php') \"><br><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 1804
r035198x
13,262 MVP
Read up on global
Aug 19 '08 #2
Markus
6,050 Recognized Expert Expert
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 Recognized Expert Expert
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
20345
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()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this property or method." in IE, and nothing happens in Firebird.
5
3222
by: A | last post by:
Hi, Consider this code: //Header File - Foo.h int i = 0; // non-static global variable class Foo{ ...
2
1878
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
3249
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 tell me why these DIVs don't drift to the left as they are supposed to? <script language="javascript">
9
8112
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 tried: onclick="calculate('<script type="text/javascript">document.write(points);</script>');
12
3458
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 properly. It works, for example, when invoking functions (alert('hello')), but not for defining functions. The case occurs when retrieving the javascript code with
13
2137
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 parts of the code, but as far as I can see, the way objects work in javascript is quite awkward. I had it working the way they suggest in the book, and it was going OK until I wanted to call one object method from another - I couldn't find a...
10
2662
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 the more specialist aspects of the job but am now completely stuck on something I would have thought were simplicity itself... I need to have a large number of global variables visible inside functions - it's not possible to pass them into the...
6
1298
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 professor which will act upon members of the site (teachers, professors) who will login. In my class professor I have a function: function login() {
26
1784
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
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.