next step in programming? [sample code included]
Posted: Sun Jan 17, 2010 2:27 am
Hello,
I have been learning php for about 8ish months now, and really enjoy it thus far, but I have noticed that my skills have become somewhat stagnant, and am really not sure where to go to advance my skills. Unfortunately, I tend to follow the structure I would for a University assignment, most were very short (and procedural) and could be solved with a single 'main' function or a few secondary functions, never really touching on OO or anything like that.
I have been reading about MVC quite a bit lately, but cannot seem to conceptualize how to make my code into OOP and MVC fashion.
Here is an example page:
With this being my second major php project, you can imagine how much fun this is to maintain later on...
Since I am basically just building prototypes and figuring out how I would like things to flow and work, it seems like a great time to try out some new skills. Any advice would be greatly appreciated, I would like some critiques on my code ( I am not proud of this by any means ) and maybe somebody could suggest good materials I could read. I have learned TONS on my own (outside of the classroom) but I am just lost as to where to go and what the next step is after 'the basics'.
Thanks
Daniel
I have been learning php for about 8ish months now, and really enjoy it thus far, but I have noticed that my skills have become somewhat stagnant, and am really not sure where to go to advance my skills. Unfortunately, I tend to follow the structure I would for a University assignment, most were very short (and procedural) and could be solved with a single 'main' function or a few secondary functions, never really touching on OO or anything like that.
I have been reading about MVC quite a bit lately, but cannot seem to conceptualize how to make my code into OOP and MVC fashion.
Here is an example page:
Code: Select all
<?php
// Sets basic checks
if( isset( $_GET['mode'] ) && isset( $_GET['type'] ) ){
$mode = $_GET['mode'];
$type = $_GET['type'];
}else{
header( 'Location: ../start.html' );
}
require( dbconnection.php );
error_reporting( E_ALL );
$sqlIcon = "
SELECT
iconID,
iconURL
FROM
mapItems_icons
";
$resultIcon = mysql_query( $sqlIcon );
if( !$resultIcon )
die( mysql_error( $conn ) );
if( $mode == 'edit' ){
//populates the form fields
$sql = "
SELECT
m.mapItemID,
m.name,
m.address,
m.url,
i.iconID
FROM
mapItems AS m
INNER JOIN mapItems_icons AS i
ON m.iconID = i.iconID
ORDER BY
m.name ASC
";
}else{
//populates the drop down
$sql = "
SELECT
iconID,
iconURL
FROM
mapItems_icons
";
}
$result = mysql_query( $sql );
if( !$result )
die( mysql_error( $conn ) );
$row = mysql_fetch_array( $result, MYSQL_ASSOC );
$iconid = $row['iconID'];
echo $iconid;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Building Information</title>
</head>
<body>
<form>
<fieldset>
<legend>General Building Information</legend>
<label for="buildingName">Building Name:</label>
<input id="buildingName" type="text" size="20" value="<?php if($mode == 'edit'){ echo $row['name']; } ?>" />
<label for="buildingAddress">Building Address:</label>
<input id="buildingAddress" type="text" size="20" value="<?php if($mode == 'edit'){ echo $row['address']; } ?>" />
<label for="buildingImage">Image URL:</label>
<input for="buildingImage" type="text" size="40" value="<?php if($mode == 'edit'){ echo $row['url']; } ?>" />
</fieldset>
<?php if( $type == 'marker' ){ ?>
<fieldset>
<legend>Choose a Marker</legend>
Select a Marker: <select>
<?php
//mysql_data_seek($result, 0);
while( $row = mysql_fetch_array( $resultIcon, MYSQL_ASSOC ) ){
$iconID = $row['iconID'];
$iconURL = $row['iconURL'];
if( $iconID == $iconid ){
echo "<option value=\"$iconID\" selected>{$iconURL}</option>\n";
}else{
echo "<option value=\"$iconID\">{$iconURL}</option>";
}
}
?>
</select>
</fieldset>
<?php } ?>
<fieldset>
<legend>Get Coordinates</legend>
<p>Map will populate here</p>
</fieldset>
<br /><br />
<button>Submit</button>
</form>
</body>
</html>
Since I am basically just building prototypes and figuring out how I would like things to flow and work, it seems like a great time to try out some new skills. Any advice would be greatly appreciated, I would like some critiques on my code ( I am not proud of this by any means ) and maybe somebody could suggest good materials I could read. I have learned TONS on my own (outside of the classroom) but I am just lost as to where to go and what the next step is after 'the basics'.
Thanks
Daniel