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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.