Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2004, 03:27 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

what?

my php variables produce the expected outcomes of year, month etc....
but the javascript produces NaN days left not the php variable of 1?

cheers
ASH:D

 
Old May 24th, 2004, 03:33 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Oh, maybe you shouldn't use quotes on numeric values.

HTH,

Snib

<><
 
Old May 24th, 2004, 03:45 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

it works if i create variables such as
$year = 2004;
$month = 05;
$day = 25;

but if i use these php variables
$year = date("Y");
$month = date("M");
$day = date("d")+1;
the values in the countdown timer are:-
NaN days NaN mins and NaN seconds?

even if i disregard the '+1' or put echo date('blah..') it still doesnt work?!

nehelp again?
thanks so far
ASH

 
Old May 24th, 2004, 03:53 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Once more, what does the source of that part of the page look like?

view-source:http://yoursite.com/yourdirectory/yourpage.asp

Snib

<><
 
Old May 24th, 2004, 03:55 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

      <html>
<head>


<script language='javascript' src='http://127.0.0.1:3001/js.cgi?pa&r=25824'></script>


<title>~{ONLINE AUCTION UK - ITEMS}~</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body background="back3.gif" link="#FFFFFF" vlink="#FF0000">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="23%">&nbsp;</td>
    <td width="57%"><table width="100%" height="600" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">

        <tr>
          <td width="800" height="167"><img src="logo.gif" width="800" height="165"></td>
        </tr>
        <tr>
          <td height="380" valign="top" background="back8.gif"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td height="33"><div align="center">~{BID
                    ON AN ITEM?}~</div></td>
              </tr>
              <tr>
                <td height="315"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td bordercolor="#000000"> <div align="center">test
                          </div></td>
                    </tr>
                    <tr>
                      <td bordercolor="#000000"> <table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
                          <tr>
                            <td width="36%"><div align="center"><img src="upload_files/ticket.jpg" ></div></td>
                            <td width="38%"><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
                                <tr>
                                  <td width="37%"><div align="center"><strong>START
                                      BID</strong></div></td>
                                  <td width="63%"><div align="center"><strong>&pound;</strong>15</div></td>
                                </tr>
                                <tr>
                                  <td><div align="center"><strong>TIME
                                      LEFT</strong></div></td>
                                  <td><div align="center">
<SCRIPT language=JavaScript1.2>
function setcountdown(theyear,themonth,theday,thehour,themi n,thesec){
yr=theyear;mo=themonth;da=theday;hr=thehour;min=th emin;sec=thesec
}
var occasion=""
var message_on_occasion="Auction Ended! Did you bid in time?"
var countdownwidth='300px'
var countdownheight='35px'
var countdownbgcolor='lightyellow'
var opentags=''
var closetags='
'
// don't change anything from here !!
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec")
var crosscount=''
function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all? document.getElementById("countdownie") : countdownie
countdown()
}
if (document.all||document.getElementById)
document.write('<center><span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span></center>')
function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr+" "+hr+":"+min+":"+sec
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000) )/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000 ))%(60*1000))/1000*1)
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da ){
if (document.layers){
document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+message_on_occasion+closeta gs)
document.countdownnsmain.document.countdownnssub.d ocument.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+ closetags
return
}
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+"Occasion already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.d ocument.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Auction already ended ! "+closetags
return
}
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.d ocument.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags
}
setTimeout("countdown()",1000)
}
//-->
</SCRIPT>
<ilayer id="countdownnsmain" width=&{countdownwidth};
height=&{countdownheight}; bgColor=&{countdownbgcolor};
visibility=hide><layer id="countdownnssub" width=&{countdownwidth};
height=&{countdownheight}; left=0 top=0></layer></ilayer>
</CENTER>

<!-- Insert this section as a revision, once you know the exact finish time
use the format setcountdown(yyyy,mm,dd,hh,min,sec) -->
<SCRIPT language=JavaScript>
<!--//
var year = '2004';
var month = '5';
var day = '25';

setcountdown(year,month,day,00,00,01)
window.onload = start_countdown
//-->
</SCRIPT>


</div></td>
                                </tr>
                                <tr>
                                  <td><div align="center"><strong>START
                                      DATE</strong></div></td>
                                  <td><div align="center">24-May-2004</div></td>
                                </tr>
                                <tr>
                                  <td><div align="center"><strong>SELLER
                                      ID</strong></div></td>
                                  <td><div align="center">ash</div></td>
                                </tr>
                                <tr>
                                  <td><div align="center"><strong>CURRENT
                                      BID<BR>
                                      </strong> AND HIGH
                                      BIDDER</div></td>
                                  <td><div align="center">
                                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                          <td><div align="center"><em>trevor</em></div></td>
                                          <td><div align="center"><STRONG>&pound;41</STRONG></div></td>
                                        </tr>
                                      </table>
                                    </div></td>
                                </tr>
                              </table></td>
                            <td width="26%">&nbsp;</td>
                          </tr>
                        </table></td>
                    </tr>
                    <tr>
                      <td bordercolor="#000000"><table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
                          <tr>
                            <td>DESCRIPTION</td>
                          </tr>
                          <tr>
                            <td>
                              <div align="center">
                                <table width="80%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                                  <tr>
                                    <td><div align="center"></div></td>
                                  </tr>
                                  <tr>
                                    <td><div align="center"> test</div>
                                     </td>
                                  </tr>
                                  <tr>
                                    <td>&nbsp;</td>
                                  </tr>
                                </table>

                              </div></td>
                          </tr>
                        </table></td>
                    </tr>
                    <tr>
                      <td bordercolor="#000000"><table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#0000FF">
                          <tr>
                            <td>POSTAGE AND PAYMENT</td>
                          </tr>
                          <tr>
                            <td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="28%"><div align="center">POSTAGE
                                      AND PACKING <br>
                                      (INCLUDING INSURANCE)</div></td>
                                  <td width="72%"><strong>&pound; 2
                                    </strong>(Add
                                    this to your bid)</td>
                                </tr>
                              </table>

                            </td>
                          </tr>
                        </table></td>
                    </tr>
                    <tr>
                      <td bordercolor="#000000"><table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#009900">
                          <tr>
                            <td>BID</td>
                          </tr>
                          <tr>
                            <td><STRONG>test</STRONG></td>
                          </tr>
                          <tr>
                            <td> <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="49%">START
                                    BID : <STRONG>&pound; 15</STRONG></td>
                                  <td width="51%">CURRENT
                                    BID : <STRONG>&pound; 41</STRONG></td>
                                </tr>
                              </table></td>
                          </tr>
                          <tr>
                            <td> <form name="form1" method="post" action="../auctiononline/bidCheck.php?51">
                                <p>PLACE A BID
                                  :
                                  <input name="bid" type="text" id="bid">
                                  (Enter <strong>&pound;
                                  43 </strong>or more)
                                  </p>
                                <p>
                                  <input type="submit" name="Submit" value="Place Bid &gt;&gt;&gt;">
                                  <input type="reset" name="Submit2" value="Reset Bid">
                                   </p>
                              </form></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table></td>
              </tr>
            </table>
            </td>
        </tr>
        <tr>
          <td height="50" valign="top" background="bottomBarBUY.gif">
<table width="800" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="184">&nbsp;</td>
                <td width="81"><div align="center"><a href="indexLOGGED.php"><img src="homebutton.gif" width="75" height="15" border="0"></a></div></td>
                <td width="67"><div align="center"></div></td>
                <td width="81"><div align="center"><a href="AddNewItem.php"><img src="homebutton.gif" width="75" height="15" border="0"></a></div></td>
                <td width="123"><div align="center"><a href="newuser.php"><img src="homebutton.gif" width="118" height="15" border="0"></a></div></td>
                <td width="80"><div align="center"><a href="login.php"><img src="homebutton.gif" width="75" height="15" border="0"></a></div></td>
                <td width="184">&nbsp;</td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <div align="center"></div></td>
    <td width="20%">&nbsp;</td>
  </tr>
</table>


<script language='javascript'>postamble();</script>
</body>
</html>


 
Old May 24th, 2004, 04:13 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

but if i use these php variables
$year = date("Y");
$month = date("M");
$day = date("d")+1;
the values in the countdown timer are:-
NaN days NaN mins and NaN seconds?

NaN means "not a number".. I ran the source code you provided in a browser and it worked fine for me (Mozilla & IE 6). In fact it worked without any JS errors.

var year = '2004';
var month = '5';
var day = '25';

I wouldn't output the numbers to a string but I don't think it has any effect.

Can you post a relevant snip of your PHP code so I can see that you have the right idea? No need to post the whole thing just the relevant portions.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old May 24th, 2004, 04:22 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

<?php

      $dbc = mysql_connect('DBSTUFF') or die ('Could not connect to MySQL :' .mysql_error());
      mysql_select_db('DBNAME') or die('Could not connect to database :' .mysql_error());

      session_start();
     $year = date("Y");
     $month = date("M");
     $day = date("24");
      $itemID = $HTTP_SERVER_VARS['QUERY_STRING'];
      $query = "SELECT * FROM kayA_items WHERE ItemID = '$itemID'";
      $result = mysql_query($query);
      ?>
      <?
        while($row = mysql_fetch_array($result,MYSQL_ASSOC))
         {
         $image= $row[image];
      ?>

I've set variables in php using the date function and ive even tested whether the values in these variables are correct.(they produce 2004, 05 and 24)
but still get this NaN??

I have tested the variables with just numbers and not date function i.e $year = 2004 and it works fine, but i need the date to be able to be set by a user?

that help?
cheers again
ASH

 
Old May 24th, 2004, 04:39 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Ok, the NaN doesn't have anything to do with the PHP side of things. If you're spitting out a number with PHP then its a Number, so its a JavaScript problem exclusively. You get NaN if you're trying to feed a data type that is (N)ot (a) (N)umber to a method that requires a number, such as a string.

var year = '2004';
var month = '5';
var day = '25';

setcountdown(year,month,day,00,00,01)

You're putting the numbers in strings here by using quotes, take out the quotes.

var year = 2004;
var month = 5;
var day = 25;

But like I said I ran the source file you provided and it works just fine for me in both Mozilla and IE, no NaN anywhere. Maybe your particular browser has a problem with converting strings to a numbers.

If that doesn't cure the problem, then the solution here is to use JavaScript debugging techniques, if you know PHP is printing out numbers, then follow the value of year, month and day on the JS side of things to determine where things are going awry. Output the values using alert() or document.write().

Out of curiosity, where are you getting: date('24') ?? ... 24 isn't a valid format option for the date function... it'll just pass through the 24 value but you don't need the date function there.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old May 24th, 2004, 05:07 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

ive got it working, dont know how but it works!
haha!

neways the only part i need to do now is test whether it has ended ie the timer has finished? so i can stop all bids on a particular item.

the idea im thinkin would be to set a field in my sql database called 'active' then if the timer is stopped set the value to 'no' which in turn will disable the bidding and produce a 'winning bidder' screen.

how would i check the timer is stoped?
cheers for all the help you seem to give me
CHEERS
ASH:D

 
Old September 15th, 2004, 08:45 PM
Authorized User
 
Join Date: Jun 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I have a similar problem but it is in php alone, no js involved. I am using the following code that extracts 2 timestamps from the database and displays them:
Auction Started: <?php echo $data['timestarted']; ?>
Auction Ends: <?php echo $data['timeend']; ?>
so it echos out:

Auction Started: 20040915155920
Auction Ends: 20040918155920

but I cannot find a suitable way to show there is:
eg. 2 days 3 hours 22 minutes and 14 seconds left, can you help as I also then need to display "auction expired" when:

date() > $data['timeend']

thanks
Sami





Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and Javascript davidhayter Beginning PHP 5 May 6th, 2005 05:33 AM
javascript with php kuehhc Beginning PHP 8 February 1st, 2005 10:59 PM
How to use javascript with php? raichand_ray PHP How-To 2 November 12th, 2004 06:41 AM
PHP with Javascript Droobles Pro PHP 1 February 17th, 2004 03:08 PM
JavaScript and php Bandy PHP How-To 2 February 10th, 2004 04:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.