Thetcm Posted April 6, 2009 Share Posted April 6, 2009 Sorry if I never answered for my last question. I ended up using the $var.="" idea and it worked. When I went to reply the thread was locked and marked as solved. Another problem arised. I need to fill a javascript array with an ajax call. echo "<script type='text/javascript' language='javascript'>tableauIDFiche.push('".$record->getRecordId()."')</script>"; doesn't work. I tried variations with Eval and Document.write to not avail. Any idea? Link to comment https://forums.phpfreaks.com/topic/152811-push-data-into-javascript-array-from-php/ Share on other sites More sharing options...
kenrbnsn Posted April 6, 2009 Share Posted April 6, 2009 You need to use AJAX techniques to do that. You can not directly access PHP information from Javascript, since they run at different times. Ken Link to comment https://forums.phpfreaks.com/topic/152811-push-data-into-javascript-array-from-php/#findComment-802486 Share on other sites More sharing options...
Thetcm Posted April 6, 2009 Author Share Posted April 6, 2009 Yes. I know that. My PHP line is in an ajax call. I'm trying to fill a javascript array with my database's IDs. Link to comment https://forums.phpfreaks.com/topic/152811-push-data-into-javascript-array-from-php/#findComment-802498 Share on other sites More sharing options...
kenrbnsn Posted April 6, 2009 Share Posted April 6, 2009 Can you post more of your code? Ken Link to comment https://forums.phpfreaks.com/topic/152811-push-data-into-javascript-array-from-php/#findComment-802500 Share on other sites More sharing options...
Thetcm Posted April 6, 2009 Author Share Posted April 6, 2009 Well I deleted that but... <script type="text/javascript" language="javascript"> var tableauIDFiche = new Array(); </script> I create the array here, then I do a search through the database with Ajax. <?php if(isset($_GET['numProd'])) { session_name("sessionname"); session_start(); require_once 'FileMaker.php'; require_once 'FMLayout.php'; $fm = new FileMaker ($_SESSION ['db'], $_SESSION ['server'], $_SESSION ['user'], $_SESSION ['pass']); $NumProd=$_GET['numProd']; $NomProd=$_GET['nomProd']; $Reference=$_GET['reference']; $Fabricant=$_GET['fabricant']; $MSDS = $_GET['MSDS']; $length = 25; $from = $vraiFrom; $findCommand = $fm->newFindCommand(LISTE_PROD); $findCommand->setRange($from, $length); $findCommand->addFindCriterion('field_name', $NumProd); $findCommand->addFindCriterion('GLOBALINFOPRODUIT_LocalMsds_Web::NomProduit_t', $NomProd); $findCommand->addFindCriterion('Reference_t', $Reference); $findCommand->addFindCriterion('GLOBALINFOPRODUIT_LocalMsds_Web::FicheOriginaleTexte_t', $MSDS); $findCommand->addFindCriterion('GLOBALFABRICANT_GlobalMsds_LocalMsds_Web::Nom_t', $Fabricant); $findCommand->addFindCriterion('GLOBALINFOPRODUIT_LocalMsds_Web::_FKLangue_t', $_SESSION['langue']); $resultListe = $findCommand->execute(); if(FileMaker::isError($resultListe)){ $resultListe =""; $nbTrouve=0; }else{ $records = $resultListe->getRecords(); $nbTrouve = $resultListe->getFoundSetCount(); } if($nbTrouve<=0){ echo "<h1>Aucunes fiches trouvées<h2>"; die; } $nbAffichage = $from + $length; $fromAfficher = $from+1; $page=""; foreach ($records as $record){ $page.= "<script type='text/javascript' language='javascript'>tableauIDFiche.push('".$record->getRecordId()."')</script>"; $leOnClick='onclick="submitRech();setComplete('.$record->getRecordId().');jQuery(\'#first\').slideDown(500);"'; $page.='<div id="trBgColor'.$record->getRecordId().'" onMouseOver="changeColor(this.id);" onMouseOut="returnColor(this.id);"><table width="900" border="0" style="font-size:12px; text-align:left;" cellspacing="0" cellpadding="0"> <tr height="50" > <td '.$leOnClick.' width="100" align="center" style="font-size:14px"><b> '.nl2br( $record->getField('NumeroFiche_n', 0)).' </b></td> <td '.$leOnClick.' width="330"><TABLE border="0" cellspacing="0" cellpadding="0" style="height:100%"><TR><TD>'; $lienPDF=""; $relatedRecords = $record->getRelatedSet("GLOBALINFOPRODUIT_LocalMsds_Web"); if (FileMaker::isError($relatedRecords) === false) { $master_record = $record; foreach ($relatedRecords as $record) { if($record->getField('GLOBALINFOPRODUIT_LocalMsds_Web::_FKLangue_t', 0)==$_SESSION['langue']){ $page.=nl2br($record->getField('GLOBALINFOPRODUIT_LocalMsds_Web::NomProduit_t', 0)); } if($record->getField('GLOBALINFOPRODUIT_LocalMsds_Web::FicheOriginale_m', 0)!=""){ $lienPDF.="<a href='pdf.php?-url=".urlencode($record->getField('GLOBALINFOPRODUIT_LocalMsds_Web::FicheOriginale_m', 0))."' target='_blank'>".$record->getField('GLOBALINFOPRODUIT_LocalMsds_Web::_FKLangue_t', 0)."</a>"; $lienPDF.="<br>"; }else{ $lienPDF="aucunes langues"; } } $record = $master_record; } if($record->getField('GLOBALFABRICANT_GlobalMsds_LocalMsds_Web::SiteWeb_t', 0)!=""){ $lienPage='<a href="'.$record->getField('GLOBALFABRICANT_GlobalMsds_LocalMsds_Web::SiteWeb_t', 0).'" target="_blank">'.$record->getField('GLOBALFABRICANT_GlobalMsds_LocalMsds_Web::SiteWeb_t', 0).'</a>'; }else{ $lienPage=""; } $page.='</TD></TR><TR><TD>'.nl2br( $record->getField('Reference_t', 0)).'</TD></TR></TABLE></td> <td '.$leOnClick.' width="230" style=""> '.nl2br( $record->getField('GLOBALFABRICANT_GlobalMsds_LocalMsds_Web::Nom_t', 0)).'<br> '.$lienPage.' </td> <td width="130" style=""> Disponible en <br>'.$lienPDF.' </td> <td '.$leOnClick.' width="20" style="">'; if($record->getField('ETAT_LocalMsds_Web::NomWeb_t', 0)!=""){ $page.='<img src="images/etats/'.$record->getField('ETAT_LocalMsds_Web::NomWeb_t', 0).'.png" />'; } $page.='</td></tr></table></div>'; $page.='<div style="height:1px;background-color:#545454"></div>'; } echo $page; } else { die; } ?> There could be mistakes in the code because I cut some part, disregarde that. As you can see, the AJAX call is trying (well, I input that) to insert data in the javascript array but I'm not sure what syntax to use. Link to comment https://forums.phpfreaks.com/topic/152811-push-data-into-javascript-array-from-php/#findComment-802510 Share on other sites More sharing options...
unska Posted April 6, 2009 Share Posted April 6, 2009 You should use JQuery for AJAX, you can download it at http://www.jquery.com Here's an example of calling a php file and moving what ever the file prints to a html element: function echo(string) { $.ajax({ type: "GET", url: "myfile.php?string="+string, success: function(msg){ if (msg) { document.getElementById("text").innerHTML = msg; } } }); } Link to comment https://forums.phpfreaks.com/topic/152811-push-data-into-javascript-array-from-php/#findComment-802519 Share on other sites More sharing options...
Thetcm Posted April 6, 2009 Author Share Posted April 6, 2009 Doesn't look all that much different from regular AJAX. And it wouldn't help me. The AJAX request returns something, so I can't insert what it return into the javascript array. I need to insert data while the ajax call is being done. Then it doesn't matter if there's a bunch of script tags in the code once it shows up. Link to comment https://forums.phpfreaks.com/topic/152811-push-data-into-javascript-array-from-php/#findComment-802527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.