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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Days of Month in rows 1

Status
Not open for further replies.

pastorandy

IS-IT--Management
Nov 2, 2006
84
GB
Hi
I have an application that lists rows of jobs by date.
What I'd like to do is list them in the same manner but to have a row shown if there is no job on that date but to still have the date displayed at the beginning of the row so that it can be quickly seen that a job can be added in for that day.

Any ideas?
 
JP
I'm having trouble working out how I reference job_id in my included files now.

it's giving me an error in my included file query which presumably is because I have currently got this..
>>>
$query4 = "SELECT * from job
WHERE job_id = $row[job_id]
<<< ";
 
yes. but always enquote your array keys.
Code:
$row['job_id']

although this is technically optional if the array element is referenced itself within double quotes

Code:
$row['job_id'] ="something";
echo "Someone is $row[job_id]"; //is ok

 
JP
still giving me error in this query in the included file
>>$query4 = "SELECT * from job
WHERE job_id = $row[job_id]
";

$result4 = mysql_query($query4) or die ("error in result4");
<<<
 
what is the code you are now using?

and instead of the error trapping you are using try this instead:

Code:
$result4 = mysql_query($query4) or die ("error in result4<br/>Query was: $query4<br/>Error was: ". mysql_error());
 
JP
Thanks for taking the time to help with this - it's much appreciated.

>>>
error in result4
Query was: SELECT * from job WHERE job_id =
Error was: You have an error in your SQL syntax near '' at line 3
<<<
 
so the job id is not being passed.

have you changed the query as mentioned? it should now look like:
Code:
$query= "
			SELECT 
				job_colour,
				job_date,
				job_time_slot,
				cust_surname,
				job_desc,
				job_location,
				job_type,
				job_id
			from 
				job
			WHERE 
				job_completed = 'No'
			ORDER BY 
				job_date asc";
 
i'm stuck without your code. is it too long to post here?
 
no I'm not. I'm just being stupid. revised code to come in a second.
 
it was a variable scope problem. this should solve it

Code:
<?
$query= "
			SELECT 
				job_colour,
				job_date,
				job_time_slot,
				cust_surname,
				job_desc,
				job_location,
				job_type,
				job_id
			from 
				job
			WHERE 
				job_completed = 'No'
			ORDER BY 
				job_date asc";

$result = mysql_query($query);
$jobs = array();
while ($row = mysql_fetch_assoc($result)){
	$tmp = $row;
	unset($tmp[job_date]);
	$jobs[$row['job_date']][]=$tmp;
}

$dates = array_keys($jobs);
if (count($dates) === 0){
$curDate = $end = time();
} else {
	$curDate = strtotime($dates[0]);
	$end = strtotime($dates[count($dates)-1]);
}
$dates = null;

echo <<<HTML
<table>
	<tr>
		<th align="center">Status</th>
		<th align="center">Job Date</th>
		<th align="left">Time Slot</th>
		<th align="left">Customer</th>
		<th align="left">Desc</th>
		<th align="left">Location</th>
		<th align="center">Type</th>
		<th align="center">Allocated</th>
		<th align="center">Free</th>
		<th align="center">Actions</th>
	</tr>

HTML;

$style = "style1";
while ($curDate <= $end){
	$displayDate = date ("Y-m-d", $curDate);
	if (isset($jobs[$displayDate])){
		$curJobs = $jobs[$displayDate];
	}else{
		$curJobs[0]['job_colour'] =
		$curJobs[0]['job_time_slot'] =
		$curJobs[0]['cust_surname'] =
		$curJobs[0]['job_desc'] =
		$curJobs[0]['job_location'] =
		$curJobs[0]['job_type'] = 
		$allocation = 
		$free = " ";
	}
	foreach ($curJobs as $job){
		$allocation = getContent("installer.php", $job);
		$free = getContent("free.php", $job);
		echo <<<HTML
	<tr class="$style">
		<td>{$job['job_colour']}</td>
		<td>$displayDate</td>
		<td>{$job['job_time_slot']}</td>
		<td>{$job['cust_surname']}</td>
		<td>{$job['job_desc']}</td>
		<td>{$job['job_location']}</td>
		<td>{$job['job_type']}</td>
		<td>$allocation</td>
		<td>$free</td>
		<td>PUT SOME BUTTONS HERE</td>
	</tr>

HTML;
	} //end of foreach loop
	$style = ($style=="style1") ? "style2" : "style1";
	$curDate = strtotime("+1 day", $curDate);
} //end of while loop

echo "</table>";

function getContent($file, $row){
	ob_start();
	include $file;
	$contents = ob_get_contents();
	ob_end_clean();
	return $contents;
}
?>
 
Jp
It takes a while to bring the results back now and it seems to repeat them. But I don't want to waist anymore of your time with this.
 
try without the includes to see whether that makes a material difference. I suspect this is where the issue is, if you have 1200 lines processing the output for two columns in each row. there is almost certainly a better way to do what you are looking for.

The easiest way for you to dummy out the includes is by changing the getContent function as follows

Code:
function getContent($file, $row){
    [red]return "";[/red]
    ob_start();
    include $file;
    $contents = ob_get_contents();
    ob_end_clean();
    return $contents;
}

as for the repetitions, i can't see any reason why it would repeat unless there was a repetition in the database. it's very difficult to debug without your full code and sample data.


 
I didn't realise you were from the UK - what on earth are you doing on your computer at 10:45pm Friday night?
 
ok - just read your profile.

As for my bulky code - that's probably about right. I'm not a brilliant coder but am learning as I go along. This part of the system that I am developing is pretty tough from my understanding but is probably easy to do for a PHP expert.

Can I send you an email with a login so that you can see what I am trying to do?
 
feel free to upload your code (zipped) and db schema +sample data to me. or provide a login (put in a text file and upload)

I provide an upload mechanism for tek-tips contacts as we are not allowed to publish email addresses in the forum. the uploader is at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top