YT
|
Posted: 08/04/2002, 10:59 AM |
|
I'm not too good with javascript so I hope someone can help please.
I want to pass a parameter from PHP in CodeCharge to a javascript function.
Basically, the PHP parameter positons an icon on the screen via javascript.
I have the javascript running but can anyone advise me how I pass the PHP
variable to the javascript?
Thanks
|
|
|
Chris Seymour
|
Posted: 08/05/2002, 5:45 AM |
|
You can try something like this :
<script language="JavaScript">
function writeIt(){
return <? echo $PHPVariable ?>
}
</script>
I think you can use <?= $PHPVariable ?> as well.
Let me know if you need further explaination or assistance.
Cheers.
Chris
|
|
|
PJ
|
Posted: 08/05/2002, 12:00 PM |
|
Hi Chris
Many thanks for the assistance. All works however I am trying to loop
through a series of records from 1 to siteid(max) to place a series of icons
on a screen at a place stipulated by the x & y co-ordinates and it is the
loop through that is posing the problem for me.
Here is the entire page and all is well for one "dot" but multiple "dots"
according to the remainder of the records is the sticky issue.
Can you assist?
Peter
<SCRIPT Language="JavaScript" src="diagram.js"></script>
</head>
<body leftmargin="100" topmargin="100">
<?php
$db_link = mysql_connect("localhost", "", "");
mysql_select_db("dbname");
#Execute a selection query
$query = "SELECT site_name, xref, yref, siteid
FROM site where xref >0 and yref >0
ORDER BY siteid";
$result = mysql_query($query, $db_link);
if ($result) {
// echo "The query executed successfully.<br>";
for ($row = 0; $row < mysql_num_rows($result); $row++) {
$xref = mysql_result($result, $row, 'xRef');
$yref = mysql_result($result, $row, 'yRef');
$siteid = mysql_result($result, $row, 'siteid');
//echo "XRef: $xref";
//echo "YRef: $yref";
//echo "siteID: $siteid";
}
}
else
{
echo "The query failed with the following error:<br>\n";
echo mysql_error($db_link);
}
mysql_close($db_link) ;?>
<table width="500" border="0" height="800">
<tr>
<td><img src="derbs.jpg" width="500" height="800">
<script language="JavaScript">
document.open();
var D=new Diagram();
D.SetFrame(159, 185, 780, 795);
D.SetBorder(0,20, 0, 40);
D.SetText("","", "Derbyshire Dragonflies");
D.Draw("", "", false);
//Change D.ScreenY value for y position
//Change D.ScreenX for x postion
var m=<? echo "$siteid" ?>, a=<? echo "$xref"?> , b=<? echo "$yref"?>,
Size=10, Type=1;
{
new Dot(D.ScreenX(a),D.ScreenY(b), Size, Type, "#FF6688");
}
document.close();
</script> </td>
</tr>
</table>
"Chris Seymour" <cseymour@seyware.com> wrote in message
news:926150653cseymourseywarecom@66.180.229.147...
> You can try something like this :
>
> <script language="JavaScript">
> function writeIt(){
> return <? echo $PHPVariable ?>
> }
> </script>
>
> I think you can use <?= $PHPVariable ?> as well.
>
> Let me know if you need further explaination or assistance.
>
> Cheers.
>
> Chris
>
|
|
|
Chris Seymour
|
Posted: 08/05/2002, 3:07 PM |
|
Hello PJ,
See if this works:
<html>
<head>
<SCRIPT Language="JavaScript" src="diagram.js"></script>
</head>
<body leftmargin="100" topmargin="100">
<?php
$db_link = mysql_connect("localhost", "", "");
mysql_select_db("dbname");
#Execute a selection query
$query = "SELECT site_name, xref, yref, siteid
FROM site where xref >0 and yref >0
ORDER BY siteid";
$result = mysql_query($query, $db_link);
if ($result) {
?>
<table width="500" border="0" height="800">
<tr>
<?php
for ($row = 0; $row < mysql_num_rows($result); $row++) { ?>
?>
<td><img src="derbs.jpg" width="500" height="800">
<script language="JavaScript">
document.open();
var D=new Diagram();
D.SetFrame(159, 185, 780, 795);
D.SetBorder(0,20, 0, 40);
D.SetText("","", "Derbyshire Dragonflies");
D.Draw("", "", false);
//Change D.ScreenY value for y position
//Change D.ScreenX for x postion
var m=<? echo $row["siteid"] ?>, a=<? echo $row
["xref"] ?> , b=<? echo $row["yref"] ?>,
Size=10, Type=1;
{
new Dot(D.ScreenX(a),D.ScreenY(b), Size, Type,
"#FF6688");
}
document.close();
</script>
</td>
<?php
}
</tr>
</table>
}
else
{
echo "The query failed with the following error:<br>\n";
echo mysql_error($db_link);
}
mysql_close($db_link) ;?>
</html>
Let me know how you make out.
Cheers.
Chris
|
|
|
PJ
|
Posted: 08/05/2002, 11:40 PM |
|
Hi Chris
No, that failed at
</script>
> </td> HERE
> <?php
> }
> </tr>
> </table>
I haven't had time to look closely at your solution other than to say that I
solved the failure by moving the scripting. This resulted in one record
displaying again. I need to work on the loop in the javascript.
PJ
"Chris Seymour" <cseymour@seyware.com> wrote in message
news:9261B7923cseymourseywarecom@66.180.229.147...
> Hello PJ,
> See if this works:
>
> <html>
> <head>
> <SCRIPT Language="JavaScript" src="diagram.js"></script>
> </head>
> <body leftmargin="100" topmargin="100">
> <?php
> $db_link = mysql_connect("localhost", "", "");
> mysql_select_db("dbname");
>
> #Execute a selection query
> $query = "SELECT site_name, xref, yref, siteid
> FROM site where xref >0 and yref >0
> ORDER BY siteid";
> $result = mysql_query($query, $db_link);
>
> if ($result) {
> ?>
> <table width="500" border="0" height="800">
> <tr>
> <?php
> for ($row = 0; $row < mysql_num_rows($result); $row++) { ?>
> ?>
> <td><img src="derbs.jpg" width="500" height="800">
> <script language="JavaScript">
> document.open();
> var D=new Diagram();
> D.SetFrame(159, 185, 780, 795);
> D.SetBorder(0,20, 0, 40);
> D.SetText("","", "Derbyshire Dragonflies");
> D.Draw("", "", false);
> //Change D.ScreenY value for y position
> //Change D.ScreenX for x postion
> var m=<? echo $row["siteid"] ?>, a=<? echo $row
> ["xref"] ?> , b=<? echo $row["yref"] ?>,
> Size=10, Type=1;
> {
> new Dot(D.ScreenX(a),D.ScreenY(b), Size, Type,
> "#FF6688");
> }
> document.close();
>
> </script>
> </td>
> <?php
> }
> </tr>
> </table>
>
> }
> else
> {
> echo "The query failed with the following error:<br>\n";
> echo mysql_error($db_link);
> }
>
> mysql_close($db_link) ;?>
>
>
> </html>
>
>
> Let me know how you make out.
>
> Cheers.
>
> Chris
|
|
|
Chris Seymour
|
Posted: 08/06/2002, 7:07 AM |
|
Hi PJ,
I will create an example and send it to you. I think what we can do is
create a delimited string from the results in PHP pass the string to
Javascript and then have Javascript parse the string to an array then walk
the array making the calls as required. I will send some code in a bit.
Hope this makes sense.
Thanks.
Chris
|
|
|
|