Jump to content

Help needed on how to display data in columns


mrtds

Recommended Posts

Hi,

 

I am trying to develop a system which would let the shop owner to schedule rota online and let staff check the rota online. I was wandering on what would be the code to get the data displayed in columns, not rows so that all the rows from MySQL database would be displayed in columns. Also I need to build an administration where every single cell could be edited or deleted. As well as new columns added for new employees.


<?php
require_once '../config.php';

mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect. ' . mysql_error());
mysql_select_db(DB_NAME) or die('Could not select database. ' . mysql_error());

$data = mysql_query("SELECT COUNT(*) FROM date") or die(mysql_error()); 
$rows = mysql_fetch_row($data);
$numrows = $rows[0];

$result = mysql_query("SELECT * FROM date");
echo '<table border="0px" cellpadding="3px" style="font:normal 10px Verdana, Helvetica, Arial; border:0px solid #bfbfbf; border-collapse: collapse;">';
echo "<tr>
	<th></th>
	<th>Mon</th>
	<th>Tue</th>
	<th>Wed</th>
	<th>Thu</th>
	<th>Fri</th>
	<th>Sat</th>
	<th>Sun</th>
	<th>Mon</th>
	<th>Tue</th>
	<th>Wed</th>
	<th>Thu</th>
	<th>Fri</th>
	<th>Sat</th>
	<th>Sun</th>
	<th>Mon</th>
	<th>Tue</th>
	<th>Wed</th>
	<th>Thu</th>
	<th>Fri</th>
	<th>Sat</th>
	<th>Sun</th>
	<th>Mon</th>
	<th>Tue</th>
	<th>Wed</th>
	<th>Thu</th>
	<th>Fri</th>
	<th>Sat</th>
	<th>Sun</th>
	</tr>";

while ($row = mysql_fetch_array($result)) {
	$name = $row['Name'];
	$mon1 = $row['Mon1'];
	$tue1 = $row['Tue1'];
	$wed1 = $row['Wed1'];
	$thu1 = $row['Thu1'];
	$fri1 = $row['Fri1'];
	$sat1 = $row['Sat1'];
	$sun1 = $row['Sun1'];
	$mon2 = $row['Mon2'];
	$tue2 = $row['Tue2'];
	$wed2 = $row['Wed2'];
	$thu2 = $row['Thu2'];
	$fri2 = $row['Fri2'];
	$sat2 = $row['Sat2'];
	$sun2 = $row['Sun2'];
	$mon3 = $row['Mon3'];
	$tue3 = $row['Tue3'];
	$wed3 = $row['Wed3'];
	$thu3 = $row['Thu3'];
	$fri3 = $row['Fri3'];
	$sat3 = $row['Sat3'];
	$sun3 = $row['Sun3'];
	$mon4 = $row['Mon4'];
	$tue4 = $row['Tue4'];
	$wed4 = $row['Wed4'];
	$thu4 = $row['Thu4'];
	$fri4 = $row['Fri4'];
	$sat4 = $row['Sat4'];
	$sun4 = $row['Sun4'];
echo "<form action='save_rota.php'  method='post' enctype='multipart/form-data'>";

echo "<tr bgcolor=#FFFFFF onMouseover=this.bgColor='#ff3300'; onMouseout=this.bgColor='#FFFFFF'>
		<td><input name='name' id='name' type='text' size='1' value=$name></td>
		<td><input name='mon1' id='mon1' type='text' size='1' value=$mon1></td>
		<td><input name='tue1' id='tue1' type='text' size='1' value=$tue1></td>
		<td><input name='wed1' id='wed1' type='text' size='1' value=$wed1></td>
		<td><input name='thu1' id='thu1' type='text' size='1' value=$thu1></td>
		<td><input name='fri1' id='fri1' type='text' size='1' value=$fri1></td>
		<td><input name='sat1' id='sat1' type='text' size='1' value=$sat1></td>
		<td><input name='sun1' id='sun1' type='text' size='1' value=$sun1></td>
		<td><input name='mon2' id='mon2' type='text' size='1' value=$mon2></td>
		<td><input name='tue2' id='tue2' type='text' size='1' value=$tue2></td>
		<td><input name='wed2' id='wed2' type='text' size='1' value=$wed2></td>
		<td><input name='thu2' id='thu2' type='text' size='1' value=$thu2></td>
		<td><input name='fri2' id='fri2' type='text' size='1' value=$fri2></td>
		<td><input name='sat2' id='sat2' type='text' size='1' value=$sat2></td>
		<td><input name='sun2' id='sun2' type='text' size='1' value=$sun2></td>
		<td><input name='mon3' id='mon3' type='text' size='1' value=$mon3></td>
		<td><input name='tue3' id='tue3' type='text' size='1' value=$tue3></td>
		<td><input name='wed3' id='wed3' type='text' size='1' value=$wed3></td>
		<td><input name='thu3' id='thu3' type='text' size='1' value=$thu3></td>
		<td><input name='fri3' id='fri3' type='text' size='1' value=$fri3></td>
		<td><input name='sat3' id='sat3' type='text' size='1' value=$sat3></td>
		<td><input name='sun3' id='sun3' type='text' size='1' value=$sun3></td>
		<td><input name='mon4' id='mon4' type='text' size='1' value=$mon4></td>
		<td><input name='tue4' id='tue4' type='text' size='1' value=$tue4></td>
		<td><input name='wed4' id='wed4' type='text' size='1' value=$wed4></td>
		<td><input name='thu4' id='thu4' type='text' size='1' value=$thu4></td>
		<td><input name='fri4' id='fri4' type='text' size='1' value=$fri4></td>
		<td><input name='sat4' id='sat4' type='text' size='1' value=$sat4></td>
		<td><input name='sun4' id='sun4' type='text' size='1' value=$sun4></td>
	</tr>";
}
echo "</table>";
echo "<input style='height: 25px; width: 200px' type='submit' value='Save' /></form>";

?>

This is what I came up so far. It's very messy, but I am looking to clean it up. However it's not really what I need, as it adds new row from database and I need it to add a new column. Also it lets me edit only the last line.

 

Here is the update script:


<?php
require_once '../config.php';

mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect. ' . mysql_error());
mysql_select_db(DB_NAME) or die('Could not select database. ' . mysql_error());

$name = $_POST['name'];
$mon1 = $_POST['mon1'];
$tue1 = $_POST['tue1'];
$wed1 = $_POST['wed1'];
$thu1 = $_POST['thu1'];
$fri1 = $_POST['fri1'];
$sat1 = $_POST['sat1'];
$sun1 = $_POST['sun1'];
$mon2 = $_POST['mon2'];
$tue2 = $_POST['tue2'];
$wed2 = $_POST['wed2'];
$thu2 = $_POST['thu2'];
$fri2 = $_POST['fri2'];
$sat2 = $_POST['sat2'];
$sun2 = $_POST['sun2'];
$mon3 = $_POST['mon3'];
$tue3 = $_POST['tue3'];
$wed3 = $_POST['wed3'];
$thu3 = $_POST['thu3'];
$fri3 = $_POST['fri3'];
$sat3 = $_POST['sat3'];
$sun3 = $_POST['sun3'];
$mon4 = $_POST['mon4'];
$tue4 = $_POST['tue4'];
$wed4 = $_POST['wed4'];
$thu4 = $_POST['thu4'];
$fri4 = $_POST['fri4'];
$sat4 = $_POST['sat4'];
$sun4 = $_POST['sun4'];

mysql_query("UPDATE date SET name='$name', mon1='$mon1', tue1='$tue1', wed1='$wed1', thu1='$thu1', fri1='$fri1', sat1='$sat1', sun1='$sun1' WHERE name='$name'");
header('location: index.php');
echo '<p>EDITED</p>';
?>

 

If anyone could shed some light for a beginner I would be very grateful.

 

Thank you.

 

 

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.