Jump to content

Embid javascript to php


napsternapster

Recommended Posts

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>

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

ajax is the answer to your prolem homes.  :P. 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,  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.