Jump to content

Johnain

Members
  • Posts

    64
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Johnain's Achievements

Member

Member (2/5)

0

Reputation

  1. Yikes cracked it - after 6 hours. Yippee. The solution (simple as always) was ... function calcdate($indate, $noofdays) { // calculates a number of days from the supplied date, plus (no sign needed) or minus (give - sign in $noofdays // Assumes that indate is yyyy-mm-dd and the outdate will be in the same format. $date = strtotime(date("Y-m-d", strtotime($indate)) . " +".$noofdays ." day"); return date("Y-m-d", $date) ; }
  2. Hi all I am constantly baffled by the unbelievable difficulty of carrying out simple date manipulations in PHP. I have just spent around six hours trying to add a day to a date and I still do not have the answer. I have a date stored in a date filed in my MySQL database in the format YYYY-DD-MM. All I want to do is retrieve it, add a day to it and display it in an HTML form as DD-MM-YYYY. I already have a function that will reverse it to DD-MM-YYYY for display and another that will reverse it back to my YYYY-MM-DD format when I wish to write it back to the database, so it's just adding a day (or two days, or any other number of days) that I need to do. But the apparently simple task of adding one (or more) days to it has proved beyond me. I have scoured the web and seen almost every solution known to mankind. Most of them incredibly complex. It must be me being an idiot. Can anybody help, please. My latest attemp is this ... function calcdate($indate, $noofdays) { // calculates a number of days from the supplied date, plus (no sign needed) or minus (give - sign in $noofdays // Assumes that indate is yyyy-mm-dd and the outdate will be in the same format. $date = strtotime(date("Y-m-d", strtotime($indate)) . " +".$noofdays ." day"); return $date ; } But it returns a number !
  3. Thanks for that. In the end I came to much the same conclusion and what I now do is simply load up one array with the values that I want and another array with the IDs that I want so that when (much later in the script) I want to use them in an SQL update I simply lookup the two arrays. In fact it's an excellent example of using experience of what's easy in one language and trying to apply it in another without thinking it through properly. So I need to be more careful next time. But a big word of thanks to those who helped me.
  4. Ok, I replaced my original eval with eval($varval) ; But I got Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home/q07peri/public_html/admin/mdprodcodeedit.php(102) : eval()'d code on line 1 I made no changes to $varval itself
  5. Ok, echo comes up with $varval = "$1_saleprice = $_POST['1_saleprice']"; If I was writing the line of code I would write ... $1_saleprice = $_POST['1_saleprice'] ; So it looks about right to me. It looks as though I have not grasped eval() properly.
  6. Hi All I have never used eval() before to generate and execute php code. The code that I am trying to generate is a varying number of rows that should say (and execute) ... $incomingvariable = $_POST['incomingvariable'] ; ... where the incoming variable will be 1_saleprice to (for example ) 10_saleprice when $pricecount (see below) has a value of 10 The variable $pricecount has a value of 8 with the data I am using and it IS passed correctly (I use EngInSite debugger so I know that). I am using a for loop. The variable that holds the number of incoming records is called $pricecount. It reads like this ... 93 for ($z = 1; $z <= $pricecount; $z += 1) 94 { 95 $y = trim($z) ; 96 97 $varval = "$" . $y . "_saleprice = $" . "_POST['" . $y . "_saleprice'] ;" ; 98 99 eval("\$varval = \"$varval\";"); 100 } You will see that I have put the terminating executing code semi-colon into the variable $varval in this example and I still get an error with or without it. (I split the $ and the _POST because otherwise it reads it directly as $_POST[') The error WITH the semi colon is ... Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/q07peri/public_html/admin/mdprodcodeedit.php(99) : eval()'d code on line 1 The error WITHOUT the closing semi-colon is exactly the same.
  7. I have got a function that the EnginSite Editor/Debugger is failing on a given line. I cannot for the life of me work out why, and the debugger has decided that is not going to accept breakpoints today (no idea why, it did yesterday). It has also decided that it's too tired to evaluate statements or to give values on watchpoints, poor labm ! There is no help to be got at EngInSite, they are not answering e-mails at the support desk. This is the function .... function getgentext($textref, $langue, $text) { // $textref is the reference of the text - NOT the row id in the table // $sessionlangue is the language // $text is to identify which text is returned // 1 = long text // 2 = medium text // 3 = short text // 4 = Column header text $sql = "SELECT * FROM peri_othertexts where textref = $textref and langue = $langue ; $result = mysql_query($sql) or die('SQL Query failed ... ' . mysql_error()); $num_rows = mysql_num_rows($result); $rowcontent = mysql_fetch_row($result) switch($num_rows) { case 0 : switch($langue) { case 'FR' : $retval = 'Texte non disponible'; break; case 'EN' : $retval = 'Text not available'; break; default : $retval = 'Text not available'; } default: switch($text) { case 1: $retval = $rowcontent['textlong'] ; break; case 2: $retval = $rowcontent['textmed'] ; break; case 3: $retval = $rowcontent['textshort'] ; break; case 4: $retval = $rowcontent['textcolhead'] ; break; default: $retval = $rowcontent['textlong'] ; break; } } return $retval ; } The highlighted line is the one that gets this message Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\htdocs\perigordirect\includes\db_lib.php on line 45 PHP Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\htdocs\perigordirect\includes\db_lib.php on line 45 But clearly there is a record found, or else it would have taken case 1 of the $num_rows switch. I have checked and there is data there. Cheers John
  8. Thanks Haku, I really appreciate that. By the way, in case you are wondering whether I feel a complete plonker, the answer is yes. I do. Talk about the obvious. But thanks again
  9. Hi I am using XHTML (T). I am successfully retrieveing data from a MySQL database field of type Text. I want to show it in a form so a user can edit it and then I can save it back to my table. However I can only see two tab types that might be relevant. 1. <input> that lets me assign an initial value but will not allow me to specify columns or rows. 2. <textbox> That will give me rows, columns and scrolling - but will not let me assign an initial value. Am I missing something? Is there a simple solution? Regards John
  10. That is really good. Thanks. As you say, it may not do it all. But it is a good looking solution. Thanks
  11. Hi all I am building my first PHP display and update form, and so far it runs like a dream (tp my amazement). However I am taking my time with this because I want it to be a "standard form" ... almost a class, for future forms of the same type. Basically, it does this. 1 Selects all data from a MySQL table, sticks it in a table for on-screen display and then shows it. Scrollbars, locked columns on the left , alternate colours on rows and other magic. Now I want to offer the user the opportunity to redisplay the form with filters and sort orders initiated by on-screen buttons. I tried onclick, but it will not go to my PHP function. Do I have to set up a "mini form" for each button and redisplay the whole page with the newly sorted and filtered data, or is there something I am missing? John
  12. You are right Adam. I thoght I had grasped it, but clearly I have not. I will take your advice. Regards and thanks John
  13. Oh, then I have really misunderstood. How then can I make a variable used in one form useable in another within the same session? Do I have to write it to a table? Regrds John
  14. $_SESSION['stepno'] = $stepno; I understood that this would add it to the session variables and that normal chages to the values of ordinary $ variables would be used to update it session wide. Is that not correct? Regrds John
×
×
  • 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.