napsternapster Posted September 2, 2009 Share Posted September 2, 2009 Afternoorn people, I'm trying to read data from a database using javascript/php. After getting the information from the database using javascript/php.The information must be sent to a javascript page and stored in array . Problem I get the information from the database but The problem is senting itto the javascript page to be validate. <?php include_once "connex.php"; $conn = new dbConnector(); if(!isset($_POST['txtcounter'])) { include_once "fmbasicinfo.php"; } else { $error .="information saved. To go back to the basic information form click the following link <a href=\"basicinfor.php\">Basic information</a>"; include_once "fmbasicinfo2.php"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Basic information</title> <script language="javascript" type="text/javascript" src="loadimage2.js"></script> <link rel="stylesheet" href="savinginformationcss.css" type="text/css" /> <?php $information = "<script type=\"text/javascript\" language=\"javascript\"> function checkname() {"; $sql = $conn->query("select valgroup_id,valgroup_desc from validating_group"); if(mysql_num_rows($sql) > 0) { while($recs = $conn->fetchArray($sql)) { $id = $recs['valgroup_id']; $desc = $recs['valgroup_desc']; echo $desc." "; //$information .= "[\"$id\",\"$desc\"]"; } } $information .= " } </script>"; echo $information; ?> </head> <body> <?php echo $display_info; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted September 2, 2009 Share Posted September 2, 2009 Your not able to use a phpscript inside a javascript, but You CAN use a javascript in your php-script this is because PHP is server side and js is client side Quote Link to comment Share on other sites More sharing options...
napsternapster Posted September 3, 2009 Author Share Posted September 3, 2009 I tried so many ways of solving this problem but nothing is close to perfection. This is a php code reading a database with embidded javascript inside.Any one who have alternative way of solving problem I'll be pleased for his/her assistance <?php $information = "<script type=\"text/javascript\" language=\"javascript\">"; $sql = $conn->query("select valgroup_id,valgroup_desc from validating_group"); if(mysql_num_rows($sql) > 0) { // $ArrayTest = array(10,10); // $count = 0; while($recs = $conn->fetchArray($sql)) { $id = $recs['valgroup_id']; $desc = $recs['valgroup_desc']; $information .= $id.$desc; } } $information .= "</script>"; echo $information; ?> Quote Link to comment Share on other sites More sharing options...
mrwutang Posted September 5, 2009 Share Posted September 5, 2009 ajax is the answer to your prolem homes. . Get javascript on the clientside to send a "GET" request to the php on the server side and get php to echo the data. Ill post the codes if youre interested in this solution. If you want the reply to be stored as an array, use ">" or "<" to separate the data on the server usin php eg while(){ somethin; echo "$data>";}. The reason we're doin this is because we want to help javascript split each $data, so that when ajax gets the reply it can store it in a variable eg var data. And use split eg data=data.split(">"); to split the data and store it in an array. And then you can validate the data. Lemme know what you think, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.