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




Date/MySQL Query


I am making an event calendar that allows users to add events. An event can possibly span multiple days so I made two fields for start date and end date. This all works fine.

I want to be able to grab the data out of the database through a query and display it on the webpage in order of date. So I'm ordering by the start date. However if the event is 3 days long I want to show the event on the page 3 times, with all other events in between also show. I have not been able to figure out the logic on how to get the event to show up 3 times with other events in between them?

Sample Data:
Event 1 Dec 31 2002
Event 2 Dec 31 2002
Event 1 Jan 01 2002




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Mysql Date Query
I need to check if one script was run later than one hour ago - I had a problem with cron and want to put in a safety code.

On successful running of the script I remember the date in db
CREATE TABLE log(id INT NOT NULL auto_increment, ttime DATETIME, other_info TEXT, PRIMARY KEY(id));

The sql query that I use now is:
SELECT HOUR(CURDATE() - ttime) as h FROM log ORDER BY h LIMIT 1;

However I have a problem - it returns sometimes value NULL (which is always first).

If I use the following syntax:
SELECT HOUR(CURDATE() - ttime) as h FROM log WHERE h IS NOT NULL ORDER BY h LIMIT 1;

I get the error: Unknown column `h` in `where clause`. What can I do?

MySql Query, Php Date Format.
This is actually 2 questions, but they go to gethere so I'm asking them as one. First, how do I write a MySql query that returns all the rows that have a date in the date collum that is newer than todays date? Then I need to take those rows, format the date in them and then print them in a table.

Date Range In MYSQL Query
I'm trying to extract data in a certain range of date (say 1 month's worth), but my results aren't what I'm expecting.  Can you guys have a look at my code and suggest what may not be coded properly?

function display_archive($month) {
  $tempdate = $month. " 1, 2007";
  $startdate = date("F d, Y", strtotime($tempdate));

  $tempdate2 = $month. " 30, 2007";
  $enddate = date("F d, Y", strtotime($tempdate2));

  db_connect();
  $result = mysql_query("select * from blog where entered BETWEEN '$date' and '$enddate'");
  $num_rows = mysql_num_rows($result);
}

How To Make MYSQL Query To Sort The Articles By Date ??
I am developing a site using PHP and MYSQL where i can post articles. Each Article has features like author, date, data etc... I want to find out top 5 recent articles.

I store the date of an article in database as  $timeStamp = Date("F j, Y");

when i make a query to retrieve the latest article by date as:

$result = mysql_query("SELECT * FROM postData ORDER BY postDate DESC LIMIT 0, 5");

it doesn't give any output...

Get Most Recent Row On An Inner Join Mysql Query Based On Date
Here is my current query:

SELECT tbl1.id, tbl1.username, tbl1.status, tbl1.joined, tbl2.timeDate, tbl1.directory FROM tbl1, tbl2 WHERE tbl1.id = tbl2.users_id GROUP BY tbl1.id

This returns their oldest ie first login.  I use this for analytics on the backend to determine user activity.  So I would like a query that instead that returns the most recent tbl2.timeDate.

Date Is Not Being Pulled From MYSQL Database, Instead Current Date Is Displayed!
I am having trouble pulling a date from a database using PHP at the <a
href="http://www.mytuneslive.com/ameshkin69/"> following page.</a>

Here is the code. As you can see, it is just making the date the
current time. The values in the database are UNIX timestamp, and the
DATE() function is used to convert from UNIX to readable date. Can

<td width="55%" align="left" valign="top"><?php
$row_comment['timestamp'] = date("n d Y g:i A");.....

Further Date Query....
I have my compiled date function working, thanks to a devshed user , It enters the start date. which can be set manually by the administrator as they may not want to start their contract for three weeks after subscribing etc. This works fine. The end date should be set by the contract length that is chosen in create user. Month / Quarter / Annual and a few others....can I make

$end_date = ($compiled_start_date, +365); and if so, would it enter it into the db as the same format that start date goes in which is 2003-MM-DD?

Also - does anyone have any suggestions for automaticall setting my start date form fields to today's date? I have three fields, days, months, year (year is non-changeable so is not a problem).

Date Query
This may be more of a MySQL question but possibly a php solution. I'm trying do do a query to return how many days a member has been subscribed. The column date is the date they joined. Code:

PHP Update Query Mysql: Query Succussful?
I can't seem to successfully test an update query. Below is a piece of code that updates a statistics table. If row today doesn;t exist, a new day must be created. But this doesn't work...

thank you for your reply.

$today= date("Y-m-d");

$qq="update totals_r set hits_r=(hits_r+1), lang_$lang=(lang_$lang+1), cat_$cat=(cat_$cat+1), rating_$rating=(rating_$rating+1), bussite_$bussite=(bussite_$bussite+1) where date='$today'";

$result_6 = mysql_query ("$qq");

if (!$result_6){ /// IF !ROW_TODAY ==> CREATE NEW DAY

$qq_2="insert into totals_r (hits_r, lang_$lang, cat_$cat, rating_$rating, bussite_$bussite, date) values(&#391;',&#391;',&#391;',&#391;',&#391;','$today')";

$result_6_2 = mysql_query ("$qq_2");

if (!$result_6_2){
$err_msg_sql_6= mysql_error();
$err_loc_6="$PHP_SELF"." // Query6: update totals_r";
}
}

Sort By Date Query
I have a gallery website that has a search facility and im trying to work out how to amend the php so the results are shown by newest photo first.This is the code.  I dont even know where to start looking. I looked at the usort section but I didnt see anything that made sense to me to amend. Code:

Query Date Range
I have a table which holds a bunch of dates

id   datefrom       dateto
1    2007-02-22   2007-03-05
2    2007-05-13   2007-06-23
3    2007-05-25   2007-07-23

the `datefrom` and `dateto` are dates in the format YYYY-MM-DD, the `datefrom` means the date the event starts and the `dateto` means the date the event ends.

What I want to run a query on this table and return any rows which have todays date between the 'datefrom' and the 'dateto'.

Does that make much sense?

Php Query To Select Min Date
im trying to get a minimum date from my database, the current way im doing it is:

SELECT * FROM events where Date > NOW() OR Date = '9999-12-12' ORDER BY Date ASC LIMIT 1

this works in terms of code, but it doesnt do what I want it to do. Its the ORDER BY Date, that is the problem: What I want to select is

The next date OR a date = 9999-12-12

I tried searching for a query like "select MIN date" but couldnt find anything on it, plus the date has to be in the future, hence the need for DATE > NOW()

quite confusing I know!! but any advice?

Date Dropdown From Mysql Date Entries
For the PHP gurus out there, here is what I want to do: create a dropdown list of available dates from a mysql database date entries. But the dropdown/s should have 3 separate fields in month, day and year which in effect shows only those months, days and years that have corresponding entries from the database.

Planning to use this in the archive section of an online news publication so people can select issues to view via dropdown list that have corresponding entries only.

UNIX Mktime To MySQL Date Or Date
A form that sends a starting date and an ending date. I have figured out how to tell the difference between the two and even rip the difference into an array because I need to compare the individual dates against a mySQL database to pull results from a particular date in a series. This is no problem. My problem is that teh mySQL database uses DATE as a field definition and this can not be changed. I managed to pull the date differences using some cleaver mktime stuff but no I do not know how to get this 1072242000 into this 2003-12-24...

Is there a function that reverses the mktime result into a usable date format? I would take anything at this point and I can explode and then array it to get what I want - but there has to be something. Code:

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?

Creating A Date Range Query?
If I have a date field, and want to select all records that are older then 30 days from today, is there a way to query MySQL for this? Code: $todaydate=date("Y-m-d");

$query = "SELECT * FROM members WHERE joined_date = '$todaydate-30' "; I know this will not work, but it's functionaly what I am trying to do.

Date Range Query Issue
I have a database which contains events, the structure has two date fields, one is called "datefrom" and the other one is called "dateto", these two fields contain dates in the format YYYY-MM-DD.

"datefrom" represents the start date and then "dateto" represents the end date.

I have a query which returns all rows which have todays date within the start and end date, but it doesnt seem to be doing this correctly all the time, if at all. Can anyone spot any issues I might have with it?

My query is

$eventssql = "SELECT * FROM events WHERE type = 2 AND datefrom BETWEEN CURDATE() AND CURDATE() + INTERVAL 6 DAY OR dateto BETWEEN CURDATE() AND CURDATE() + INTERVAL 6 DAY LIMIT 10";
$eventsquery = @mysql_query($eventssql,$connection) or die(mysql_error());
Make any sense?

Query Date Range Select
how do i make a query that select between today and a week from today.

Limiting A Query By Number And Date
I run a hockey league and want to post my schedule for the upcoming season.  The problem is that I have 100 games in the season and I want to limit the query to 30 games on the schedule that is posted on my website.

That part was no problem for me but I also would like to have those 30 games be determined by date. So I would like the script to acquire the current date and post the next 30 games that are upcoming. I have a date field in the daatbase that is in the form YYYY-MM-DD. 

Convert Date From A Database Query
I have a simple database for events. I have a column named "date" that I would like to display as "March 8, 2007" on the webpage. What do I need to add to change the date format? Here is my php code:

PHP Saying Error In Mysql Syntax, But Written My Mysql Query Browser!
I have a basic db that I access with MySQL query browser. Everything
seems fine to me but I am using this db as part of a php shopping
basket and when I try to add an item I get:

Notice: Query failed: You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '>function.extract]: First argument should be an
array in functions.inc.php on line 31
Notice: Undefined variable: price in functions.inc.php on line 36
Notice: Undefined variable: price in functions.inc.php on line 39
Notice: Undefined variable: total in unctions.inc.php on line 39

I'm assuming the last three are caused by this problem as price should
be passed to the cart, and total is worked out using it. However
although I know mySQL code it was the MySQL query browser that
actually generated the code and I cannot see a way to view or debug
the code.

The db has one table in it which is made up of id, name, subname,
desc, and price.

The code in the php file that is being referred to is:

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?

Query MySql Using PHP
I've created my first search form and it seems everything is working pretty well. However, since I am very novice in scripting in general, I'm having one problem that I can't seem to unearth an answer to. Perhaps someone could easily offer the answer:

my query asks to select a 2 char state code or a 5 digit zip code in order to obtain results desired. In testing, if I enter a state code, it brings up only the state requested. However, when I enter a zipcode, I get the wrong results. I'm sure its the "LIKE" that is throwing this off. Here is the query portion of the script:

$result = mysql_query ("SELECT * FROM fish_dealers
WHERE Zip = ´$Zip%´

OR State LIKE ´$State%´
");


Can anyone give me a clue?

Mysql Query
I have wrote a Select statement, that checks if the user and password and returns a value, however can i add something to the statement that would allow me to get the userID from the table users, so that i can write the value to a cookie, is it possible. PHP Code:

MySQL Query
I want to have a field where I store a list of what categories that
particular row falls under, I don't know which format to do or how I
would query it.

For example, row1 might belong to categories 1, 3 & 7 - I'd want to be
able to query all rows belonging to 3 and get row1.

AND And OR In MySQL Query
I've build a query from a php form where people van select more results for a cell wich can only contain one value Here's my query:

SELECT * FROM person WHERE color_eye = ('brown') OR color_eye = ('black') AND color_hair = ('Blonde')

Everything after the "OR" will be ingnored. So how can I tell MySQL I want all the brown and blacked eye?? Without the AND it works fine, but in real the query is way longer with multiple AND's.

Mysql Query
I have a code that installs some tables into a mysql database. Heres the code, but it keeps coming up with the error "Install failed (ID 1)" I have tried tons of things, even looking at other installers and mimicking them, but nothing. PHP Code:

Php/mysql Query
I want to display the users name on the pages when they have logged into my site. i have done it one way that is to take what they type in the login form and post it on the page and that works fine. only one problem and its more of a preference than a problem but the way i did it takes exactly what they type say "username" and posts that so if they type "UsErNaMe" it will post it like that. i want to show the name exactly as they make it when signing up. im guessing i have to query the data base... mine being MYsql. PHP Code:

Mysql Query
How can I get rownum using MySQL queries ,
In Oracle one can you in this way SELECT rownum as srno, fname FROM
tablename
suppose If there are 45 records and if i use while for the

srno should display 1, 2, 3, ... 45

query like SELECT rownum as srno, fname FROM tablename

I dont want to use php counter, i want it from query

Mysql Query
I'm running a sports pool and I'm trying to display stats from the
results of the picks.

The table is 'results' and the fields are 'pick_number', 'game_number',
'user_id', 'points' and 'date'

There is one record for each users' pick. 0 points are given for a loss
and 1-4 points are given for a win. I've already created a query that
gives me the top players by overall points but I'd like to expand that
to include the number of points won just this week, overall winning %
and winning % this week. Can I do this in one query and then display in
an HTML table?

$query = "SELECT user_id, SUM(points) AS points FROM results GROUP BY
user_id ORDER BY points DESC";

Mysql Query
1) i have a database divinelive_messages table with a sessid column
2) i need to find out rows from the database, which only show that sessid in there once.

Mysql Query With * And +
im trying to return all results that come from or went to certain extensions on our phone logging system but i don't want to return any that have a src or dst that contain a * or a +. This is the where statement i have that is not working Code:

Getting MySQL Query
I took some info out of my database.  I want to display an error page if their are no rows in the database.  How would I go about doing that. I have this:

$query = I execute my query here.  Taken it out so you don't connect to my database Muahahahhaah

$row = mysql_fetch_row($query)

if ($row == '')
{
echo 'Their is nothing in the database!';
}else{
echo 'Yes, the database does home info in it.';}

What would I put to make this work?

MySQL Query
Whats wrong with this query:

SELECT from, subject, message, time FROM user_messages WHERE username='$username' ORDER BY timestamp DESC

I get this error:
QuoteYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, subject, message, time FROM user_messages WHERE username='Drezard' ORDER B' at line 1

MySql Query
I'm having some difficulty formulating  query that will allow me to retrieve the details of a specific user in the database. The user's information is stored in one table called Users and another called UserProfile. Both tables are linked by the UserID field.

My current query returns a Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource and my knowledge of Mysql is not great(Still learnng)

Here is my code:

Date Mysql Vs Php
I had a question regarding php gathering a MYSQL and then formating the date. This was answered, however, like most things in life, there was more than one way to do it.

The question now is this: What is the most optimal way of handling date formating. This might even be important for other such queries. Should PHP be used or MSQL? Is there a speed issue?

DATE, Php/MySQL...
I want the date print it like this d-m-Y how i can do this? I know that is default at MySQL (y-m-d) but i want to change it? Code:

Using Date With PHP And MySql
how do you sort a date, mysql way of storing the date seems somewhat strange, to what I learned from using access and ASP, with asp you could read in a variable in to a specific ASP and arrange its formating, I can't seem to find a way to do this with PHP date() only seems to insert the current date, is there a way or does it require a little coding?

Php And Mysql DATE
I have a mysql database and a vairable thedate of the type DATE. I search for a specific date, and when I try this: date("d-M-Y", $thedate) I get 31-Dec-1969, but $thedate is 1999-04-03. What could be the problem?

MySQL Date
i have my database and in that db there is a table. one of the columns is a date column, so the format is YYYY-MM-DD all i want is to be able to format the date when i retrive it from the DB say the db value is 2007-08-02 i want my php script to display Tuesday, 2nd August 2007.

Date() And Mysql
Whenever I store an output from Date(YmdGi); into my mysql database. It always comes up as the same number...

E.G: My database looks like this

Timestamp        |  Username

2147483647          John
2147483647          Jack
2147483647          Peter

Here is my script:

// $username = Form data

$timestamp = date(YmdGi);

echo "$timestamp";

$result ("INSERT INTO users (timestamp, username) VALUES ('$timestamp', '$username')");

When I run this script it outputs something like 200703251056 but then in the database its always that same number....

What am i doing wrong?

Need Help With Basic Php Mysql Query
$z = "goodBMW"; the word goodBMW is no where to be found in in the table times. but it will echo every single row thats in that table and it doesend sort between Group 1 and Group 2 where the hell is my query wrong.

Problematic MySQL Query
Would anyone be able to help me with the following MySQL problem. I am
trying to extract all of the users who are not on vacation for a given
date. I am using a NOT IN statement, however, I need to have a more
advanced query than a simple one. What I need to do is as follows
SELECT users.user_id,...

MySQL Query Quandry
I have a simple need to go into a 4 column table and based on the content of the first 3 print the content of the 4th. In other words if column1 = a, column2 = b, and column3 = c then print "dog" from column4. This will be the action for a short form that allows the user to make 3 choices that will determine a link. I have this from another script that I'm trying to modify:

mysql_select_db('search_links');
$query = "select * from links ";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo '<p>Number of books found: '.$num_results.'</p>'
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. Title: '
echo htmlspecialchars(stripslashes($row['type_prop']));
echo '</strong><br />Author: '
echo stripslashes($row['area_code']);
echo '<br />ISBN: '
echo stripslashes($row['price_range']);
echo '<br />Price: '
echo stripslashes($row['saved_link']);
echo '</p>'
}

The above query prints the entire table and I would like a query that limits to the form choices indicated above.

PHP: MySQL UPDATE Query
I need to have a page where the user can update his info and/or delete his record. I haven't tested the DELETE query yet.

When I open the page it shows all the info stored in the database. When I change something and hit the update button I get the message that the record was successfully updated, but nothing really hapens.

If you want to see what's happening go to URL , click on the 'directory' link
The user ID is 'scooby', and password 'dooby'. If it does not work, try the following combination: user ID: 'sunny', password: 'trout' . Then click on the 'edit profile' link and try to change something and see what happens. I am attaching a php file of the 'edit profile' page, the one I am having trouble with so you can see the entire code.

Getting Variable From Mysql Query
what's the best way to set a variable = to a result from a mysql query?

Advanced Mysql Query
There are currently two queries in one of my scripts. One is:

SELECT * FROM foo

the other is:

SELECT var FROM bar WHERE something = 'somethingelse'

Is is possible to use a join statement and combine these two into one query? My reason is that I'm trying to speed up the script, and hopefully combining the queries will do that.

Mysql Query - Select Any
I have the following sql statemant to search a mysql database that gets
if values from a form with combo box's in.

SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =
hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND
hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND
hottubs.seatsto <= '%s' AND hottubs.shape = '%s' ORDER BY
$thesearchtype_search.

Everything works fine except I want to add a select "any" from the
shape combo box. I really need a way of cutting out the last " AND
hottubs.shape = '%s' " if the $_GET['shape'] = 'any'
Will this work using a variable as shown below??

IF ($_GET['shape'] != 'any' )
{
$shape = AND hottubs.shape = '%s'
}

SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =
hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND
hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND
hottubs.seatsto <= '%s' $shape ORDER BY $thesearchtype_search

I have only been doing php about a month so go gentle!

MySQL Query On The Same Page.
here it is: i have a table with lets say 2 fields, first_name and last_name. When user enters index.php he gets database records sort by first_name (ORDER BY first_name). Now i ave made two links above those records. They are: sortb by firts name and sort by last_name.

My question is, what code should be written for the link sort by last name if i wanna show the same records already displayed but sorted by last_name???

And how do i make that if user has clicked sort by last name that thislink is disabled (not underlined, just bold text) and if he clicks on sort by first name that this link becomes text.


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