hi all.
one doubt/....
now i am using class in PHP for my pgms...
my class is
GetAll.inc.php
<?
class GetAll{
function GetRegion($num)
{
$query=mysql_query("select reg_id ,reg_name from cregion ORDER BY reg_name");
echo"<select size=\"1\" name=\"RN\">";
echo "<option >Choose a Region</option>";
while($row = mysql_fetch_array($query))
{
$reg=$row[reg_id];
echo "<option value=\"$reg\"";
if ($reg == $num)
echo " selected";
echo ">$row[reg_name]</option>n";
}
echo "</select>";
}
}
?>
****************************************
i am making use of this class in another php file like this and i am getting result also...(ie. for populating dropdown box Region)
that part of code is this:
<tr>
<td width="158" height="22" align="right" class="officeBearers">Region</td>
<td width="5" height="22"> </td>
<td width="532" height="22">
<?php
include("connect.inc.php");
$objmysqlcon= new Connect();
$objmysqlcon->start_connectmysql();
include("GetAll.inc.php");
$post[0]=$_POST['RN'];
$O=new GetAll();
$O->GetRegion($post[0]);
?>
</td>
</tr>
Now i want to save a combination for making use for search later .....
like
$search_strval = Trim($vREGID).Trim($vESTNAME);
$search_strval .= Trim($vCOMPUTERIZED_YR);
$qrysearch_str= "update hos_computer SET hos_computer.search_str = '$search_strval' where ESTCD ='$vESTCD'";
$searchresult_str=mysql_query($qrysearch_str)
or die("Error in query:$qrysearch_str.". mysql_error());
here
$vREGID=$_POST['RN']; which is from that class file.
i need to get the region name in place of this and form my serach_strval like
$search_strval = Trim($vREGIONNAME).Trim($vESTNAME);
$search_strval .= Trim($vCOMPUTERIZED_YR);
HOW TO GET THIS REGION NAME FROM THAT CLASS.....IN MY DROP DOWN PASSING VALUE IS REGIONID AND DISPLAYING VALUES IS REGIONNAME...SO I WANT THIS DISPLAYING VALUE TO BE IN SEARCH STRING....
pls help me
thanx
ckb
accessing class variables in PHP
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Producing a simplified example..
$useval=$O->getRegion() could be replaced by $o->$region without a method call but this
is considered bad practice.
Also you should name the class constructor,normally the first function the same as the class name
.
(When I say "method" this is Object Oriented speak for the PHP functions within a class.)
Hope that helps
Code: Select all
<?php
class temp
{
var $region; // The class variable to use.
function temp($value)
{
$this->setRegion($value);
}
function getRegion()
{
return $this->region;
}
function setRegion($region)
{
$this->region=$region;
}
}
// Main block creates the Object and assigns the $region variable within it.
$O=new $temp("Europe");
...
// We need to get the value...
$useval=$O->getRegion();
?>is considered bad practice.
Also you should name the class constructor,normally the first function the same as the class name
(When I say "method" this is Object Oriented speak for the PHP functions within a class.)
Hope that helps