Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP not giving correct Mysql results
Old 11-29-2010, 11:14 AM PHP not giving correct Mysql results
Novice Talker

Posts: 5
Name: Daniel White
Trades: 0
Hi

I have been going over this for the best part of a week, with no resolve. I would like this simple MySQL link to show an accurate list of events, automatically kept up to date by the MKTIME function. I know the DB table is accurate, but I cannot see where my script is going wrong. Any advice would be amazing. Thanks in advance.

Dan

PHP Code:
$link mysql_connect('HOST''USER''PASS');
                            if (!
$link) {
                                die(
'Not connected : ' mysql_error());
                            }
                            
$db_selected mysql_select_db('DBNAME'$link);
                            if (!
$db_selected) {
                                die (
'Failed to load data : ' mysql_error());
                            }
$result mysql_query("SELECT * FROM TABLENAME ORDER BY yy ASC, mm ASC, dd ASC  LIMIT 4");
    while(
$row mysql_fetch_array($result))
                                {

list(
$day$month$year) = explode('-'$row['end']);
$timestampmktime(000$month$day$year);


 if(
$timestamp mktime()){echo'';} else{
                        echo
'
                                    <a href=""><img src="'
.$row['ROWNAME'].'" height="220" /></a>
                        '
; }
                        ;} 

Last edited by NullPointer; 11-29-2010 at 12:06 PM.. Reason: added [php] tags
gingerdan1 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-29-2010, 11:54 AM Re: PHP not giving correct Mysql results
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
In what way(s) is it going wrong?
PaulW is offline
Reply With Quote
View Public Profile
 
Old 11-29-2010, 11:58 AM Re: PHP not giving correct Mysql results
Novice Talker

Posts: 5
Name: Daniel White
Trades: 0
It is just not returning anything. It works in reverse, i.e. {if($timestamp > mktime())} perfectly well. My database is sound, I just cannot see what is going wrong here.
gingerdan1 is offline
Reply With Quote
View Public Profile
 
Old 11-29-2010, 02:26 PM Re: PHP not giving correct Mysql results
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Not sure if I'm understanding you correctly. Are you saying that the table has a field named end which contains a date and that you have records where that value is before current date/time and records where it is after, and that those after are returned by the query but not those before? Can you echo the values returned from list($day, $month, $year) = explode('-', $row['end']);

Last edited by PaulW; 11-29-2010 at 02:31 PM..
PaulW is offline
Reply With Quote
View Public Profile
 
Old 11-30-2010, 05:17 AM Re: PHP not giving correct Mysql results
Novice Talker

Posts: 5
Name: Daniel White
Trades: 0
Hi
Sorry, should have mentioned, the function of the script is to automatically remove from view yesterday's events from a live music calendar based on a stated end date (defined as $row['end'] in the MySQL table) being less than MKTIME().
If I echo the results as the reverse, i.e. MKTIME() is less than $row['end'], it does produce the results as expected.
Dan
gingerdan1 is offline
Reply With Quote
View Public Profile
 
Old 11-30-2010, 06:37 AM Re: PHP not giving correct Mysql results
Novice Talker

Posts: 5
Name: Daniel White
Trades: 0
I think I have found the problem, but this leaves me with another. The issue is the LIMIT 4 section of the mysql_query. Because it will only read the top 4 results, all of which have their dates in the past, it will not show any more.

The newest dilemna is the following.

How do I delete rows based upon the $row['end'] being less than MKTIME()?

The idea would be that when a user loads the site, the pre-head section of the page would delete from the table the "in the past" rows before the page is produced, and thus, a totally up to date page is shown.
gingerdan1 is offline
Reply With Quote
View Public Profile
 
Old 11-30-2010, 08:11 AM Re: PHP not giving correct Mysql results
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
where end < curdate ?(I don't have access at the moment to mysql, sorry, that's why I'm sort of guessing.)
PaulW is offline
Reply With Quote
View Public Profile
 
Old 11-30-2010, 10:04 AM Re: PHP not giving correct Mysql results
Novice Talker

Posts: 5
Name: Daniel White
Trades: 0
Perfect! Thanks Paul! So obvious now!
gingerdan1 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP not giving correct Mysql results
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26680 seconds with 12 queries