Current location: Hot Scripts Forums » Programming Languages » PHP » MYSQL Error - Date select problem


MYSQL Error - Date select problem

Reply
  #1 (permalink)  
Old 10-16-07, 02:33 AM
vivabensmith vivabensmith is offline
Newbie Coder
 
Join Date: Nov 2006
Location: Bristol Uk
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
MYSQL Error - Date select problem

HTML Code:
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 ''newspage' WHERE (TO_DAYS(NOW()) - TO_DAYS('date_entered')) > 10)' at line 1
Hi all im getting the above error message from the code below? Im I missing anything as im new to date selecting in mysql?


PHP Code:

$query "SELECT * FROM 'newspage' WHERE (TO_DAYS(NOW()) - TO_DAYS('date_entered')) > 10)"
Reply With Quote
  #2 (permalink)  
Old 10-16-07, 02:43 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Remove the single quotes around the table name.
Reply With Quote
  #3 (permalink)  
Old 10-16-07, 03:02 AM
vivabensmith vivabensmith is offline
Newbie Coder
 
Join Date: Nov 2006
Location: Bristol Uk
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Nico!

date_entered

2007-09-25 21:47:49
2007-09-13 19:34:30
2007-09-13 19:29:48
2007-09-25 21:46:31

Im trying to select items from 'newspage' from the last 30 days, this should display all the above records?

$query = "SELECT * FROM newspage WHERE (TO_DAYS(NOW()) - TO_DAYS('date_entered') > 30)";

But its not?

PHP Code:

<?php 

// function
function trunc($phrase$max_words

   
$phrase_array explode(' ',$phrase); 
   if(
count($phrase_array) > $max_words && $max_words 0
      
$phrase implode(' ',array_slice($phrase_array0$max_words)).'...';
   return 
$phrase
}
// function



$page_title 'viewnews'
        require_once (
'../mysql_connect.php'); // Connect to the db. 
 

$imagesize='height="50" width="50"';

$alignright='right';
 
$query "SELECT * FROM newspage WHERE (TO_DAYS(NOW()) - TO_DAYS('date_entered') > 30)";
if (
$result = @mysql_query ($query))
{
    
$num mysql_num_rows($result);
}
else
{
    echo 
mysql_error();
}
      
      
       

    if (
$num 0) { // If num     
           
    
while ($myrow mysql_fetch_array($resultMYSQL_ASSOC)) { //While

    
$newsText=(htmlspecialchars(strip_tags($myrow['news'])));
    
$firstImage='uploads/'.$myrow['file1'].'';
    
               
      if(!empty(
$myrow['file1'])){ // ok an image exists
             
if(file_exists($firstImage)){ // ok image exists in the folder as well so display
         
echo '<p class="bold" align="left">' .$myrow['heading'] .'</p><p align="left"><img ' $imagesize .' src="uploads/'.$myrow['file1'] .'" align="'.$alignright .'"/>'trunc($myrow['news'],10).'</p>';
         echo
'<a href="#top">full details</a>';
            echo 
'<br />  ';
            echo
'<hr />';
        }
     } else {
      echo
'<p class="bold" align="left">' .$myrow['heading'] .'</p><p align="left">'trunc($myrow['news'],10).'</p>';
      echo
'<a href="#top">full details</a>';
         echo 
'<br />  ';
         echo
'<hr />';
     }
         
         
   } 
//End of if num
  
//End of while

    
    
else { /// if db not run display error 
    
echo '<table align="center" cellspacing="0" cellpadding="5">';
    echo
'<td><span class = "style1">Sorry, no records found!</span></td>';
    echo 
'</table>';
    
    


?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi & Myphpadmin getting started help php_guru_besar New Members & Introductions 4 03-19-06 11:06 PM
mysql query problem (very important for me...) pedroso PHP 5 07-26-05 01:09 AM
problem printing mysql data by "x rows/page" abtimoteo PHP 1 07-30-04 07:55 PM
Mysql Select IB FORUM PROBLEM landboy PHP 4 07-28-04 11:07 AM
Database table contents to email problem (PHP and MySQL) blokeofftheinternet PHP 2 04-29-04 09:34 AM


All times are GMT -5. The time now is 07:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.