473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Updating records

6
Thanks, it worked. Another problem:
Hey folks, where is the bug in this code? When updating the date field, it is updating all the records in the table with the same value (e.g. 2008-01-07) instead of incrementing the day by one in each record.
$schedule=position_courses($time_of_day);
$x=0;
$z=0;
$temp=0;
//getting the initial date
$date=set_date(7,1,2008,true);

foreach($schedule as $value)
{
$z++;
if($temp!=$value['day'])
{
$temp=$value['day'];
++$x;

if($x==5)
{
$x=0; //reseting the counter to 0
}
}
$day=$date['day'];
$month=$date['month'];
$year=$date['year'];
$day_name=$date['day_name'];
$full_date=$year.'-'.$month.'-'.$day;
if ($z!=1) $date=set_date($date['day'],$date['month'], $date['year'],false);

// Updating the date field in the table
$sql="UPDATE roomschedule SET date='$full_date'";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
Any help will be deeply appreciated. alexph@live.com
Jan 18 '08 #1
11 1857
dlite922
1,584 Expert 1GB
Be nice to the people who will help you, post your code using the [PHP ] and [/ PHP] around your code, to show us like this:


[PHP]
$schedule=position_courses($time_of_day);
$x=0;
$z=0;
$temp=0;
//getting the initial date
$date=set_date(7,1,2008,true);

foreach($schedule as $value)
{
$z++;

if($temp!=$value['day'])
{
$temp=$value['day'];

++$x;
if($x==5)
{
$x=0; //reseting the counter to 0
}
}

$day=$date['day'];
$month=$date['month'];
$year=$date['year'];
$day_name=$date['day_name'];
$full_date=$year.'-'.$month.'-'.$day;

if ($z!=1)
{
$date=set_date($date['day'],$date['month'], $date['year'],false);
}

// Updating the date field in the table
$sql="UPDATE roomschedule SET date='$full_date'";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}// <--- bracket was missing?

[/PHP]

now let me read it to see if i can help.....
Jan 18 '08 #2
dlite922
1,584 Expert 1GB
In your Update you don't set which record to update, i.e. no WHERE clause.

UPDATE tablename SET fieldName = "fieldValue" WHERE $foo = 'bar';

MySQL by default sets every row to that value.
Jan 18 '08 #3
xelA
6
I did that. It is still updating all the records with same value (2008-01-07). No increment in date. What do I do? Please Help...
Jan 23 '08 #4
Purple
404 Expert 256MB
Hi xelA

Can you post your updated code and ideally don't forget the code tags.

Purple
Jan 23 '08 #5
xelA
6
Hi xelA

Can you post your updated code and ideally don't forget the code tags.

Purple
Here is my code.
(PHP)
<?php
require_once 'scheduler.php';
include 'generate_date.php';

draw_schedule();
function clear_existing_schedule()
{
//deleting existing contents to avoid duplication
$sql="DELETE FROM roomschedule";
mysql_query($sql);
}
function sechudle_courses()
{
//instantiate a course object
$course=new course();
$roomSchecdule=new roomSchedule();
//getDistinctCourses
$courses=$course->getDistinctCourses();

//deleting existing contents to avoid duplication
clear_existing_schedule();
$start=1;
foreach($courses as $value)
{
$numberOfStudents=$course->getNumberOfStudents($value);
$year_of_study=$course->getYearOfStudy($value);
if($year_of_study%2==1)$morning=1;else $morning=0;
$start=$roomSchecdule->updateRoomSchedule($value,$start,$morning,$number OfStudents);
}
}
function position_courses($time_of_day)
{
$roomSchecdule=new roomSchedule();
$course=new course();
$roomSchecdule->sheduleDays($time_of_day);
$days=$roomSchecdule->printDays($time_of_day);
$max=count($days);
$array_value=0;
$courses=$course->getDistinctCourses();
for($i=0;$i<$max;$i++)
{
$course_code=$days[$i][0];
$day_number=$days[$i][1];
if($day_number>$array_value)
{
$array_value++;
}
$numberOfStudents=$course->getNumberOfStudents($course_code);
$class_room=$roomSchecdule->get_classroom($course_code);
$schedule[$i]['day']=$array_value;
$schedule[$i]['course_code']=$course_code;
$schedule[$i]['room']= $class_room;
$schedule[$i]['number_of_students']=$numberOfStudents;
}
return $schedule;

}
function draw_schedule()
{
sechudle_courses();
for($i=0;$i<=1;$i++)
{
if($i==0)
{
$time_of_day='morning';
echo '<h4>MORNING SESSIONS (09:00HRS)</h4>';
}
else
{
$time_of_day='afternoon';
echo '<h4>AFTERNOON SESSIONS (14:00 HRS)</h4>';
}

$schedule=position_courses($time_of_day);
$x=0;
$z=0;
$temp=0; //a temporary variable for checking if the value of the date is greater or less
echo '<table border="1">';
echo '<tr><th>Day</th><th>Course Code</th><th>Venue</th><th>No of
Students</th><th>Date</th></tr>';

//get the starting date
$date=set_date(7,1,2008,true);
foreach($schedule as $value)
{
$z++;
if($temp!=$value['day'])
{
$temp=$value['day'];
++$x;
if($x==5)
{
$x=0; //reseting the counter to 0
}
}
$day=$date['day'];
$month=$date['month'];
$year=$date['year'];
$day_name=$date['day_name'];
$full_date=$year.'-'.$month.'-'.$day;
if ($z!=1) $date=set_date($date['day'],$date['month'], $date['year'],false);
$sql="UPDATE roomschedule SET date='$full_date' WHERE date='$full_date'";
mysql_query($sql);

echo'<tr><td>'.$day_name.'</td><td>'.$value['course_code'].'</td><td>'.$value['room'].'</td><td>'.$value['number_of_students'].'</td><td>'.$full_date.'</td></tr>';
}
echo '</table>';
}
}
?>
Jan 28 '08 #6
dlite922
1,584 Expert 1GB
Here is my code.
(PHP)
<?php
require_once 'scheduler.php';
include 'generate_date.php';

draw_schedule();
function clear_existing_schedule()
{
//deleting existing contents to avoid duplication
$sql="DELETE FROM roomschedule";
mysql_query($sql);
}
function sechudle_courses()
{
//instantiate a course object
$course=new course();
$roomSchecdule=new roomSchedule();
//getDistinctCourses
$courses=$course->getDistinctCourses();

//deleting existing contents to avoid duplication
clear_existing_schedule();
$start=1;
foreach($courses as $value)
{
$numberOfStudents=$course->getNumberOfStudents($value);
$year_of_study=$course->getYearOfStudy($value);
if($year_of_study%2==1)$morning=1;else $morning=0;
$start=$roomSchecdule->updateRoomSchedule($value,$start,$morning,$number OfStudents);
}
}
function position_courses($time_of_day)
{
$roomSchecdule=new roomSchedule();
$course=new course();
$roomSchecdule->sheduleDays($time_of_day);
$days=$roomSchecdule->printDays($time_of_day);
$max=count($days);
$array_value=0;
$courses=$course->getDistinctCourses();
for($i=0;$i<$max;$i++)
{
$course_code=$days[$i][0];
$day_number=$days[$i][1];
if($day_number>$array_value)
{
$array_value++;
}
$numberOfStudents=$course->getNumberOfStudents($course_code);
$class_room=$roomSchecdule->get_classroom($course_code);
$schedule[$i]['day']=$array_value;
$schedule[$i]['course_code']=$course_code;
$schedule[$i]['room']= $class_room;
$schedule[$i]['number_of_students']=$numberOfStudents;
}
return $schedule;

}
function draw_schedule()
{
sechudle_courses();
for($i=0;$i<=1;$i++)
{
if($i==0)
{
$time_of_day='morning';
echo '<h4>MORNING SESSIONS (09:00HRS)</h4>';
}
else
{
$time_of_day='afternoon';
echo '<h4>AFTERNOON SESSIONS (14:00 HRS)</h4>';
}

$schedule=position_courses($time_of_day);
$x=0;
$z=0;
$temp=0; //a temporary variable for checking if the value of the date is greater or less
echo '<table border="1">';
echo '<tr><th>Day</th><th>Course Code</th><th>Venue</th><th>No of
Students</th><th>Date</th></tr>';

//get the starting date
$date=set_date(7,1,2008,true);
foreach($schedule as $value)
{
$z++;
if($temp!=$value['day'])
{
$temp=$value['day'];
++$x;
if($x==5)
{
$x=0; //reseting the counter to 0
}
}
$day=$date['day'];
$month=$date['month'];
$year=$date['year'];
$day_name=$date['day_name'];
$full_date=$year.'-'.$month.'-'.$day;
if ($z!=1) $date=set_date($date['day'],$date['month'], $date['year'],false);
$sql="UPDATE roomschedule SET date='$full_date' WHERE date='$full_date'";
mysql_query($sql);

echo'<tr><td>'.$day_name.'</td><td>'.$value['course_code'].'</td><td>'.$value['room'].'</td><td>'.$value['number_of_students'].'</td><td>'.$full_date.'</td></tr>';
}
echo '</table>';
}
}
?>
before mysql_query($sql), write

die($sql);

paste this into mysql command line (if the error is not obvious by looking at it) and mysql will show you that query is executing the way it is.
Jan 29 '08 #7
xelA
6
Please don't be annoyed with me. I just need your help. After doing that, it is giving me the following error msg:

UPDATE roomschedule SET date='2008-01-07' WHERE date='2008-01-07'

If I echo full_date, it is showing me want I anticipate. The problem comes when entering the date in the table. It is failing to update the date field.
Jan 31 '08 #8
Markus
6,050 Expert 4TB

Please read the forum guidelines


And post the code again with the proper code tags.
Jan 31 '08 #9
xelA
6

Please read the forum guidelines


And post the code again with the proper code tags.
Thanks for your concern. But why should I post my code again?
Feb 1 '08 #10
Markus
6,050 Expert 4TB
Because people will just neglect to read your code if you haven't used code tags. Therefore, you not getting an answer.

Until a mod (few and far between) changed it, you'll have to repost it.

Or not.

Just remember to use proper code tags :)
Feb 1 '08 #11
dlite922
1,584 Expert 1GB
Oh for crying out loud:

[PHP]
<?php
require_once 'scheduler.php';
include 'generate_date.php';

draw_schedule();
function clear_existing_schedule()
{
//deleting existing contents to avoid duplication
$sql="DELETE FROM roomschedule";
mysql_query($sql);
}
function sechudle_courses()
{
//instantiate a course object
$course=new course();
$roomSchecdule=new roomSchedule();
//getDistinctCourses
$courses=$course->getDistinctCourses();

//deleting existing contents to avoid duplication
clear_existing_schedule();
$start=1;
foreach($courses as $value)
{
$numberOfStudents=$course->getNumberOfStudents($value);
$year_of_study=$course->getYearOfStudy($value);
if($year_of_study%2==1)$morning=1;else $morning=0;
$start=$roomSchecdule->updateRoomSchedule($value,$start,$morning,$number O fStudents);
}
}
function position_courses($time_of_day)
{
$roomSchecdule=new roomSchedule();
$course=new course();
$roomSchecdule->sheduleDays($time_of_day);
$days=$roomSchecdule->printDays($time_of_day);
$max=count($days);
$array_value=0;
$courses=$course->getDistinctCourses();
for($i=0;$i<$max;$i++)
{
$course_code=$days[$i][0];
$day_number=$days[$i][1];
if($day_number>$array_value)
{
$array_value++;
}
$numberOfStudents=$course->getNumberOfStudents($course_code);
$class_room=$roomSchecdule->get_classroom($course_code);
$schedule[$i]['day']=$array_value;
$schedule[$i]['course_code']=$course_code;
$schedule[$i]['room']= $class_room;
$schedule[$i]['number_of_students']=$numberOfStudents;
}
return $schedule;

}
function draw_schedule()
{
sechudle_courses();
for($i=0;$i<=1;$i++)
{
if($i==0)
{
$time_of_day='morning';
echo '<h4>MORNING SESSIONS (09:00HRS)</h4>';
}
else
{
$time_of_day='afternoon';
echo '<h4>AFTERNOON SESSIONS (14:00 HRS)</h4>';
}

$schedule=position_courses($time_of_day);
$x=0;
$z=0;
$temp=0; //a temporary variable for checking if the value of the date is greater or less
echo '<table border="1">';
echo '<tr><th>Day</th><th>Course Code</th><th>Venue</th><th>No of
Students</th><th>Date</th></tr>';

//get the starting date
$date=set_date(7,1,2008,true);
foreach($schedule as $value)
{
$z++;
if($temp!=$value['day'])
{
$temp=$value['day'];
++$x;
if($x==5)
{
$x=0; //reseting the counter to 0
}
}
$day=$date['day'];
$month=$date['month'];
$year=$date['year'];
$day_name=$date['day_name'];
$full_date=$year.'-'.$month.'-'.$day;
if ($z!=1) $date=set_date($date['day'],$date['month'], $date['year'],false);
$sql="UPDATE roomschedule SET date='$full_date' WHERE date='$full_date'";
mysql_query($sql);

echo'<tr><td>'.$day_name.'</td><td>'.$value['course_code'].'</td><td>'.$value['room'].'</td><td>'.$value['number_of_students'].'</td><td>'.$full_date.'</td></tr>';
}
echo '</table>';
}
}
?>


[/PHP]
Feb 14 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
1
by: Chris Jackson | last post by:
I'm a novice Access user and am not sure how to solve the following problem. Any help with the following would be greatly appreciated! I have two tables with identical structures, the first holds...
0
by: | last post by:
I am updating MS access tables with data in an xml document. I create two dataset, one for existing data and one for new data. I fill the first dataset with the records from MS Access, the second...
1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
1
by: davidgordon | last post by:
Hi, If I am updating a list of records for a user on an asp page, is there a way to hold the page updating, even if they refresh the page, until I have updated all the records. i.e. rather...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
2
by: Alexey.Murin | last post by:
The application we are developing uses MS Access 2003 database (with help of ADO). We have noticed that during massive records updating the size of the mdb file increases dramatically (from 3-4 to...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
5
by: Bill Schanks | last post by:
I have a winform app (VB 2005) that allows users to export data to excel, make updates to the excel file and import the data from that Excel file and update the database. My question is: Is it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.