Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Text Field As Date (MySQL)


I have a generic table used for many different generic
functions. the fields are mainly varchar's but one of these varchars
contains dates (in the format dd/mm/yyyy) for one reason or another.

My question is, can I perform a query on this table, using date
functions on this varchar field? I.e. search for the latest date?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Quickly Adding Text To A Mysql Text Field That Is NOT Empty
Is there a way to insert text into a mysql text field that already has
text into it; without having first to extract the existing data and
append the new text to that string variable and then insert the new
string.

Basically i'm looking for a way to do it with a single query not 2 (one
being a select to gather existing data).

Formatting Date From MYSQL Date Field
i've got a date field in my table, but the default format is YYYY-MM-DD... is there any way i can pull the date out of the database and format it differently... like DD.MM.YYYY or like April 13, 2003?

Mysql Text Field
I have a DB with a column that is set as Text format. The data stored in the field will be stored in many lines. When I get the data from the DB I want it to display where the line breaks are I'm not sure how to write the script to do this. I have worked withe explode before but there is nothing come at the end of each line to do this with.

MySQL Date Field Help Needed
I have a Date type in my MySQL table - I'm trying to do a query on all
rows within the last 30 days based on that Date field - I'm having
trouble figuring out how to form the query?

$php_SQL = "SELECT * FROM basics WHERE creation_date =
DATE_ADD(creation_date, INTERVAL -30 DAY)";

Php How To Treat Mysql Field Like A Date?
I have a query that looks like this: (I insert the date created with the php
date function)

$status = "Active";

//(I cannot use the mysql timestamp function for other reason).
$curdate = date("m/j/Y H:i");
$owner = "not assigned";

@ $db_connect = mysql_connect("localhost", "$db_username", "$db_password");
if (!$db_connect)
{
echo "Unable to connect to the database;
exit;
}
mysql_select_db("$db");
$query = "insert into tickets (user, status, loannum, problem, description,
multiples, ticketnumber, ip, office, submissiontime, ticketowner) values
('$user1', '$status', '$loannum', '$problem', '$description', '$multiples',
'$ticketnumber', '$ip', '$office', '$curdate', '$owner')";
$result = mysql_query($query);

I need to pull out the last fifty records from the database, so I use this
query:

$order = $order;
if ($order ==""){
$order = "user";
}

mysql_select_db("$db");
$query = "select * from tickets ORDER by $order";
$result = mysql_query($query);
$num = mysql_num_rows($result);

if I order the tickets by submission time, it orders the items, but not
correctly. It looks like php treating the submissiontime like integer:
example:

12/1/2003 16:51

12/1/2003 16:58

12/10/2003 12:29

12/10/2003 12:36

12/11/2003 07:10

12/2/2003 09:16

Converting Dates To Mysql Date Field
Is there a way to convert a date in this format:

8-7-2002 to fit into a MySQL date field format 2002-08-07.

the 8-7-2002 is a field in which users pick a date from a pop-up calendar in javascript. When I enter that date into the database, i want to convert it to the MySQL date format.....is there a way to convert it?

Phpmyadmin/MySQL - Dynamic Date Field?
I am a relative newbie for php/MySQL, and most of what
I am doing is based on being self-taught using someone else's
well-written code, and my own googling the answers to my questions.

I'm doing a php/MySQL page that reads data out of a MySQL database.
Longer term, I'll do a data-entry screen allowing me to modify the
database or add new records. For now, I'm just using phpmyadmin to data
enter stuff.

Is there a way to set up a date field, Last_Update, that would
automatically update to today's date any time a record was added or
changed using phpmyadmin?

Not sure if I'm asking the question clearly. What I want would be that,
let's say that I add a new record today, April 23. The Last_Update
field for the record would automatically be April 23. If I go in and
modify and part of that record on April 29, Last_Update automatically
changes to April 29 for that record.

If that's not possible, then how in php/MySQL would I display on a web
page "Information last updated on mm/dd/yyyy" based on the contents of
the database?

Put Today's Date Into A MySQL "date" Formated Field
My MySQL table has a field that is set as type "date." I need to get
today's date, and insert it into that field. The default for that MySQL
field is 2006-00-00.

I know about the date() function. I have tried date("Y-m-d") and
date("U"), neither worked. The date field was just filed with all
zeros.

Can anybody point me in the right direction?

Displaying First 50 Characters Of A Mysql Text Field?
I have been searching for hours on the php website for a function that
will allow me to display just the first 50 chars of a mysql text field
in a results table, but i'm having no luck. I need it to create a
results page for a site i'm creating in php.


Display MySQL Data In Text Field
I have my site set up and am now working on the admin side. I have a page that lets me search my users then its linked to another page so I can edit the information.

I am attempting to get the code to display in my forms text boxes and text areas for updating. My problem is that I can't figure out how to get the data into my form for editing. I have a few different things but can't seem to figure this out.

Error When Inserting A ' Into Mysql Text Field
I'm using the below code to insert some text fields from a form into a database. I've noticed that if we type something using a ' (i.e we're all going out for the day) in the text field then we get a insert error back from mysql saying it can't insert into the text field. I kind of think I know what the problrem is but need someone in the know to clear it up for me ....

Can't Update Date Field - Mysql Client Version 5.0.33
I am trying to update record and date field, but it fails although my timestamp echos perfectly.  I don't know what to do:  my sql client version is 5.0.33 and the model table has got date filed which is model_date. Code:

Book Script ,should I Use Txt File Or Mysql Text Field ?
I am doing simply book script, where we will have hundred of books,user will be able to read chapter by chapter or search etc.. As u know that book contain will have html tages..etc.. and each book is around 200 kB....My php script read text file and display. It's a huge text file.

I am thinking to use database instead of text file. But text files are very huge. My question, should i use database instead of text file ? which one is faster and better.

I have noticed, when i copy 150 kB files and paste into phpmyadin, it gives me internel error..but it insert record. I used txt field for book contain.

Text To Date And Insert To Mysql...
Kindly break out the 4x2 and bring me to my senses.
I seem to have gotten myself totally confused with php.net, mysql.org pages
on dates etc, as well as groups.google.

Could someone explain, even using pseudo code, how to take a text input I
have set up as YYYY-MM-DD using php, and convert to a value mysql will
insert into a Date (not timestamp, not datetime) field.

Save Date To Table Field Date Type
I have a calendar picker on a form that fills a text box with  XX/XX/XXXX  date format. If I run a insert statement  the date field in the database shows 0000-00-00. If i change the field type to varchar  the correct format displays. 

What is the correct way to save a date to a mysql database?  Furthermore to query on the date  how about a select * from db_name where servicedate >= $startdate  and  servicedate >= $enddate  I supose this will not work
Any pointers?

Text Returned From DB Gets Cutoff When Placed In A Text Field
I have a string that contains an apostrophe or a quotation mark, stored in a DB. I can retrieve the data, and display it properly (for editing) in a textarea, but when I try to put the string in a text field, it get's cut off right before the questionable character.

For example:
$string_in_database = "John's car."

 -displays correctly here <textarea><?php print $string_in_database ?></textarea> and displays this - John's car.

 -gets cutoff here <input type='text' value=''<?php print $string_in_database ?>' /> and displays this -  John

I've tried adding slashes and stripping slashes and I just can't figure out what I need to do.

Date Field
Im making a date field in mysql, but im not sure which data type to make it, like a number should be INT(xx), but what about a date?

Date Field And Formats
I have been looign at and wonder...

what is the easiest way to check a date field and transfer it into:
dd.mm.yyyy ?

Eventually I would like to accept dd.mm then yyyy is present year (unless month < now, then yyyy++ ). The basic thing is to format the date as dd.mm.yyyy - how?

Sort By Field (date)
I would like to display my data but sorted by date. I have already had some postponed games, so now the results are not displaying in order of date. Code:

Sort By Field (date)
I would like to display my data but sorted by date. I have already had some postponed games, so now the results are not displaying in order of date. Code:

Select Both Field Name And Field Value- Mysql ?
What function to use to select both field name and field value from a mysql table ?

Validate Text Field
This is very simple in javascript but I can't seem to find the exact solution in php. I have searched the forum but couldn't find my exact example.

I have "page1.php" with a <form> that includes one text field and a submit button. Once submitted the data in the text field would be entered into the DB. I want to make sure that before the <form> is submitted that there has been some data entered into the text field. I have seen the function --- empty() and I have also seen if (!$textfieldName)
all coupled with <? PHP_SELF ?> in the action field of the <form> but it just doesn't seem to work for me.

I think that it doesn't work because the page that I am entering data in the text field is also inserting data to the DB from a previous page and the <? PHP_SELF ?> is conflicting with this----(Just speculating).....I don't know I am kinda stumped.

Text Field Variable
I'm new trying to use php forms.  Trying to write what is typed into the text field to a file.  But its not working.  It makes the file, but the text field data is not written. Code:

How To Query In A Text Field
can i query in a text field, i have the normal fulltext search but i want to or substr search it or something, but i dont know how.

Deleting A Field Value Based On Date?
How would I delete a field value in a mysql database every 24 hours? Anyone know?

Date Field Defaults To 01/01/1970...!!?
I'm having a problem with an SQL datetime field. The field is set to allow nulls and that it has no default value but when I submit the PHP form the datetime field gets updated to 01/01/1970 12:00:00:00 AM. Can anyone tell me whats going on!? I want to have the null values!

Validating TEXT Field Entires
Because I have several TEXT fields in my MySQL database, I need to know how to validate that only alphanumeric characters have been entered -- as this data will be echoed back to the user upon completion of the form.

Therefore, I need to prevent any malicious text from being entered into the form (SSIs, HTML formatting, etc.)

Is there any way to do this?

So far, I've only been referred to addslashes(). I've managed to use the following function:

function validate_text($text) {
$text = addslashes($text);
return ($text); }
$input_text = validate_text($input text);

But this only escapes single and double quotes with the slash. URLs, SSI statements, etc. remain untouched.

TEXT Or BLOB Field Problems
When I use a form and php to input long articles (in a TEXT field) into a mysql table, the code runs smoothly (i get a thank you message). However, the record isnt always put into the table.

If I input only the varchar fields into the form, then it works. But if I also try to append the TEXT field then it doesn't work from a web form. It works sometimes but not all fo the time.

Why does this only work sometimes, do i have to do something witht he code? change the database?

Form Text Field Validation
I've got a form and I'm now trying to validate the text fields in it. The field I want to validate is for someones name, so there should only contain letters. Below is the function I've written to handle this. Code:

How To Find A Match In A Text Field ?
i am using ereg($rowvalue[0],'humor2')==true to find a match in the text field. how can i find a exact match, ie. the text field contains 'humor,humor2'

so, if using ereg the result will be true for both humor and humor2 but only 1 - humor2 is correct. how do i find an exact match ?

Increment A Text Field In A Form
I am creating an intranet which shows active projects and allows people to add new projects. If users want to add a new project, they fill in a form but what I want the form to display in the ProjectNumber field (which is a var char field & not the primarykey) is the last Job Number incremented by 1.

For example if the last ProjectNumber was TS0014, then the default value in the ProjectNumber field should be TS0015 - this way users know what the next job number is.
At present, the last job number in my table is TS0014. Below is the code i'm using but for some reason in the Job Number field in the form Im getting TS001? WHY? Code:

Form Field Text Output
How can I get html code in an editable form field to display properly? Specifically: I have text that is echoed to a form field via <? echo $text ?>

The user can then edit that text and submit. However <BR> is showing up as a literal <BR> and should be a linefeed. Is there a way to have this display properly?

Example: LINE ONE<BR>LINE TWO
should display as
LINE ONE
LINE TWO

Note that this is only a problem in the form field. It displays properly when echoed outside of the form.

How To Get Un-escaped Text From A Form Field
I have a php script that gets the text from a form field:

<?php

include("global.inc.php");

pt_register( 'POST', 'test1');
echo $test1;

?>

The text comes back fine, just some characters (', " and ) are now escaped
(', " and ). The problem is that I need the he text to be exactly as it
was entered by the user. I could process the text myself, and replace the
escaped characters, but I'd like first to understand why this is happening
and if there is a way to disable this behavior and get the unmodified text
directly.

Text Field, Dates And Insert
The user types a date (dd-mm-YYYY) in to a text field, the date is checked against a regex and if it passes, is then inserted to a database.

For some reason inserting the date ($this->input->post('date')) directly in to the database gives the default for the field (0000-00-00). I've tried doing date("d-m-Y", $this->input->post('date')) but get 1970-01-01 or something like that. Do you have any advise for converting the text field input in to a format that can be inserted in to the database?

Removing URL Link From Text Field
How can i remove a URL link from a form text field or the area where results are posted when a user enters http://www.mywhateversite.com. For example, here on this site.

I want to allow the text, but not the link. If you guys are familiar with myspace and have tried to put a link to another site, the myspace site automatically changes it to something else or blank. Thus allowing the user to post the site url, but without the link.

Stoping Auto Updates Of The Date Field
I have a table with a field using the "timestamp" type. When I update another field, the "timestamp" field also updates to the time the other field was updated. I don't want this.
I'm using this to update the table. PHP Code:

Split Title From Date In Field Using Preg_replace
I am building a CSV file but one of the fields for titles contains the title and a date at the end in the format of dd/mm/yy, such as

"summer manual 03/01/07".

I want to split this into two csv fields by doing this,

"summer manual,03/01/07".

What regex do you need to search for the dd/mm/yy part of the string? I am not very good at these myself.

PHP Will Not Read More Than 4096 From My Microsoft Sql Text Field.
I have a textarea that is saving to a mssql text (very large) field. The insert, update is working fine. However, when php reads the data using mssql_result function, I'm getting limited to 4096 characters read by php. I know that there are at least 6000 characters and I can see them using microsoft's query analyzer. This is not a magic quotes, single quote, quote, html entity or anthing like that. PHP will not read more than 4096 from my microsoft sql text field. Any ideas how I can get php to read more?

Is It Possible To Modify Part Of A Text Field Output?
I am made a simple web site search function. I use MySql 4 and have a table that contains all text on a web site in a column type text.

I can search it, but I want to make the search term bold when I print out the text field content. PHP Code:

Text Field Eats Up Multiple Words!!??
I pass a variable in my url which is let's say two words separated by a space.
now if i just echo($variable) then i get both the words as they are.. separated by a space... but on the other hand if i put that same variable inside a text field.. i.e <input type=text name=bla value=$variable> i get only the first word of the variable

e.g.
$variable = "hello there";

displayed normaly i get:
hello there

displayed inside a text field i get:
hello

i tried using different things like urldecode/urlencode/rawurl blabla/ the best i could get to display was a hello+there
so is there any solution to displaying $variable as it is inside a text field.. by the way it displayed fine if i use a textarea but i need to use a normal text type input.

Inserting A Row Of Characters In Text Field Automatically
Good Day to All! Hoping someone can help with this simple problem. I am inserting text into a text field. Because there may be a number of entries made sequentially I want to automatically insert a line of characters such as ****** or ------------- automatically between rows to make the output more legible. Here is what I have so far. I want to insert the line after ....

How To Sort A Flat Text File By A Particular Field
I have created a flat file database to store contact information on my friends. The fields are 'firstname', 'surname', 'job title', 'address' etc What I am trying to do is be able to display a sorted list of my friends based on a particular field eg 'sort by surname'or 'sort by address' etc

Each row in the file ends with a '' and each field in each row is separated by a ' '.

I have come to the conclusion that I need to use the array_multisort function but cannot find any examples of taking information from a flatfile database and using array_multisort to sort and display based on a particular field. This is how far I have got but I am now stuck as to where to go from here? I have read the php manuals but it does not appear to improve my understanding of what needs to be done. Code:

Displaying Information From A Database In A Text Field,
I am trying to create an admin page, but before I get anywhere near that, I need to understand how to get data froma database to show up in appropriate form fields *text, textarea, etc...*

I am able to get content from my database to show up in my template, now I want to create a page that allows a user to click on a link for which they want to edit the information (name, and bio) So I want that page to show up with a simple form, a text field displaying the name, and a textarea displaying the bio information, so that they can modify it and save it to the database. how do you get the information to show up in the form fields? Code:

Passing PHP Variable Into An Html Text Field
I am working on a flatfile configuration program and I need to read a single record csv file into php and pre-load the values into html text boxes. I have the file reading part working with 6 variables $field1 through $field6. When I am done, I then save the form back to the same file. This allows a configuration file to be updated from the web.

How To Check For Blank Spaces In A Text Field???
does anybody know how to check for blank spaces?  I dont just mean blank, blank but actual spacebar spaces. ive tried is_null and !isset and neither one works??

Help On A Multiple Keyword Search On A TEXT Field Type
Working on a php/mysql driven site which requires me to have a search facility based on multiple keywords. I read the tutorial "quick and dirty search engine". What i want to know is :

1. Is there any SQL query i could perform which could to almost the same thing ( i dont really need the accuracy ) ?

2. Any other methods of achieving it?

Is There A Php Command To Take A Specific Field From A Delimited Line Of Text?
I have a string which is multiple fields delimited by commas.

I would like a php command that says... take the 3rd field for
example.

ie. If MYVARIABLE has the data "hello,there,big,world".

I would like to be able to say, pickup the 3rd field "big" without
knowing the character positions or lengths.

Removing/stripping Unwanted String In A Text Field
I have an abstract field that contains some rtf codes..now I want to strip all those rtf format so I can display it in my page cleanly..how can I accomplish this?. Code:

Formatting The Contents Of A Text Area Form Field
On my site I get users to enter a load of information in a textarea
box, however when i save this data to my mysql DB and then retrieve it,
it comes out without all the formatting, like new paragraphs and new
lines.

Can anyone tell me how you can capture the data entered into such a
field with all the formatting the user has entered like new paragraphs
etc?


Copyright © 2005-08 www.BigResource.com, All rights reserved