Forum Moderators: coopster

Message Too Old, No Replies

js and php

         

franches

9:33 am on Nov 22, 2004 (gmt 0)

10+ Year Member



hi,
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 what's wrong with it.


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!");
}
<? }?>
}


thanks in advance...

coopster

4:15 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What's not working? Are you invoking php and closing php correctly? It seems you aren't closing it after you run the mysql_num_rows() function.

franches

6:27 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. the code does not read the program starting the if statement since it does not display any of the alert I made.

<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>
</form>
</body>

franches

12:32 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:16 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
$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.

jatar_k

7:39 pm on Nov 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I always convert all of my dates to unix timestamps for comparison and calculation. Once that is complete I convert them for db insert (if needed) and display.

franches

5:35 am on Nov 25, 2004 (gmt 0)

10+ Year Member



could you show some examples on how would I be able to do it? actually my problem is the date data to be compared to the dates in my database.

jatar_k

5:43 am on Nov 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



form date style : november 23 2004
db date style : 2004-11-23

is that right?

I need to be absolutely sure of the 2 formats if you want a good example.

franches

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

10+ Year Member



my db format is date: 2004-11-01 and in my form the format is string:2004-11-1. do you have any suggestions on how am i going to make in my form the format string:2004-11-1 to format as date:2004-11-1.