Jump to content

mysql fetch data help


colmustard

Recommended Posts

Hi, I am able to fetch and display the data from the table, however I need a system where I can pick and choose which data to display. For example if a certain date is specified the loop needs to only pull out the data with the task_log_date that corresponds.

 

Currently it just loops through everything in the database, this is great but I only want to pull out data that is related to the current date.

 

Here is a snippet of my code. Any help is greatly appreciated!  ;)

 

$today = date("m/d/y");

$thistime=0;
$totaltime=0;
$query = "SELECT * FROM task_log WHERE `task_log_creator` = ".$creator." AND `task_log_date` >= '".$today."' ORDER BY task_log_date";

$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print title with links to go to that Item
while($row = mysql_fetch_object($result))
{
	echo '<tr>';
		echo '<td>'. $row->task_log_id . '</td>';
		echo '<td>'. $row->task_log_task . '</td>';
		echo '<td>'. $row->task_log_name . '</td>';
		$description = $row->task_log_description;
		echo '<td>'. nl2br($description) . '</td>';
		echo '<td>'. $row->task_log_hours . '</td>';
		echo '<td>'. $row->task_log_date . '</td>';
		echo '<td>'. $row->task_log_related_url . '</td>';
	echo '</tr>
	';
	$thistime = $row->task_log_hours;
	$totaltime = $totaltime + $thistime;
}
echo '<tr>';
	echo '<td> </td><td> </td><td> </td><td> </td>';
	echo '<td class="total">'. $totaltime .'</td>';
	echo '<td> </td><td> </td>';
echo '</tr>';

}

Link to comment
https://forums.phpfreaks.com/topic/208209-mysql-fetch-data-help/
Share on other sites

Not exactly sure, but my assumption is it's how you're formatting your date that it's confusing the WHERE clause.

 

Are you storing the dates in the table in the m/d/y format? I think the general way to do it is yyyy-mm-dd and MySQL might not know how to process it otherwise with the slashes in there.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.