Forum Moderators: open

Message Too Old, No Replies

jscript and php

         

franches

12:39 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



hi,
i already posted this at php forum but still got no answer. maybe someone here in js forum could help me with this. there's something wrong with my code. the code is not working. here's some part of my code which is not working. could someone tell me and help me what's wrong with it.


<script language="jscript">
function getWrkHrsNew (tempDateLog2)
{
//some code here
//connection to database here
$recllWrkHrsNew_query=mysql_query(($SQLString),$datenewWrkHrsRec);
$recllWrkHrsNew2=mysql_num_rows($recllWrkHrsNew_query);

if (<?$recllWrkHrsNew2?>!=0)
{
<? while($recllWrkHrsNew=mysql_fetch_array($recllWrkHrsNew_query))
{?>
if ("<? echo $recllWrkHrsNew["Transaction_Date"];?>" == tempDateLog2)
{
alert ("found something");
TotalRemainingTemp = TotalRemainingTemp + 7.5
foundValue = "found"
}
else
{
alert ("Can't find same date!");
}
<? }?>
}
</script>

HERE is somecode in vbscript

<script language="vbscript">
Sub OkOutput()
tempDateLog = NewDataForm.LogYear.value &"-"& NewDataForm.LogMonth.value &"-"& NewDataForm.LogDay.value
NewDataForm.DateLog.value = tempDateLog
tempDateLog2 = tempDateLog
getWrkHrsNew(tempDateLog2)
End Sub
</script>

I am trying my best to work around with it but I'm stuck. hoping for help out there. thank you in advance

Bernard Marx

2:52 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's no PHP in here. It appears to be a mixture of JScript and VBScript blocks.
..with some undefined variables.

An ASP forum may be what you need.

Lance

3:34 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



You can't mix PHP and j/s. PHP runs on the server but j/s runs on the client.

All PHP processing must be done before j/s ever sees it.

PHP code embedded in j/s is just meaningless strings.

This will work
<script>
function getPHPvar() {
var MyVarFromPHP = "<? echo SomePHPvar?>"
}
</script>
but not because PHP and j/s are interacting. It will work because PHP has written part of your j/s before the page was rendered.

franches

6:42 am on Nov 23, 2004 (gmt 0)

10+ Year Member



actually, this function was only converted from asp to php. I am trying to make this work but i unfortunately i can't. i am not an expert in programming and i'm still on the process of learning php. i think there's a problem in my code starting the if statement since it does not display any of my alert.

<script language="javascript">
function getWrkHrsNew (tempDateLog2)
{
//some code here
//connection to database here
$recllWrkHrsNew_query=mysql_query(($SQLString),$da
tenewWrkHrsRec);
$recllWrkHrsNew2=mysql_num_rows($recllWrkHrsNew_qu
ery);

if (<?$recllWrkHrsNew2?>!=0)
{
<? while($recllWrkHrsNew=mysql_fetch_array($recllWrkH
rsNew_query))
{?>
if ("<? echo $recllWrkHrsNew["Transaction_Date"];?>" == tempDateLog2)
{
alert ("found something");
TotalRemainingTemp = TotalRemainingTemp + 7.5
foundValue = "found"
}
else
{
alert ("Can't find same date!");
}
<? }?>
}
</script>
and here's the some part of the code which is working
<script language="vbscript">
Sub OkOutput()
tempDateLog = NewDataForm.LogYear.value &"-"& NewDataForm.LogMonth.value &"-"& NewDataForm.LogDay.value
NewDataForm.DateLog.value = tempDateLog
tempDateLog2 = tempDateLog
getWrkHrsNew(tempDateLog2)
End Sub
</script>
<body>
<form name=NewDataForm ...>
//select box here LogYear,LogMonth,LogDay
</form>
</body>

Bernard Marx

10:32 am on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A friendly request:

This is a (largely client-side) Javascript forum. We don't deal in PHP. Your problem may well be in the Javascript, but to solve it we'll need to see the code that reaches the browser.

Run your code on the server, then post the resulting client-side code (all server-side code having been resolved) on the forum so we can have a look at it.

franches

12:27 pm on Nov 23, 2004 (gmt 0)

10+ Year Member



i tried to edit some of the code and it displays the the alert "ga san" then "san ga" then the next alert is blank then the next alert is "1975" then the next alert is "NONE" then it will alert again "san ga" then blank then "1970" then "NONE". I think the only problem i've got is <? if ( $WrkHrsNew['Date'] == $DateLogtemp ) which i don't know why. and also the date being displayed "1975 and 1970" are wrong. in my database my date are "2004-11-22 and 2004-11-23". i really don't know why is this happening. hope someone is patient enough to help me. i've got nowhere to go.

<? if ($WrkHrsNew2!= 0 )
{?>
alert ("ga san");
<? while( $WrkHrsNew=mysql_fetch_array($WrkHrsNew_query))
{
?>
alert ("san ga");
alert (<? echo $DateLogtemp?>);
alert (<? echo $WrkHrsNew['Date']?>);
<? if ( $WrkHrsNew['Date'] == $DateLogtemp )
{?>
alert ("Found!");
<? }
else
{?>
alert ("NONE");
<? }
}
}?>

the other code which is working

Sub OkOutput()
tempDateLog = NewDataForm.LogYear.value &"-"& NewDataForm.LogMonth.value &"-"& NewDataForm.LogDay.value
NewDataForm.DateLog.value = tempDateLog
tempDateLog2 = tempDateLog
NewDataForm.DateLogtemp.value = tempDateLog2
getWrkHrsNew(tempDateLog2)
End Sub

franches

1:29 pm on Nov 24, 2004 (gmt 0)

10+ Year Member



hi,
i parly solved my problem. i don't know if i did it right.

<script language="js">
function getWrkHrsNew (tempDateLog2)
{
temp = tempDateLog2;

//some code here
//connection to database here
$WrkHrsNew_query=mysql_query($SQLString,$newWrkHrsRec);
$WrkHrsNew2=mysql_num_rows($WrkHrsNew_query);?>

<? if ($WrkHrsNew2!= 0 )
{?>
alert ("ga san");
<? while( $WrkHrsNew=mysql_fetch_array($WrkHrsNew_query))
{?>
alert ("<? echo $WrkHrsNew['Date']?>");
alert (temp);

if ("<? echo $WrkHrsNew['Date']?>" == temp)
{ alert ("Found!");
foundValue = "found";
}
else
{ alert ("NONE");
}
<? }
}?>
}
</script>

<script language="vbscript">
//some other vb code
Sub OkOutput()
tempDateLog = NewDataForm.LogYear.value &"-"& NewDataForm.LogMonth.value &"-"& NewDataForm.LogDay.value
NewDataForm.DateLog.value = tempDateLog
tempDateLog2 = tempDateLog
getWrkHrsNew(tempDateLog2)
End Sub
</script>

but i've got a problem in comparing dates. in my database i have dates 2004-11-02, and 2004-11-22. in my select box if i have chosen the date november 23 2004 it is displayed in my textbox as 2004-11-23 and this date will be compared if there is a date in my database equal to my chosen date then it displays "Found". however, if i have chosen novermber 2 2004 it is displayed in my textbox as 2004-11-2 so when it is compared in my database it is displayed as "NONE". any idea what will i do now? thank you in advance. i will be looking forward for your reply.

franches

2:39 pm on Nov 25, 2004 (gmt 0)

10+ Year Member



no need to answer my question. thank you guys. i've already solved my problem. i made all my vbscript code to javascript and have some data manipulations. thanks again. :)