By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

How do I insert specified time as a query?

P: 16
while($i=01:00; $i<=01:10; $i++){
$query= "INSERT INSERT INTO $January_Ad1 (Day, Time) VALUES ('1','$i')";
$result= mysql_query($query);
}

I want to insert 11 rows that say the Day is 1 and the time is incremented by 1 such that the time would read 01:00, 01:01, 01:02... 01:10.
Dec 22 '07 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
while($i=01:00; $i<=01:10; $i++){
$query= "INSERT INSERT INTO $January_Ad1 (Day, Time) VALUES ('1','$i')";
$result= mysql_query($query);
}

I want to insert 11 rows that say the Day is 1 and the time is incremented by 1 such that the time would read 01:00, 01:01, 01:02... 01:10.
What you are using there is incorrect.

i.e.
a while loop:
[php]
while($something < $somethingElse){
//execute code
}
[/php]
a FOR loop:
[php]
for($i = 1; $i < 100; $i++){
//eecute code
}
[/php]
Dec 22 '07 #2

Markus
Expert 5K+
P: 6,050
After changing a few things i got the code to work :)
The revised code:
[php]
<?php
for($i='01:00'; $i<='01:10'; $i++){
#$query= "INSERT INSERT INTO $January_Ad1 (Day, Time) VALUES ('1','$i')";
echo $i."<br />";
}
?>
[/php]
1. I changed the loop to a FOR loop.
2. 01:00 is not a valid interger, so i wrapped it with single qoutes to change it into a string.
3. Echoed out the string to show it works.

-- just uncomment the query line (remove the #) and give it a run

:)
Dec 22 '07 #3

P: 16
that worked very well and thanks for the fast response! only problem i am still having is getting it to insert into the database. it prints it out fine separately, but it's not being queried into the database even after i added in the line $result=mysql_query($query);
Dec 22 '07 #4

P: 16
nvm, found that there were two inserts in the query.


thanks again though for the help!
Dec 22 '07 #5

Markus
Expert 5K+
P: 6,050
nvm, found that there were two inserts in the query.


thanks again though for the help!
No problem my friend :)
Dec 22 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.