Objected Oriented or not!! can someone help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Everah wrote:The only OOP in there is the $row var being set to mysql_fetch_object. Other than that, it is all procedural.
And $row is simply being used as a struct so there is zero OO going on -- and I doubt there was much OO in the "ASP" version as well. I would not even elevate it to the level of calling it Structured Programming.
(#10850)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

arborint wrote:
Everah wrote:The only OOP in there is the $row var being set to mysql_fetch_object. Other than that, it is all procedural.
And $row is simply being used as a struct so there is zero OO going on -- and I doubt there was much OO in the "ASP" version as well. I would not even elevate it to the level of calling it Structured Programming.
I'm tempted to slightly disagree, but not much.

Many of the properties of $row imply an person/user object - it has a city, address, phone, etc. Unfortunately for the original poster, that object is poorly defined. It doesn't have any behaviors for acting on the object (add_email? change_phone?), and thus lacks encapsulation.

Where I would argue against the statement that there is "zero OO going on", is that I see a strong Object model being presented. Its clear that there *is* an object - the user/person. Its also clear that the application 'wants' to display, modify, and update those objects. Put another way, its procedural code that has a strong OOP smell to it. It could go OOP very easily, and probably would be more effective if it did.

Compare with something like a email validation class, which is almost entirely procedural, and has little if any object behavior, and hopefully you see the difference justifying that there is "more than zero OO going on".

But I stress, not much. Personally, I'd describe the code as procedural, and in need of an OOP revamp.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Roja wrote:Many of the properties of $row imply an person/user object - it has a city, address, phone, etc. Unfortunately for the original poster, that object is poorly defined. It doesn't have any behaviors for acting on the object (add_email? change_phone?), and thus lacks encapsulation.

Where I would argue against the statement that there is "zero OO going on", is that I see a strong Object model being presented. Its clear that there *is* an object - the user/person. Its also clear that the application 'wants' to display, modify, and update those objects. Put another way, its procedural code that has a strong OOP smell to it. It could go OOP very easily, and probably would be more effective if it did.
I disagree. There is nothing about $row that is an object other than some idea that the data in the structure may be related in some way. There are a even bunch of values at the end that look like they should probably be in separate tables. Maybe Active Record would be more appropriate. If you changed $row to an array there would be zero effect on this scripts design -- just some renaming.
(#10850)
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

That was only some of my code.

I have a fullyworking system which is currently being used by an organisation to manage all thier contctas, i.e updating details, editing records each record linking to the contacts email address and organisations website.

heres some more code to edit records, the way Ihave arranged the code was to enable me to have 'pagination' you can select the number of records you wnat to view per page and then previous next links take you through.

I also have a search facility which allows you to search for particular records.

Anymore views?


edit records

Code: Select all

?php include "dyn.header"; ?>
<!-- Please don't remove these comments -->
<!-- Content Start -->
<h1>Edit People</h1>
<p>
<strong><font size="4">Change Details</font></strong><br>
<A HREF="people.html"><CENTER>Back to People</CENTER></A>

<?php
		
/* Connecting, selecting database */
$link = mysql_connect("vxxxxx", "xxxx", "0xxxxxx")
   or die("Could not connect : " . mysql_error());
echo "";
mysql_select_db("contact_management_system") or die("Could not select database");
	
		if(isset($_GET['person_id'])){
			$person_id=$_GET['person_id'];
		}

		if ($_POST['Submit'] == 'Save'){

			foreach ($_POST as $formName => $phpName){
				$$formName = $phpName;
			}
			
					 $sql ="UPDATE people SET "
					. " salutation='"	.$salutation."'," 
					. " firstname='"	.$firstname	."'," 
					. " surname='"		.$surname."'," 
					. " organisation='" .$organisation	."'," 
					. " role='"			.$role."'," 
					. " address1='"	.	$address1."'," 
					. " address2='" .$address2."'," 
					. " city='" .$city."'," 
					. " telephone='" .$telephone."'," 
					. " mobile='" .	$mobile	."'," 
					. " fax='" .$fax."'," 
					. " dateoflastcontact='" .$dateoflastcontact."',"
					. " datecontactagain='" .$datecontactagain."',"
					. " notes='" .$notes."',"
					. " email='" .$email."',"
					. " org_id='" .	$org_id	."',"
					. " consultation_panel_member='" .	$consultation_panel_member	."',"
					. " primary_contact='" .	$primary_contact	."',"
					. " primarycontactemail='" .	$primarycontactemail	."',"
					. " advertising_grad_jobs='" .	$advertising_grad_jobs	."',"
					. " offer_mscproject='" .	$offer_mscproject	."',"
					. " offer_ugproject='" .	$offer_ugproject	."',"
					. " professional_devactivities='" .	$professional_devactivities	."',"
					. " bcs_membership='" .	$bcs_membership	."',"
					. " bcs_pds='" .	$bcs_pds	."',"
					. " teaching_courses='" .	$teaching_courses	."',"
					. " academic_consultancy='" .	$academic_consultancy	."',"
					. " employer_feedback='"	. $employer_feedback."'"
					. " WHERE person_id='" . $person_id."'";

			echo "<br><div align=center><br>";
			mysql_query($sql) or die('could not insert' . mysql_error());

			echo  "		<div align=left><table width=70% border=1 cellpadding=10 align=center>"
				. "		<tr>"
				. "			<td width=40%>"
				. "					<font face=arial size=2><b>"
				. "					Salutation"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $salutation . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Firstname"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $firstname . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Surname"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $surname . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Organisation"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $organisation . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Role"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $role . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Address 1"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $address1 . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Address 2"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $address2 . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					City"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $city . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Postcode"
				. "					</font>"
				. "				</td>"
				. "					<td>"
				. "					<font face=arial size=2>"
				. "					" . $postcode . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "						Telephone"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $telephone . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Mobile"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $mobile . "</font>"
				. "				</td>"
				. "			</tr>"
				."			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Fax"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $fax . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Last Contact"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $dateoflastcontact . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Contact Again"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $datecontactagain . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					E-mail"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $email . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"


				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					OID"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $org_id . "</font>"
				. "				</td>"
				. "			</tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Consultation Panel"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $consultation_panel_member . "</font>"
				. "				</td>"
				. "			</tr>"
	
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Primary Contact"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $primary_contact . "</font>"
				. "				</td>"
				. "			</tr>"

				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Primary Contact E-mail"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $primarycontactemail . "</font>"
				. "				</td>"
				. "			</tr>"
				
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Employer Feedback"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $employer_feedback . "</font>"
				. "				</td>"
				. "			</tr>"
				





		
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Graduate Jobs"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $advertising_grad_jobs . "</font>"
				. "				</td>"
				. "			</tr>"
				

				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					MSC Projects"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $offer_mscproject . "</font>"
				. "				</td>"
				. "			</tr>"
				

				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					UG Project"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $offer_ugproject . "</font>"
				. "				</td>"
				. "			</tr>"
				

				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Professional Developement"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $professional_devactivities . "</font>"
				. "				</td>"
				. "			</tr>"
				


				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					BCS Membership"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $bcs_membership . "</font>"
				. "				</td>"
				. "			</tr>"
				


				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					BCS PDS"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $bcs_pds . "</font>"
				. "				</td>"
				. "			</tr>"
				
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Teaching Courses"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $teaching_courses . "</font>"
				. "				</td>"
				. "			</tr>"
				
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					Academic Consultancy"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $academic_consultancy . "</font>"
				. "				</td>"
				. "			</tr>"
				







				. "		</table>"; 
		}
		
		$sql = "SELECT * FROM people WHERE person_id='" . $person_id . "'";
			//echo "<br><div align=center>" . $sql . "<br>";
			echo "<br><div align=center><br>";
			$memb = mysql_query($sql) or die(mysql_error());
			$row = mysql_fetch_array($memb);

			echo  "\n"
				. "		</div>\n"
				. "		<form name=form2 method=post action=editpeople.html?person_id=" . $person_id . ">\n"
				. "			<table width=70% border=1 cellpadding=10 align=center>\n" 
				. "				<tr>\n"
				. "					<td width=40%>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Salutation\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=salutation type=text id=salutation value='" . $row['salutation'] . "'></font>\n"
				. "				<tr>\n"
				. "					<td width=40%>\n"
				. "						<font face=arial size=2><b>\n"
				. "						First Name\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=firstname type=text id=firstname value='" . $row['firstname'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Surname\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=surname type=text id=surname value='" . $row['surname'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Organisation\n"
				. "						</font>\n"
				. "						</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=organisation type=text id=organsation value='" . $row['organisation'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Role \n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=role type=text id=role value='" . 
				$row['role']		. "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Address (1)\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=address1 type=text id=address1 value='" . $row['address1'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Address(2)\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=address2 type=text id=address2 value='" . $row['address2'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						City\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=city type=text id=city value='" . 
				$row['city']	. "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Postcode\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=postcode type=text id=postcode value='" . $row['postcode'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Telephone\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=telephone type=text id=telephone value='" . $row['telephone'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Mobile\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=mobile type=text id=mobile value='" . 
				$row['mobile'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Fax\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=fax type=text id=fax value='" . 
				$row['fax'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Last Contact\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=dateoflastcontact type=text id=dateoflastcontact 								value='" . 
				$row['dateoflastcontact'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Contact Again\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=datecontactagain type=text id=datecontactagain 									value='" . 
				$row['datecontactagain'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						E-mail\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=email type=text id=email value='" . 
				$row['email'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						OID\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=org_id type=text id=org_id value='" . $row['org_id'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"

				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					Consultation Panel\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=consultation_panel_member type=text id=consultation_panel_member 
				value= ' ". $row['consultation_panel_member'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"

				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					Primary Contact\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=primary_contact type=text id=primary_contact 
				value= ' ". $row['primary_contact'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"

				
				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					Primary Contact E-mail\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=primarycontactemail type=text id=primarycontactemail 
				value= ' ". $row['primarycontactemail'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"




				
				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					Employer Feedback\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=employer_feedback type=text id=employer_feedback 
				value= ' ". $row['employer_feedback'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"


				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					Graduate Jobs\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=advertising_grad_jobs type=text id=advertising_grad_jobs 
				value= ' ". $row['advertising_grad_jobs'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					MSC Project\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=offer_mscproject type=text id=offer_mscproject
				value= ' ". $row['offer_mscproject'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"

				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					UG Project\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=offer_ugproject type=text id=offer_ugproject
				value= ' ". $row['offer_ugproject'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"


				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					Professional Dev.\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=professional_devactivities type=text id=professional_devactivities
				value= ' ". $row['professional_devactivities'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"

				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					BCS Membership\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=bcs_membership type=text id=bcs_membership
				value= ' ". $row['bcs_membership'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					BCS PDS\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=bcs_membership type=text id=bcs_membership
				value= ' ". $row['bcs_pds'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"


				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					Teaching Courses\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=teaching_courses type=text id=teaching_courses
				value= ' ". $row['teaching_courses'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"


				. "				<tr>\n"
				. "					<td>\n"
				. "					<font face=arial size=2><b>\n"
				. "					Academic Consultancy\n"
				. "					</font>\n"
				. "						</td>\n"
				. "						<td>\n"
				. "						<font face=arial size=2>\n"
				. "	<input name=academic_consultancy type=text id=academic_consultancy
				value= ' ". $row['academic_consultancy'] . "'></font>\n"
				. "											</td>\n"
				. "											</tr>\n"


				


				
				. "				<tr>\n"
				. "					<td colspan=2>\n"
				. "						&nbsp\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td colspan=2 align=center>\n"
				. "						<input type=reset name=Reset value=Cancel>\n"
				. "						<input type=submit name=Submit
				value=Save>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "			</table>\n"
				. "		</form>\n";
	//	}
		
		
			if ($_POST['action'] == "Delete Record"){
$delete = mysql_query("DELETE FROM people WHERE person_id = '$person_id'") or die(mysql_error()); }

echo "<form action=\"editpeople.html?person_id=$person_id\" method=\"post\">
<input type=\"hidden\" name=\"action\" value=\"Delete Record\">
<input type=\"submit\" value=\"Delete Record\">
</form>

        </td><p>";

?>

<p>
<!-- Content End   -->
<!-- Please don't remove these comments -->
<?php include "dyn.footer"; ?>


and heres one example of a search code I have a number of these

Code: Select all

<?php include "dyn.header"; ?>
<!-- Please don't remove these comments -->
<!-- Content Start -->

<p>
<strong><font size="4">Personal Details</font></strong><br>
<a href="queries.html"> Quick Search: Find a Contact</a>
<hr>

<?php

 

// config-------------------------------------
$host = "xxxx"; //your database host
$user = "axxxxx"; // your database user name
$pass = "xxxxx"; // your database password
$db = "contact_management_system"; // your database name

$filename = "orderfirstname.html"; // name of this file
$option = array (5, 10, 20, 50, 100, 200);
$default = 100; // default number of records per page
$action = $_SERVER['PHP_SELF']; // if this doesn't work, enter the filename


// database query. Enter your query here

 $query = 	"SELECT 
		o.org_id,o.web_url,
		p.person_id,p.org_id,p.salutation,p.firstname,p.surname,
		p.organisation,p.role,p.address1,p.address2,p.city,
		p.postcode,p.telephone,p.mobile,p.fax,p.dateoflastcontact, 
		p.datecontactagain,p.email,p.consultation_panel_member,
		p.primary_contact,p.primarycontactemail, 
		p.advertising_grad_jobs,p.offer_mscproject,p.offer_ugproject,
		p.professional_devactivities,p.bcs_membership,p.bcs_pds,
		p.teaching_courses,p.academic_consultancy,

		DATE_FORMAT(dateoflastcontact, '%M/%Y') 
		AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%M/%Y') 
		AS datecontactagain 

		FROM people p LEFT JOIN organisations o
     		ON o.org_id = p.org_id		
		ORDER BY firstname";



// end config---------------------------------

$opt_cnt = count ($option);

$go = $_GET['go'];
// paranoid
if ($go == "") {
$go = $default;
}
elseif (!in_array ($go, $option)) {
$go = $default;
}
elseif (!is_numeric ($go)) {
$go = $default;
}
$nol = $go;
$limit = "0, $nol";
$count = 1; 

echo "<form name=\"form1\" id=\"form1\" method=\"get\" action=\"$action\">\r\n";
echo "<select name=\"go\" id=\"go\">\r\n";

for ($i = 0; $i <= $opt_cnt; $i ++) {
if ($option[$i] == $go) {
echo "<option value=\"".$option[$i]."\" selected=\"selected\">".$option[$i]."</option>\r\n";
} else {
echo "<option value=\"".$option[$i]."\">".$option[$i]."</option>\r\n";
}
}

echo "</select>\r\n";
echo "<input type=\"submit\" name=\"Submit\" id=\"Submit\" value=\"Go\" />\r\n";
echo "</form>\r\n";

$connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect");
mysql_select_db ($db) or die ("Unable to select database $db");



// control query------------------------------
/* this query checks how many records you have in your table.
I created this query so we could be able to check if user is
trying to append number larger than the number of records
to the query string.*/
$off_sql = mysql_query ("$query") or die ("Error in query: $off_sql".mysql_error());
$off_pag = ceil (mysql_num_rows($off_sql) / $nol);
//-------------------------------------------- 


$off = $_GET['offset'];
//paranoid
if (get_magic_quotes_gpc() == 0) {
$off = addslashes ($off);
}
if (!is_numeric ($off)) {
$off = 1;
}
// this checks if user is trying to put something stupid in query string
if ($off > $off_pag) {
$off = 1;
}

if ($off == "1") {
$limit = "0, $nol";
}
elseif ($off <> "") {
for ($i = 0; $i <= ($off - 1) * $nol; $i ++) {
$limit = "$i, $nol";
$count = $i + 1;
}
} 




// Query to extract records from database.
$sql = mysql_query ("$query LIMIT $limit") or die ("Error in query: $sql".mysql_error()); 



// Define your colors for the alternating rows

$color1 = "#ADD8E6";$color2 = "#E0FFFF";
$color = $color2;echo 

"<table width=\"50%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">

    <tr>
		<td><b><small>RecNo</small></b></td>
		<td><b><small></small></b></td>
		<td><b><small>Title</small></b></td>
		<td><a href=\"orderfirstnamedesc.html\"><b><small>First Name</small></b></a></td>
		<td><a href=\"ordersurname.html\"><b><small>Surname</small></b></a></td>
		<td><a href=\"people.html\"><b><small>Organisation</small></b></a></td>
		<td><b><center><small>Role</small></center></b></td>
		<td><b><small>Address(1)</small></b></td>
		<td><b><small>Address(2)</small></b></td>
		<td><b><small>City</small></b></td>
		<td><b><small>Post Code</small></b></td>
		<td><b><small>Telephone</small></b></td>
		<td><b><small>Mobile</small></b></td>
		<td><b><small>Fax</small></b></td>
		<td><b><small>Last Contact</small></b></td>
		<td><b><small>Contact Again</small></b></td>
		<td><b><small>Consultation Panel</small></b></td>
		<td><b><small>Primary Contact</small></b></td>
		<td><b><small>Graduate Jobs</small></b></td>
		<td><b><small>MSC Projects</small></b></td>
		<td><b><small>UG Projects</small></b></td>
		<td><b><small>Professional Dev</small></b></td>
		<td><b><small>BCS Mem.</small></b></td>
		<td><b><small>BCS PDS</small></b></td>
		<td><b><small>Teaching</small></b></td>
		<td><b><small>Academic Consultancy</small></b></td>";




while ($row = mysql_fetch_object($sql)) 






{($color==$color2)? $color = $color1 : $color = $color2;


echo "<tr bgcolor=\"$color\"><td>".$count . '</td>

<td>'.'<a href="editpeople.html?person_id='.$row->person_id. '">edit</a></td>
<td>'.$row->salutation .'</td>
<td>'.'<a href=mailto:'.$row->email.'>'.$row->firstname .'</a></td>
<td>'.'<a href=mailto:'.$row->email.'>'.$row->surname .'</a></td>
<td>'.'<a href=http://'.$row->web_url.'>'.$row->organisation . '</a></td>
<td>'.$row->role.'</td>
<td>'.$row->address1 .'</td>
<td>'.$row->address2 .'</td>
<td>'.$row->city .'</td>
<td>'.$row->postcode .'</td>
<td>'.$row->telephone .'</td>
<td>'.$row->mobile .'</td>
<td>'.$row->fax .'</td>
<td>'.$row->dateoflastcontact.'</td>
<td>'.$row->datecontactagain.'</td>
<td>'.$row->consultation_panel_member.'</td>
<td>'.'<a href=mailto:'.$row->primarycontactemail.'>'.$row->primary_contact.'</td>
<td>'.$row->advertising_grad_jobs.'</td>
<td>'.$row->offer_mscproject .'</td>
<td>'.$row->offer_ugproject.'</td>
<td>'.$row->professional_devactivitites .'</td>
<td>'.$row->bcs_membership .'</td>
<td>'.$row->bcs_pds .'</td>
<td>'.$row->teaching_courses .'</td>
<td>'.$row->academic_consultancy .'<td>';
$count += 1;
}

echo "</table>"; 

echo "<br /><br />\r\n";
if ($off <> 1) {
$prev = $off - 1;
echo "[ < <a href=\"$filename?offset=$prev&go=$go\">prev</a> ] \r\n";
}
for ($i = 1; $i <= $off_pag; $i ++) {
if ($i == $off) {
echo "[<b> $i </b>] \r\n";
} else {
echo "[ <a href=\"$filename?offset=$i&go=$go\">$i</a> ] \r\n";
}
}
if ($off < $off_pag) {
$next = $off + 1;
echo "[ <a href=\"$filename?offset=$next&go=$go\">next</a> > ] \r\n";
}

echo "<br /><br />\r\n";
echo "Page $off of $off_pag<br />\r\n";



?>
<p>
<!-- Content End   -->
<!-- Please don't remove these comments -->
<?php include "dyn.footer"; ?>


User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Again, you don't need to post huge chunks of scripts -- especially if it is mostly HTML -- for us to get the idea. Those are what are usually known as Transaction Scripts (see PoEAA). It is an older style of PHP development. It is an effective style for some kinds of projects and programmers.

But there is not really any OO in that code and I think your question of what to call it has been answered in some depth.
(#10850)
Post Reply