Hi John, <?php /* Using PostgreSQL: it needs $numrows and $row=0 to work. Also set it to choose only one record in db to simplify testing. Date was set to 10 May 1998*/ // $db conect stuff
$query = "SELECT rexpiry FROM rap WHERE rid = '1024'"; $result = pg_exec($db, $query); if (!$result) {printf ("ERROR"); exit;} $numrows = pg_numrows($result); $row = 0; $Row = pg_fetch_array($result,$row); $rexpiry = $Row['rexpiry']; $Date = explode(" ", $rexpiry); $Year = $Date[3]; pg_close($db); print $Year; /* 'Year' returns something like "1" */ ?> Btw, according to the error message, there's no such function as 'RIGHT' in PostgreSQl. (Sorry about referring to the string as an array in a session variable -- I've extracted the code from some other stuff that I had been working on.) Sigh. I'd like to know why this doesn't work: how I can extract the last few characters from the array. Regards, Andre On Wednesday 12 June 2002 09:34 pm, you wrote: > I don't understand why you keep referring to the string as an array in a > session variable. Can you show me how you are issuing the query, > fetching the result, assigning it to the session, etc... > > It should be as easy as this: > > <? > $result = MySQL_query("SELECT RIGHT(date_column,4) AS Year FROM > tablename"); > while($row = MySQL_fetch_array($result)) > { > echo $row['Year']; > } > ?> > > You know you could write a simple little script to convert this into the > correct format for a date column. > > If you want to do sorting by year, you can try this: > > SELECT date_column FROM table ORDER BY RIGHT(date_column,4) ASC > > ---John Holmes... > > > -----Original Message----- > > From: Andre Dubuc [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, June 12, 2002 9:32 PM > > To: [EMAIL PROTECTED] > > Subject: Re: [PHP] Extracting from an Array > > > > Hi John, > > > > Yup. I know now that I've caused myself all sorts of grief when I set > > it > > > to > > varchar. If I recall correctly (and I set this up four months ago when > > I > > > began coding) I couldn't get it format without the crummy little > > dashes. > > > So I > > set it to a string. > > > > Much coding later, I realize that I could solve this problem by > > changing > > > it > > back to 'date' type, but as i'm writing, I remember that this > > particular > > > array has only one use - and in a string format it's easier to > > manipulate. > > > [Bad reason, I guess with hindsight -- perhaps it's a hangover from my > > Paradox PAL days where I needed to format the string for 'other > > purposes'.] > > > > Your last point is precisely what I'm writing about: it IS all messed > > up! > > > So, > > the upshot is - live with it, and don't use it; or change it. Hmmm. I > > had > > > planned to sort a column by 'Year', but it might be a case of > > 'overkill' - > > > - > > the form is already loaded with enough options. > > > > Now that being said, this is more a problem of why can't I get ALL of > > the > > > last part of the array? Suppose I wanted to extarct something that was > > not > > > a > > date like: $_SESSION['odd'] which was varchar in the format of > > "Session is > > > closed". Now if I wanted to extract the last part: 'closed' what I've > > tried > > wouldn't work. It would give me: "c" -- how would I get the rest of > > the > > > characters? > > > > Thanks for the advice, > > Regards, > > Andre > > > > On Wednesday 12 June 2002 08:25 pm, you wrote: > > > What are the possible reasons that you "need it to be a varchar" ?? > > Do > > > > you realize how much extra work you are creating for yourself? Do > > you > > > > realize that you can have your users enter data in one format, and > > > convert it to another format for MySQL? Do you realize you can use > > > DATE_FORMAT() in your query to re-format the date back to dd-mm-YYYY > > if > > > > you want to? Do you realize that if you ever wanted to sort by this > > > column, you'd be all messed up? It'll sort as a string, where "10" > > is > > > > less than "2". Do you realize what I'm trying to say?? > > > > > > ---John Holmes... > > > > > > > -----Original Message----- > > > > From: Andre Dubuc [mailto:[EMAIL PROTECTED]] > > > > Sent: Wednesday, June 12, 2002 8:15 PM > > > > To: Lazor, Ed > > > > Cc: [EMAIL PROTECTED] > > > > Subject: Re: [PHP] Extracting from an Array > > > > > > > > Thanks Ed, > > > > > > > > Slight change -- I forgot that the delimiter was a 'space'. > > Anyway, I > > > > > still > > > > get the first letter of the last part of the array. I guess what I > > > > > > need is > > > > > > > something that specifies a range as in something like this: > > > > > > > > $Year = $Date[3-whatever?]; > > > > > > > > Seems rather odd that with the string as varchar it does this. > > I've no > > > > > problem extracting various parts of a date from type 'date' but > > this > > > > wierd > > > > > > > date-thingy. . . how I wish I didn't need it as varchar. > > > > > > > > Anyway, thanks -- I plug away at it. > > > > > > > > Regards, > > > > Andre > > > > > > > > On Wednesday 12 June 2002 07:09 pm, you wrote: > > > > > $sql = "select fieldname from tablename"; > > > > > $Results = mysql_query($sql, $DBLink); > > > > > $Row = mysql_fetch_array($Results); > > > > > $fieldname = $Row["fieldname"]; > > > > > $Date = explode("-", $fieldname); > > > > > $Year = $Date[2]; > > > > > > > > > > > -----Original Message----- > > > > > > From: Andre Dubuc [mailto:[EMAIL PROTECTED]] > > > > > > Sent: Wednesday, June 12, 2002 4:11 PM > > > > > > To: [EMAIL PROTECTED] > > > > > > Subject: [PHP] Extracting from an Array > > > > > > > > > > > > > > > > > > I have a db field, type varchar, that is actually a 'date' > > > > > > string formatted > > > > > > as dd-mm-YYYY. I used type 'varchar' (rather than type > > > > > > 'date') since I had to > > > > > > accomplish other things with it. > > > > > > > > > > > > Now, however, I do need to extract the Year (the last four > > > > > > digits in the > > > > > > array). I've tried to access the array $_SESSION['expiry'] > > > > > > but I don't know > > > > > > how to explode this array to extract all characters in last > > > > > > item after the > > > > > > last separator : i.e. '-YYYY'. I've used "-" as the > > > > > > separator, but I just > > > > > > get the first number of the last part of the array, i.e.: > > '-Y'. > > > > > > > Is there a way of extracting all characters in that array? > > > > > > > > > > > > I've tried a bunch of combinations, but I obviously don't > > > > > > understand the > > > > > > basic mechanics of array manipulation or 'slicing'. If > > > > > > someone could point me > > > > > > to a good resource, or explain what I'm doing wrong, I would > > > > > > greatly any > > > > > > assistance. > > > > > > > > > > > > Tia, > > > > > > Andre > > ************************************************************************ > > > > ** > > > > > > > * > > > > > > > > >* This message is intended for the sole use of the individual and > > > > > > entity > > > > > > > to > > > > > > > > > whom it is addressed, and may contain information that is > > > > > > privileged, > > > > > > > > confidential and exempt from disclosure under applicable law. > > If > > > > you > > > > > > > are > > > > > > > > > not the intended addressee, nor authorized to receive for the > > > > > > intended > > > > > > > > addressee, you are hereby notified that you may not use, copy, > > > > > > disclose > > > > > > > or > > > > > > > > > distribute to anyone the message or any information contained in > > the > > > > > > message. If you have received this message in error, please > > > > > > immediately > > > > > > > > advise the sender by reply email and delete the message. Thank > > you > > > > very > > > > > > > > much. > > > > > > > > -- > > > > Please pray the Holy Rosary to end the holocaust of abortion. > > > > Remember in your prayers the Holy Souls in Purgatory. > > > > > > > > May God bless you abundantly in His love! > > > > For a free Cenacle Scriptural Rosary Booklet: > > > > > > http://www.webhart.net/csrb/ > > > > > > > -- > > > > PHP General Mailing List (http://www.php.net/) > > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > > Please pray the Holy Rosary to end the holocaust of abortion. > > Remember in your prayers the Holy Souls in Purgatory. > > > > May God bless you abundantly in His love! > > For a free Cenacle Scriptural Rosary Booklet: > > http://www.webhart.net/csrb/ -- Please pray the Holy Rosary to end the holocaust of abortion. Remember in your prayers the Holy Souls in Purgatory. May God bless you abundantly in His love! For a free Cenacle Scriptural Rosary Booklet: http://www.webhart.net/csrb/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php