Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Mysql + Php Question
omarsdali
post Jan 8 2008, 12:03 AM
Post #1


Member [Level 1]
****

Group: Members
Posts: 74
Joined: 2-June 07
Member No.: 44,080



Hi,


I am creating a website in php and using a mysql database to store the data. I want to store time data in the database. My question is what is the best datatype I should use and how do I read the time from the database and format(display) it using php ?
Go to the top of the page
 
+Quote Post
sonesay
post Jan 8 2008, 01:34 AM
Post #2


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 642
Joined: 20-June 07
From: Auckland
Member No.: 45,102



The best datatype to use for each field would depend on what kind of data you intend to store. You will have to get fimilar with these datatypes before you begin to use it or you may end up with the wrong ones.

I'm not sure what your asking on the last question. Do you want to know how to display the data in your database? You mention time in there do you mean time from the database? I'm not sure mysql stores time.
Go to the top of the page
 
+Quote Post
jlhaslip
post Jan 8 2008, 02:03 AM
Post #3


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,882
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



SQL code for adding Table to the Database:
SQL
CREATE TABLE users (
user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
first_name VARCHAR(15) NOT NULL,
last_name VARCHAR(30) NOT NULL,
email VARCHAR(40) NOT NULL,
password CHAR(40) NOT NULL,
registration_date DATETIME NOT NULL,
PRIMARY KEY (user_id)
);

#INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('Larry', 'Ullman', 'phpmysql2@DMCInsights.com', SHA('password'), NOW());



php code for MySql:
SQL
$query = "SELECT CONCAT(last_name, ', ', first_name) AS name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC";


php code for printing the Results of the above query:

HTML
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['dr'] . '</td></tr>
';
}


So, the DB Table has a field that is "DATETIME", that is added to the DB using the NOW(), that uses "DATE_FORMAT(registration_date, '%M %d, %Y')" in the Query, and prints it out via php as an Associative Array string...

try it.

*code snippets from a Book on Php and MySql by author Larry Ullman, PHP and MySql For Dynamic Web Sites*
Go to the top of the page
 
+Quote Post
shadowx
post Jan 8 2008, 05:18 PM
Post #4


A clever man learns from his own mistakes, a WISE man learns from those of OTHERS
*********

Group: [HOSTED]
Posts: 884
Joined: 12-April 06
From: Essex, UK
Member No.: 21,719



jlhaslip covered good code there so take a look at that. Also google Tizag and maybe "php mysql tutorial" alongside it and you should find an excellent website for PHP and SQL tutorials which is where i learned all i know today.

as for datatypes. Im a lazy person when it comes to DB's, unless you're going to be using functions like comparing two numbers to find the highest, or incrementing a number, or comparing dates you dont need to worry too much about data types (IMHO) So you can store a number in a TEXT field and it wont make any difference. Unless you ask the DB to compare the numbers to see which is higher etc.. then you have problems.

Also with numbers in Ms access you couldnt start a number with 0 for some reason.. i dont know if this is true in MYSQl but if it is then numbers like phone numbers should always be in a TEXT field, otherwise you hit errors. As for text i just stick it into a TEXT field, it makes sense, i dont know the reason for all tghe other data types like blob and such.. they just seem useless when i have text, char and integer types. I guess its for validation but its better to validate with PHP and JS (or whatever language you're using) rather than passing it to the DB then handling the error it gives without showing the user a messy error message and then going back to the PHP page to get them to change it. Its just a waste of time and BW if you have a big site.
Go to the top of the page
 
+Quote Post
gogoily
post Jan 10 2008, 01:58 AM
Post #5


Member [Level 2]
*****

Group: Members
Posts: 76
Joined: 30-October 05
Member No.: 13,571



I prefer "DateTime" type
It stores data in form of "YYYY-MM-DD HH:mm:ss"
Go to the top of the page
 
+Quote Post
iGuest
post Jun 2 2008, 01:50 PM
Post #6


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



Importing excel to mysql by using php coading without using csv it is possible?
Mysql + Php Question

Hi,
I am working in php from 3 months, I am new with php so I trying to convert excelsheet data into mysql without using csv. I am lot of trying but I cant solution. I tried to converting excel sheet into csv and then by using coding importing it through coding.
But in excel shee in address and products column there is lots of commas is assign.
So it can break from that and put it into next field into database. To avoid this situation is reticules because my excel sheet contain around 40,000 rows so I can not possible to modify csv file.

Please guide me and tell me direct importing method excel to mysql to solve my problem. It urgent.

Thanks & Regards
Chetan chopkar
Excel Informatics


-question by Chetan
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Mysql Infos(2)
  2. Mysql Tool(0)
  3. Mysql And Ms Access(1)
  4. What If You Forget Mysql Root Password(2)
  5. Mysql Host Adress(4)
  6. Import From Excel File Into Mysql Database(7)
  7. Php And Mysql Problem(8)
  8. Tips On Creating Your Own Search(1)
  9. Syndicate Your Content Using Php And Mysql(0)
  10. Phpbb And Mysql Relations?(2)
  11. How Do You Combine Multiple Mysql Databases Into One Database?(3)
  12. Merging Database Php Mysql(5)
  13. Which Data Type To Use In Mysql Table(4)
  14. Another Question On Mysql Table Data Type(1)
  15. Accessing Mysql From Javascript(4)
  1. Index In A Mysql Database(3)
  2. Mysql(2)


 



- Lo-Fi Version Time is now: 25th July 2008 - 09:30 PM