Özel php işlevleri çağıran Garip davranışlar ise: PHP

3 Cevap

Flex PHP ile kodlama yaparken bir garip davranışlar karşılıklı. Bana durumu açıklayayım:

Ben iki funcions Diyelim ki var:

populateTable() //puts some data in a table made with flex
createXML() //creates an xml file which is used by Fusion Charts to create a chart

Şimdi i populateTable() yalnız çağırırsanız, masa verilerle doldurulan ama createXML() ile ararsanız, tablo nüfuslu almaz ama createXML() yapar Bu iş, yani bir xml dosyası oluşturur bulunuyor.

I aşağıdaki kodu çalıştırmak bile, sadece xml dosyası oluşturulur alır ama createXML önce populateTable () (denir oysa tablo) boş kalır. Herhangi bir fikir ne yanlış gidiyor olabilir?

MXML Bölüm

<mx:HTTPService id="userRequest" url="request.php" method="POST"  resultFormat="e4x">
    <mx:request xmlns="">
    	<getResult>send</getResult>
    </mx:request>

ve

<mx:DataGrid id="dgUserRequest" dataProvider="{userRequest.lastResult.user}" x="28.5" y="36" width="525" height="250" >
<mx:columns>
    <mx:DataGridColumn headerText="No." dataField="no" />
    <mx:DataGridColumn headerText="Name" dataField="name"/>
    <mx:DataGridColumn headerText="Age" dataField="age"/>
</mx:columns>

PHP Bölüm

<?php
//--------------------------------------------------------------------------
function initialize($username,$password,$database)
//--------------------------------------------------------------------------
{

# Connect to the database
$link = mysql_connect("localhost", $username,$password);
if (!$link) 
{
    die('Could not connected to the database : ' . mysql_error());
}
# Select the database
$db_selected = mysql_select_db($database, $link);
if (!$db_selected) 
{
    die ('Could not select the DB : ' . mysql_error());
}
//

populateTable();
createXML();



# Close database connection

}

//--------------------------------------------------------------------------
populateTable()
//--------------------------------------------------------------------------
{   
if($_POST['getResult'] == 'send')
{

   $Result = mysql_query("SELECT * FROM session" );
   $Return = "<Users>";
   $no = 1;
   while ( $row = mysql_fetch_object( $Result ) )
   {
   $Return .= "<user><no>".$no."</no><name>".$row->name."</name><age>".$row->age."</age><salary>". $row->salary."</salary></session>";
     $no=$no+1; 
   $Return .= "</Users>";
   mysql_free_result( $Result );
   print ($Return);
}


//--------------------------------------------------------------------------
createXML()
//--------------------------------------------------------------------------
{   
$users=array
(
"0"=>array("",0),
"1"=>array("Obama",0),
"2"=>array("Zardari",0),
"3"=>array("Imran Khan",0),
"4"=>array("Ahmadenijad",0)
);
$selectedUsers=array(1,4); //this means only obama ve ahmadenijad are selected ve the xml file will contain info related to them only 

//Extracting salaries of selected users
$size=count($users);
for($i = 0; $i<$size; $i++)
{
  //initialize temp which will calculate total throughput for each protocol separately
  $salary = 0;
  $result = mysql_query("SELECT salary FROM userInfo where name='$users[$selectedUsers[$i]][0]'");
  $row = mysql_fetch_array($result))
  $salary = $row['salary'];
 }
  $users[$selectedUsers[$i]][1]=$salary;
}

//creating XML string

$chartContent = "<chart caption=\"Users Vs Salaries\" formatNumberScale=\"0\" pieSliceDepth=\"30\" startingAngle=\"125\">";
for($i=0;$i<$size;$i++)
{ 
 $chartContent .= "<set label=\"".$users[$selectedUsers[$i]][0]."\" value=\"".$users[$selectedUsers[$i]][1]."\"/>";
}
$chartContent .= "<styles>" .
        			"<definition>" .
        				"<style type=\"font\" name=\"CaptionFont\" size=\"16\" color=\"666666\"/>" .
        				"<style type=\"font\" name=\"SubCaptionFont\" bold=\"0\"/>" .
        			"</definition>" .
        			"<application>" .
        				"<apply toObject=\"caption\" styles=\"CaptionFont\"/>" .
        				"<apply toObject=\"SubCaption\" styles=\"SubCaptionFont\"/>" .
        			"</application>" .
        			"</styles>" .
        "</chart>";



$file_hvele = fopen('ChartData.xml','w'); 
fwrite($file_hvele,$chartContent);
fclose($file_hvele);
}

initialize("root","","hiddenpeak");
?>

3 Cevap

Lütfen createXML function aynı tam sayfa nesil xml üretir, ve application / xml bir Content-Type gönderirse o zaman might tablo şeyler ayrıştırmaz mümkün. Kodunu sağlanan kadar tekrar, bu sadece tahmin olacaktır.

Peki, tek cevap createXML yere (muhtemelen global) tabloyu siler / yazar olmasıdır. Tekrar koduna lütfen bir göz atın.

Yukarıda verilen yorum gibi, daha fazla bilgi / kodları / backend db olmadan zor olacak:

ancak benim vahşi misafir:

populateTable () db veri eklemek

populateTable tarafından eklenen createXML () sorgu verileri ().

2 fark db baðlant benziyor. Bazı db eğer öyleyse, db bağl kapatmadan önce () emin populateTable içinde bunu yapmak, u kodu içinde taahhüt edersiniz gereklidir.