By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,463 Members | 3,115 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,463 IT Pros & Developers. It's quick & easy.

Using variables from the global scope inside a function.

P: 39
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
Share this Question
Share on Google+
3 Replies


10K+
P: 13,264
Read up on global
Aug 19 '08 #2

Markus
Expert 5K+
P: 6,050
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
Expert 5K+
P: 5,058
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

Post your reply

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