Jump to content

paul2463

Members
  • Posts

    955
  • Joined

  • Last visited

    Never

Everything posted by paul2463

  1. Hello I am struggling with something to do with dates and placing them in an array, for information in the script the sy,sm,sd,ey,em,es are all configured and sDate and eDate are correctly configured dates. All I have is a start date and an end date I need to fill all the rest of the dates in as well ( ie sDate = 04 July 2006 and eDate = 07 July 2006, i need to also add the 5th and 6th) [code] var sDate = new Date(sy,sm,sd); var eDate = new Date(ey,em,ed); var dates = new Array(); var count = 0; while (sDate <= eDate)  {     dates[count] = sDate;     sDate.setDate(sDate.getDate()+1);     count ++; }[/code] what happens is that I get an array of dates for correct number of days that is should be, but all dates are the same and they are all eDate+1, so for the above example before the code I get an array of length 4 but all slots have 8 July 2006 in it. I am all confused
  2. [!--quoteo(post=387723:date=Jun 25 2006, 05:39 AM:name=jajtiii)--][div class=\'quotetop\']QUOTE(jajtiii @ Jun 25 2006, 05:39 AM) [snapback]387723[/snapback][/div][div class=\'quotemain\'][!--quotec--] I build by arrays like so : [code] $res = [array of row results from db]; $ct = [num_rows]; for($x=0; $x<$ct; $x++) { if ($res[$x]['flower_color'] = 'red') { $this->flower_name[] = $res[$x]['flower_name']; } } [/code] [/quote] a better way to build the array I feel is use the while statement instead of a FOR loop. [code] $query = "pull all data from the database that you require"; $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error()); $flower_name = array(); //force it to be an array if (mysql_num_rows($result) >0) {   while($row = mysql_fetch_assoc($result)) {     if ($row['flower_color'] == 'Red') {        $flower_name[] = $row['flower_name']; //puts the flower name into the $flower_name array        }    } } [/code] hope that helps
  3. [!--quoteo(post=387714:date=Jun 25 2006, 04:23 AM:name=hackerkts)--][div class=\'quotetop\']QUOTE(hackerkts @ Jun 25 2006, 04:23 AM) [snapback]387714[/snapback][/div][div class=\'quotemain\'][!--quotec--] What is RTFM ? [/quote] it stands for READ THE MANUAL
  4. Hi something that I found out as well that may be of use in this problem is that whenever I have used a variable in a PHP/SQL statement that variable has to be wrapped in single quotes [code] $query = "SELECT * FROM news ORDER BY id DESC LIMIT '$frontpagelimit'"; [/code]
  5. [!--quoteo(post=387492:date=Jun 24 2006, 11:22 AM:name=cableuser)--][div class=\'quotetop\']QUOTE(cableuser @ Jun 24 2006, 11:22 AM) [snapback]387492[/snapback][/div][div class=\'quotemain\'][!--quotec--] $dbhost = '50webs.net' //this is the line you typed $dbhost = '50webs.net'' //this is the documentation line in your post [/quote] the fault could be one of two things in my mind 1. either the error is the fact that you have a single quote at the start of 50webs.net and a double quote at the end. 2. you are missing the ; at the end of the statement have a look at the first one and see if there is a mix of quote marks otherwise try option 2
  6. [!--quoteo(post=387415:date=Jun 24 2006, 06:40 AM:name=Etrok)--][div class=\'quotetop\']QUOTE(Etrok @ Jun 24 2006, 06:40 AM) [snapback]387415[/snapback][/div][div class=\'quotemain\'][!--quotec--] hi . i want to bring some contents from another website . which is dynamic . to my web page . for example the links for the newest topics of one site . how can i do that . if u give me a keyword to search for it is not bad . and if u reply is more better .t nq . [/quote] Have a look at this site:- [a href=\"http://us2.php.net/include/\" target=\"_blank\"]http://us2.php.net/include/[/a] it may give what you want, also towards the bottom of the page are some sample ways of using it etc. hope that helps
  7. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] [code] $basedate = strtotime("21 june 2006"); $finaldate = date("Y-m-d ", strtotime("-1 day", $basedate)); [/code] [/quote] if you had done your method but with an extra set of parenthases ( spelt wrong but hey ho) it may have worked you need the final variable in the date function to be completed before the date function finishes its call so if you would have done [code] $basedate = strtotime("21 june 2006"); $finaldate = date("Y-m-d ", (strtotime("-1 day", $basedate))); [/code] your method would work and in fact I have just tested it and it does work that way
  8. I had the same problem as this a while ago and I had to use strtotime to make it work, this is how I did it [code] $basedate = strtotime("21 june 2006"); $plusdate = strtotime("-1 day", $basedate); $finaldate = date("Y-m-d ", $plusdate); echo ($finaldate); [/code] produces [code] 2006-06-20 [/code] if you look at:- [a href=\"http://uk.php.net/manual/en/function.date.php\" target=\"_blank\"]http://uk.php.net/manual/en/function.date.php[/a] - it will tell you all bout the different ways it can represent dates "Y-m-d " produces a date as in your origonal post 2006-06-21 [a href=\"http://uk.php.net/strtotime\" target=\"_blank\"]http://uk.php.net/strtotime[/a] lets you know what this does and how it does it hope this helps
  9. try this one for size then, I have tried to run the script and to clear the faults I changed your script to the following [code] if (!$db) { $db = mysql_pconnect("xxxxxxx", "xxxxxxxx", "xxxxxx") or die("Could not connect"); mysql_select_db("xxxxxxxx") or die("Could not connect"); } [/code] notice the semi-colon's at the end of the two lines of code in the IF statement, the errors went away but I dont know if the script fully works, you will though as you will have all the databsae names etc for it to connect to hope it helps anyway
  10. [!--quoteo(post=387125:date=Jun 23 2006, 06:49 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 23 2006, 06:49 AM) [snapback]387125[/snapback][/div][div class=\'quotemain\'][!--quotec--] Essentially, that's the same solution I posted (except I only determined the $id value once - before the conditionals instead of inside each one). The reason why the queries were failing was the query syntax was wrong. You had the right idea adding useful error messaging to your initial query. If that practice had been followed for the other queries, you would have spotted the problem much more easily. I'm still not sure why you have three different conditional tests but use exactly the same query in each case. I hope that was a [b]non-alcoholic brew[/b] that got the programming juices flowing :) [/quote] thanks again Andy, I have gone with your method and only determined the $id value the one time as well, as I said the queries read the same in here because I wrote the first one and then copied and pasted it for the other two forgetting to change values. It was not copied from my program directly it was hand typed into here as I am at work and we are not allowed to put anything that doesnt belong to the company into the company confusers. but thanks for the help and guidance over this problem. no alcohol in this building - mores the pity...
  11. thanks for looking but after I have walked away had a brew and walked back again I have solved it by adding some more STUFF ( what a lovely word, covers amultitude of sins) for each of the IF statements I did the following [code]if($row['insDate']==$tda)       {          $id = $row['idVeh'];          $query2 = "UPDATE Veh SET tdaSent = 'true' WHERE idVeh = '$id'";          mysql_query($query2);          count++;       }[/code] just added the extra variable so not too many in the query and it works ...... thanks for the reply Andy the queries were all identicle in the post because I just copied and pasted each of the IF statements into here many thanks for the reply though, looks remarkably like the way I did it too just took some thinking about thats all ( and a break) I have also noticed that by trying to set it to TRUE using the word 'true' does not work I have to set it to '1' even though reading it back from the database it works using the words 'true' or 'false' I realise the true and false are indeed either 1 or 0 but I thought I might be able to set it to a true value using the word 'true'
  12. Hello I am a noobie too but I think I may have found your fault, your line16 code printed below has a fault [code]mysql_select_db("xxxxxxxxxx_xxx") or die("Could not select database")[/code] I think what it should read is the following [code]mysql_select_db('xxxxxxxxxx_xxx') or die("Could not select database")[/code] note the single quote marks around the databse name that should clear the fact that it found T_STRING marks where it wasnt expecting them have a go anyway, its cant be made any worse by that change but I think that is the problem (apart from any spelling mistakes made by me in this post for which there is an amnesty)
  13. Hello, I ma having a bit of trouble getting PHP to UPDATE fields in a table here is my code: all variables such as $tda, $twe, $mon, $fardate have been initialised and the initial query works: [code] $query = "SELECT idVeh, insDate, tdaSent, tweSent, monSent FROM Veh WHERE insDate < '$fardate'"; $res = mysql_query($query) or die ('Error in Query: $query. ' . mysql_error()); $count = 0; $count1 = 0; if (mysql_num_rows($res)) {    while($row = mysql_fetch_assoc($res))    {       if($row['insDate']==$tda)       {          $query2 = "UPDATE Veh SET tdaSent = 'true' WHERE $row.idVeh = idVeh";          mysql_query($query2);          count++;       }       elseif($row['insDate']==$twe)       {          $query3 = "UPDATE Veh SET tdaSent = 'true' WHERE $row.idVeh = idVeh";          mysql_query($query3);          count++;       }       elseif($row['insDate']==$mon)       {          $query4 = "UPDATE Veh SET tdaSent = 'true' WHERE $row.idVeh = idVeh";          mysql_query($query4);          count++;       }       else       {          $count1++;       }    }    echo ("Number of Row with data changed = ");    echo ($count);    echo ("Number of Rows ignored = ");    echo ($count1); } [/code] it seems to function and the correct counts are returned for the test data entered but nothing is changed in the table to reflect the UPDATE command anywhere. where have I gone wrong in the UPDAT queries please?
  14. [!--quoteo(post=386249:date=Jun 20 2006, 09:47 PM:name=mainewoods)--][div class=\'quotetop\']QUOTE(mainewoods @ Jun 20 2006, 09:47 PM) [snapback]386249[/snapback][/div][div class=\'quotemain\'][!--quotec--] you don't need to reissue the query(that would be slower), just reset the pointer to the result: [code]mysql_data_seek($result, 0); //resets the pointer to the first row[/code] [/quote] thanks a lot this works brilliantly. all is happy in the "lack of Knowledge" camp at this time.
  15. [code]<?php function sortdates($res,$vals) {    $retarr = array(array(),array());    while($row = mysql_fetch_assoc($res))    {       for ($i=0,$i<count($vals);$i++)            if($row['status_2']==$vals[$i])                $retarr1[$i][]=$row['adate'];    } return $retarr; } list($pDates, $bDates) = each(sortdates($result,array('p','b'))); ?>[/code] Ken [/quote] I dont understand this code( which is not surprising I know), to answer Thorpe the 'p' and 'b' are the values that may appear in the status_2 field of the rows pulled from availability. to make it a bit easier to understand the adate value is either 'booked' or 'pending'. what I required from the $pDates and $bDates is two seperate arrays, one with the pending dates in and one with the booked dates. I cant seem to get my head around the above code and what it is trying to do, can someone please explain?
  16. Hello again the faithfull problem giver is back....... can someone explain to me why in my code only one call to the function actually fires, both of them work in their own right, I can comment one of the calls out and the other works perfectly but both together only the first call fires... [code] <?php //databse is connected to and the data is being pulled ok $query = 'SELECT adate,status_2 FROM availabilty'; $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error()); $pDates = array(); $bDates = array(); function sortdates($res,$val) {    $arr1 = array();    while($row = mysql_fetch_assoc($res))    {       if($row['status_2']==$val)       {          $arr1[]=$row['adate'];       }    } return $arr1; } $pDates = sortdates($result,p); $bDates = sortdates($result,b); print_r($pDates); echo "<br/><br/>; print_r($bDates); ?> [/code] its as though once $result has been passed to the first call to the function it is used up and cannot be used again.
  17. thanks for the help, I figured out my problem and it was tipping urror on my behalf, when you initialise a variable called "adate" and then try and refernece a variable called "aDate" it doesnt seem to work. how daft can one person be??? (rhetorical question - no actual answer required)
  18. I have figured it out I think..I am a noobie and decided to try and answer this one from a "lack of knowledge" perspective the function:- function now() { $row=gettimeofday(); echo $row['usec']; } does not actually return a value that can be assigned to $start and $stop, all it is asked to do is to write out the value of 'usec' function now() { $row=gettimeofday(); echo $row['usec']; return $row['usec']; } makes it work fine laugh at me all you like, I am new and am trying my best....... Paul
  19. Hi I am also new to PHP but I think I see a problem with your code from what I do know unless PHP is lax over this. you have put the following:- for ($count=0; $count<$num_results; $count++) echo row[$count]; you have braces missing from it and it should look like this:- for ($count=0; $count<$num_results; $count++) { echo row[$count]; } thats the summ of my knowledge so if it does not help then I am sorry Paul
  20. Hello, I am trying to get information from a sequel query and place it into 2 different arrays based on a test. I am pulling two values from the table valueA and valueB, if valueB is a certain number then valueA gets written to one new array and if the test fails then it is written to the other new array. here is the code:- <?php //create new variable arrays $arr1 = array(); $arr2 = array(); // connect to database , create and execute query $query = 'SELECT valueA, valueB FROM table'; $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error()); // check if records were returned if (mysql_num_rows($result) > 0) { //iterate over record set [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]while($row = mysql_fetch_row($result)) { if ($row['valueB' == '1') { $arr1[] = $row['valueA']; [!--coloro:#000000--][span style=\"color:#000000\"][!--/coloro--]//will this bit work??[!--colorc--][/span][!--/colorc--] } else { $arr2[] = $row['valueA']; } }[!--colorc--][/span][!--/colorc--] } else { // print error message echo 'No rows found!'; } // close connection to MySQL server mysql_close($connection); ?> It seems to run ok and places something into the relevant arrays but when I try and view whats in the arrays it tells me the block numbers of the arrays but the value is blank, as though it has placed a NULL value in there....I am now confused..thanks in advance valueA is date object valueB is a number so what I am expecting is two arrays, both with dates in them, one corresponding to a row value of ones and the other to a row value of anything else.
×
×
  • 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.