Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php, mysql from_unixtime

Status
Not open for further replies.

darryncooke

Technical User
May 6, 2009
308
US
I have a select function in php.

Code:
$month_recordEventsmonth = "April";
if (isset($_GET['month'])) {
  $month_recordEventsmonth = $_GET['month'];
}
mysql_select_db($database_theGREENbar, $theGREENbar);
$query_recordEventsmonth = sprintf("SELECT * FROM wp_cgm_cal_entries WHERE FROM_UNIXTIME(start_date_time) = %s", GetSQLValueString($month_recordEventsmonth, "text"));
$recordEventsmonth = mysql_query($query_recordEventsmonth, $theGREENbar) or die(mysql_error());
$row_recordEventsmonth = mysql_fetch_assoc($recordEventsmonth);
$totalRows_recordEventsmonth = mysql_num_rows($recordEventsmonth);

Using
Code:
FROM_UNIXTIME(start_date_time, "%M")
did not work (however it works as a select statement in MySQL). Neither does what i have now. I need the timestamp to equal the month that is being passed in the url.

any help is appreciated.

thank you,

Darryn Cooke
| The New Orange County Graphic designer and Marketing and Advertising Consultant
| Marketing and Advertising blog
 
you forgot the quotes
Code:
$query_recordEventsmonth = sprintf("SELECT * FROM wp_cgm_cal_entries WHERE FROM_UNIXTIME(start_date_time) = [red]'[/red]%s[red]'[/red]", GetSQLValueString($month_recordEventsmonth, "text"));
$recordEventsmonth = mysql_query($query_recordEventsmonth, $theGREENbar) or die(mysql_error());
 
that gave me this error

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 'April''' at line 1

Darryn Cooke
| The New Orange County Graphic designer and Marketing and Advertising Consultant
| Marketing and Advertising blog
 
I figured it out

Code:
$colname_recordEventsmonth = "April";
if (isset($_GET['month'])) {
  $colname_recordEventsmonth = $_GET['month'];
}
mysql_select_db($database_theGREENbar, $theGREENbar);
$query_recordEventsmonth = sprintf("SELECT *, FROM_UNIXTIME(start_date_time, '%%M') AS month FROM wp_cgm_cal_entries WHERE FROM_UNIXTIME(start_date_time, '%%M') = %s", GetSQLValueString($colname_recordEventsmonth, "text"));
$recordEventsmonth = mysql_query($query_recordEventsmonth, $theGREENbar) or die(mysql_error());
$row_recordEventsmonth = mysql_fetch_assoc($recordEventsmonth);
$totalRows_recordEventsmonth = mysql_num_rows($recordEventsmonth);

Darryn Cooke
| The New Orange County Graphic designer and Marketing and Advertising Consultant
| Marketing and Advertising blog
 
unless getsqlvaluestring is a function that also enquotes variables, you will still need to enquote the %s.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top