mtorbin
Members-
Posts
65 -
Joined
-
Last visited
Everything posted by mtorbin
-
In case anyone is wondering, I was able to figure it out using jQuery and an open API (though I'd rather use the tinyurl api instead): <html> <head> <script type="text/javascript" src="jQuery.js"></script> </head> <body> <div id="result"></div> <script type="text/javascript"> function TweetThis(bigurl){ $.getJSON( "http://json-tinyurl.appspot.com/?&callback=?", {url: bigurl}, function(data){ alert(data.tinyurl); } ); } TweetThis("http://www.phpfreaks.com/"); </script> </body> </html> Now I just need to convert this to prototype.js and I'm most of the way there. - MT
-
If you have any other suggestions, I'd love to hear them. I feel like I'm at an impasse here with this.
-
I definitely checked that but it didn't seem to do what I wanted it to do. I was able to get back the responseText and status, but not the HTML of the actual page. Here is the quick script I tested yesterday: <script type="text/javascript"> new Ajax.Request('http://tinyurl.com/api-create.php?url=http://www.phpfreaks.com/', { onSuccess: function(response) { alert(response.responseText.length); } }); </script> response is an object and the attribute that seemed most appropriate was responseText. As you can see it's returning a length of zero. - MT
-
Morning folks, I'm trying to transfer my knowledge of php to ajax to accomplish what I believe should be a very easy goal. I am trying to get the contents of an html page loaded into a variable. Normally I would have done this with PHP but in this case, I really need to use AJAX or the Prototype.js framework to accomplish this. Here's what I'd like to do in PHP: <?php $myURL = "http://tinyurl.com/api-create.php?url=http://www.phpfreaks.com/"; $myContents = file_get_contents($myURL); ?> Can something like this be done in AJAX? I've been looking for tutorials but they don't quite cover (from what I've read) what I want to do. Thanks, - MT
-
Hey all, I am working on a script that will call onMouseOut when the cursor leaves a fixed div but certain actions will be taken only if the cursor is now over a new dynamically placed div. Therefore, I need something like the following but I can't find the right syntax: function doThis() { if(document.getElementById("showMe").onmouseover == true) { // do this } else { // do that } } Any suggestions would be much appreciated. - MT
-
I got a little closer but now I want to be able to get this data without having to pass it: <html> <head> <title></title> <script type="text/javascript"> function showDivNmbr() { alert(myElement); } </script> <style type="text/css"> #divContainer{width:270px;border:1px #000 solid;overflow:auto;} .singleDiv{text-align:center;width:50px;margin:2px;background-color:#777;color:#fff;cursor:pointer;float:left;} </style> </head> <body> <div id="divContainer"> <div class="singleDiv" onClick="showDivNmbr()" id="div1">one</div> <div class="singleDiv" onClick="showDivNmbr()" id="div2">two</div> <div class="singleDiv" onClick="showDivNmbr()" id="div3">three</div> <div class="singleDiv" onClick="showDivNmbr()" id="div4">four</div> <div class="singleDiv" onClick="showDivNmbr()" id="div5">five</div> <div class="singleDiv" onClick="showDivNmbr()" id="div6">six</div> <div class="singleDiv" onClick="showDivNmbr()" id="div7">seven</div> <div class="singleDiv" onClick="showDivNmbr()" id="div8">eight</div> <div class="singleDiv" onClick="showDivNmbr()" id="div9">nine</div> <div class="singleDiv" onClick="showDivNmbr()" id="div10">ten</div> </div> </body> </html>
-
Hey all, I'm trying to write a script that will capture the index number of the calling tag (be it an anchor tag, a div, or whatever). As an experiment, I set up the following: <html> <head> <title></title> <script type="text/javascript"> function showDivNmbr(myElement) { alert(myElement); } </script> <style type="text/css"> #divContainer{width:270px;border:1px #000 solid;overflow:auto;} .singleDiv{text-align:center;width:50px;margin:2px;background-color:#777;float:left;} .singleDiv a{color:#fff;text-decoration:none;} </style> </head> <body> <div id="divContainer"> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div1">one</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div2">two</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div3">three</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div4">four</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div5">five</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div6">six</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div7">seven</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div8">eight</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div9">nine</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div10">ten</a></div> </div> </body> </html> Any suggestions would be most helpful. Thanks, - MT
-
Ah, got it! I didn't go up high enough on the chain: <?php class VenueData { public function __construct($key,$name) { $searchURL = 'http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=' . $key . '&limit=1&venue=' . $name; $searchXML = simplexml_load_file($searchURL); foreach($searchXML->results->venuematches->venue as $venue) { print($venue->id . "\n"); } } } ?> - MT
-
Hey all, I'm probably missing something super easy, but for whatever reason, my simpleXML object call is coming back null. Here is my code: <?php class VenueData { public function __construct($key,$name) { $this->searchURL = 'http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=' . $key . '&limit=1&venue=' . $name; $this->searchXML = simplexml_load_file($this->searchURL); $this->venueMatches = $this->searchXML->venuematches->{venue}; print(gettype($this->venueMatches) . "\n"); } } ?> Without giving away my key, here is a url that you can use to see the xml that's being pulled back: http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=b25b959554ed76058ac220b7b2e0a026&venue=arena Please help me figure out what I'm missing here. Thanks, - MT
-
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
Ok, so I think I'm good now. I've addressed the object vs. array issue, I believe I've addressed the public/private/protected issue. The circular logic issue is one that I didn't quite understand. Could you explain? I've tested the code below and it definitely works. <?php abstract class TranslateXML { protected $eventData,$eventXML,$currentYear,$currentMonth,$currentDay,$today; function setEventVars($myOBJ,$myCount) { $this->eventData['myGameID'] = $myOBJ[$myCount]->getGameID(); $this->eventData['myHomeTeamName'] = $myOBJ[$myCount]->getTeamName('home'); $this->eventData['myHomeTeamCity'] = $myOBJ[$myCount]->getTeamCity('home'); $this->eventData['myVisitTeamName'] = $myOBJ[$myCount]->getTeamName('visit'); $this->eventData['myVisitTeamCity'] = $myOBJ[$myCount]->getTeamCity('visit'); $this->eventData['myGameDate'] = $myOBJ[$myCount]->getGameDate(); $this->eventData['myGameTime'] = $myOBJ[$myCount]->getGameTime(); $this->eventData['myVenueID'] = $myOBJ[$myCount]->getVenueID(); $this->eventData['myPerfID'] = $myOBJ[$myCount]->getPerfID(); $this->eventData['myGenre'] = $myOBJ[$myCount]->getPcomGenre(); return $this->eventData; } function buildNode($myEvent) { $eventXML .= "\t<event>\n"; $eventXML = "\t\t<event_id>STATS" . $myEvent['myGameID'] . "</event_id>\n"; $eventXML .= "\t\t<event_title>" . $myEvent['myVisitTeamCity'] . ' ' . $myEvent['myVisitTeamName'] . ' (away) vs. ' . $myEvent['myHomeTeamCity'] . ' ' . $myEvent['myHomeTeamName'] . " (home)</event_title>\n"; $eventXML .= "\t\t<perf_id>" . $myEvent['myPerfID'] . "</perf_id>\n"; $eventXML .= "\t\t<addl_perfs></addl_perfs>\n"; $eventXML .= "\t\t<venue_id>" . $myEvent['myVenueID'] . "</venue_id>\n"; $eventXML .= "\t\t<event_desc>" . $myEvent['myVisitTeamCity'] . ' ' . $myEvent['myVisitTeamName'] . ' (away) vs. ' . $myEvent['myHomeTeamCity'] . ' ' . $myEvent['myHomeTeamName'] . " (home) [" . $myEvent['myGameDate'] . ' @' . $myEvent['myGameTime'] . "]</event_desc>\n"; $eventXML .= "\t\t<genres>\n"; $eventXML .= "\t\t\t<genre>" . $myEvent['myGenre'] . "</genre>\n"; $eventXML .= "\t\t</genres>\n"; $eventXML .= "\t\t<showtimes></showtimes>\n"; $eventXML .= "\t\t<schedule>\n"; $eventXML .= "\t\t\t<performance date=\"" . $myEvent['myGameDate'] . "\">" . $myEvent['myGameTime'] . "</performance>\n"; $eventXML .= "\t\t</schedule>\n"; $eventXML .= "\t</event>\n"; return $eventXML; } function compareDates($myGameDate) { $currentYear = date('y'); $currentMonth = date('m'); $currentDay = date('d'); $today = strtotime($currentMonth . "/" . $currentDay . "/20" . $currentYear); $myGameDate = strtotime($myGameDate); if($today <= $myGameDate) {return 'future';} else {return 'past';} } } class StatScheduleXML extends TranslateXML { private $myXML; public function __construct($type,$url) { switch($type) { case 'mlb': include 'class/class.MlbSchedule.php'; $this->myXML = new mlbXML($url); break; case 'nba': include 'class/class.NbaSchedule.php'; $this->myXML = new nbaXML($url); break; case 'nfl': include 'class/class.NflSchedule.php'; $this->myXML = new nflXML($url); break; case 'nhl': include 'class/class.NhlSchedule.php'; $this->myXML = new nhlXML($url); break; } } function getNewXml() {return $this->myXML->getScheduleXml();} } class mlbXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $mlbEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'baseball-mlb-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new MlbSchedule($schedule,$data); $mlbEvents[$counter] = $scheduleOBJ; if(($this->compareDates($mlbEvents[$counter]->getGameDate()) == 'future')&&(($mlbEvents[$counter]->getTeamName('home') == "Phillies")||($mlbEvents[$counter]->getTeamName('visit') == "Phillies"))) { $currentOBJ = $this->setEventVars($mlbEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } class nbaXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $nbaEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'nba-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new nbaSchedule($schedule,$data); $nbaEvents[$counter] = $scheduleOBJ; if(($this->compareDates($nbaEvents[$counter]->getGameDate()) == 'future')&&(($nbaEvents[$counter]->getTeamName('home') == "76ers")||($nbaEvents[$counter]->getTeamName('visit') == "76ers"))) { $currentOBJ = $this->setEventVars($nbaEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } class nflXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $nflEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'football-nfl-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new nflSchedule($schedule,$data); $nflEvents[$counter] = $scheduleOBJ; if(($this->compareDates($nflEvents[$counter]->getGameDate()) == 'future')&&(($nflEvents[$counter]->getTeamName('home') == "Eagles")||($nflEvents[$counter]->getTeamName('visit') == "Eagles"))) { $currentOBJ = $this->setEventVars($nflEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } class nhlXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $nhlEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'hockey-nhl-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new nhlSchedule($schedule,$data); $nhlEvents[$counter] = $scheduleOBJ; if(($this->compareDates($nhlEvents[$counter]->getGameDate()) == 'future')&&(($nhlEvents[$counter]->getTeamName('home') == "Flyers")||($nhlEvents[$counter]->getTeamName('visit') == "Flyers"))) { $currentOBJ = $this->setEventVars($nhlEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } ?> -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
OK, so I'm going through and making the suggested changes. In reference to your protected/private/public comment, we're talking about variables, right? In other words, all of my variables that are not in the abstract class should be declared private, yes? - MT -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
PLEASE IGNORE THE ABOVE POST: Here is the new code that I was able to get to work properly: <?php abstract class TranslateXML { function setEventVars($myOBJ,$myCount) { $tempOBJ; $tempOBJ->myGameID = $myOBJ[$myCount]->getGameID(); $tempOBJ->myHomeTeamName = $myOBJ[$myCount]->getTeamName('home'); $tempOBJ->myHomeTeamCity = $myOBJ[$myCount]->getTeamCity('home'); $tempOBJ->myVisitTeamName = $myOBJ[$myCount]->getTeamName('visit'); $tempOBJ->myVisitTeamCity = $myOBJ[$myCount]->getTeamCity('visit'); $tempOBJ->myGameDate = $myOBJ[$myCount]->getGameDate(); $tempOBJ->myGameTime = $myOBJ[$myCount]->getGameTime(); $tempOBJ->myVenueID = $myOBJ[$myCount]->getVenueID(); $tempOBJ->myPerfID = $myOBJ[$myCount]->getPerfID(); $tempOBJ->myGenre = $myOBJ[$myCount]->getPcomGenre(); return $tempOBJ; } function buildNode($myOBJ) { $tempData .= "\t<event>\n"; $tempData = "\t\t<event_id>STATS" . $myOBJ->myGameID . "</event_id>\n"; $tempData .= "\t\t<event_title>" . $myOBJ->myVisitTeamCity . ' ' . $myOBJ->myVisitTeamName . ' (away) vs. ' . $myOBJ->myHomeTeamCity . ' ' . $myOBJ->myHomeTeamName . " (home)</event_title>\n"; $tempData .= "\t\t<perf_id>" . $myOBJ->myPerfID . "</perf_id>\n"; $tempData .= "\t\t<addl_perfs></addl_perfs>\n"; $tempData .= "\t\t<venue_id>" . $myOBJ->myVenueID . "</venue_id>\n"; $tempData .= "\t\t<event_desc>" . $myOBJ->myVisitTeamCity . ' ' . $myOBJ->myVisitTeamName . ' (away) vs. ' . $myOBJ->myHomeTeamCity . ' ' . $myOBJ->myHomeTeamName . " (home) [" . $myOBJ->myGameDate . ' @' . $myOBJ->myGameTime . "]</event_desc>\n"; $tempData .= "\t\t<genres>\n"; $tempData .= "\t\t\t<genre>" . $myOBJ->myGenre . "</genre>\n"; $tempData .= "\t\t</genres>\n"; $tempData .= "\t\t<showtimes></showtimes>\n"; $tempData .= "\t\t<schedule>\n"; $tempData .= "\t\t\t<performance date=\"" . $myOBJ->myGameDate . "\">" . $myOBJ->myGameTime . "</performance>\n"; $tempData .= "\t\t</schedule>\n"; $tempData .= "\t</event>\n"; return $tempData; } function compareDates($myGameDate) { $currentYear = date('y'); $currentMonth = date('m'); $currentDay = date('d'); $today = strtotime($currentMonth . "/" . $currentDay . "/20" . $currentYear); $myGameDate = strtotime($myGameDate); if($today <= $myGameDate) {return 'future';} else {return 'past';} } } class StatScheduleXML extends TranslateXML { private $myXML; public function __construct($type,$url) { switch($type) { case 'mlb': include 'class/class.MlbSchedule.php'; $this->myXML = new mlbXML($url); break; case 'nba': include 'class/class.NbaSchedule.php'; $this->myXML = new nbaXML($url); break; case 'nfl': include 'class/class.NflSchedule.php'; $this->myXML = new nflXML($url); break; case 'nhl': include 'class/class.NhlSchedule.php'; $this->myXML = new nhlXML($url); break; } } function getNewXml() {return $this->myXML->getScheduleXml();} } class mlbXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $mlbEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'baseball-mlb-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new MlbSchedule($schedule,$data); $mlbEvents[$counter] = $scheduleOBJ; if(($this->compareDates($mlbEvents[$counter]->getGameDate()) == 'future')&&(($mlbEvents[$counter]->getTeamName('home') == "Phillies")||($mlbEvents[$counter]->getTeamName('visit') == "Phillies"))) { $currentOBJ = $this->setEventVars($mlbEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } ?> -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
That first function inside of TranslateXML (setEventVars) gives me the following errors: Fatal error: Class 'object' not found Googling this just returns a bunch of error pages. Any suggestions? -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
Thanks again for all of you helping me through this learning curve. Below is what I perceive to be a good start towards a much better (and to Nightslyr's point, a better "smelling") class file. Please give me your thoughts and criticisms: <?php abstract class TranslateXML { function setEventVars($myOBJ,$myCount) { $tempOBJ = new Object(); $tempOBJ->myGameID = $myOBJ[$myCount]->getGameID(); $tempOBJ->myHomeTeamName = $myOBJ[$myCount]->getTeamName('home'); $tempOBJ->myHomeTeamCity = $myOBJ[$myCount]->getTeamCity('home'); $tempOBJ->myVisitTeamName = $myOBJ[$myCount]->getTeamName('visit'); $tempOBJ->myVisitTeamCity = $myOBJ[$myCount]->getTeamCity('visit'); $tempOBJ->myGameDate = $myOBJ[$myCount]->getGameDate(); $tempOBJ->myGameTime = $myOBJ[$myCount]->getGameTime(); $tempOBJ->myVenueID = $myOBJ[$myCount]->getVenueID(); $tempOBJ->myPerfID = $myOBJ[$myCount]->getPerfID(); $tempOBJ->myGenre = $myOBJ[$myCount]->getPcomGenre(); return $tempOBJ; } function buildNode($myOBJ) { $tempData .= "\t<event>\n"; $tempData = "\t\t<event_id>STATS" . $myOBJ->myGameID . "</event_id>\n"; $tempData .= "\t\t<event_title>" . $myOBJ->myVisitTeamCity . ' ' . $myOBJ->myVisitTeamName . ' (away) vs. ' . $myOBJ->myHomeTeamCity . ' ' . $myOBJ->myHomeTeamName . " (home)</event_title>\n"; $tempData .= "\t\t<perf_id>" . $myOBJ->myPerfID . "</perf_id>\n"; $tempData .= "\t\t<addl_perfs></addl_perfs>\n"; $tempData .= "\t\t<venue_id>" . $myOBJ->myVenueID . "</venue_id>\n"; $tempData .= "\t\t<event_desc>" . $myOBJ->myVisitTeamCity . ' ' . $myOBJ->myVisitTeamName . ' (away) vs. ' . $myOBJ->myHomeTeamCity . ' ' . $myOBJ->myHomeTeamName . " (home) [" . $myOBJ->myGameDate . ' @' . $myOBJ->myGameTime . "]</event_desc>\n"; $tempData .= "\t\t<genres>\n"; $tempData .= "\t\t\t<genre>" . $myOBJ->myGenre . "</genre>\n"; $tempData .= "\t\t</genres>\n"; $tempData .= "\t\t<showtimes></showtimes>\n"; $tempData .= "\t\t<schedule>\n"; $tempData .= "\t\t\t<performance date=\"" . $myOBJ->myGameDate . "\">" . $myOBJ->myGameTime . "</performance>\n"; $tempData .= "\t\t</schedule>\n"; $tempData .= "\t</event>\n"; return $tempData; } function compareDates($myGameDate) { $currentYear = date('y'); $currentMonth = date('m'); $currentDay = date('d'); $today = strtotime($currentMonth . "/" . $currentDay . "/20" . $currentYear); $myGameDate = strtotime($myGameDate); if($today <= $myGameDate) {return 'future';} else {return 'past';} } } class StatScheduleXML extends TranslateXML { private $myXML; public function __construct($type,$url) { switch($type) { case 'mlb': include 'class/class.MlbSchedule.php'; $this->myXML = new mlbXML($url); break; case 'nba': include 'class/class.NbaSchedule.php'; $this->myXML = new nbaXML($url); break; case 'nfl': include 'class/class.NflSchedule.php'; $this->myXML = new nflXML($url); break; case 'nhl': include 'class/class.NhlSchedule.php'; $this->myXML = new nhlXML($url); break; } } } class mlbXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $mlbEvents = Array(); $scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'baseball-mlb-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new MlbSchedule($schedule,$data); $mlbEvents[$counter] = $scheduleOBJ; if(($this->compareDates($sportSchedules[$counter]->getGameDate()) == 'future')&&(($sportSchedules[$counter]->getTeamName('home') == "Phillies")||($sportSchedules[$counter]->getTeamName('visit') == "Phillies"))) { $currentOBJ = setEventVars($mlbEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $scheduleXML .= "</events>\n"; } } ?> - MT -
[SOLVED] Correctly Assigning Attributes to an Object
mtorbin replied to mtorbin's topic in PHP Coding Help
Mark, thank you! I knew it was something simple. -
I held off on posting this until I was absolutely sure I did as much research on my own as I could. I'm sure I'm missing something SUPER simple but I'm not sure what it is. The following code snippet: <?php function setEventVars() { $tempOBJ = new object(); $tempOBJ.myGameID = "something"; $tempOBJ.myHomeTeamName = "something"; $tempOBJ.myHomeTeamCity = "something"; $tempOBJ.myVisitTeamName = "something"; $tempOBJ.myVisitTeamCity = "something"; $tempOBJ.myGameDate = "something"; $tempOBJ.myGameTime = "something"; $tempOBJ.myVenueID = "something"; $tempOBJ.myPerfID = "something"; $tempOBJ.myGenre = "something"; return $tempOBJ } ?> gives me the following error message: Parse error: syntax error, unexpected '=' in .../sandbox.php on line 4 And for the life of me I cannot figure out why. What am I doing wrong? - MT
-
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
Got it: <?php abstract class TranslateXML { } class StatScheduleXML extends TranslateXML { private $myXML; public function __construct($type,$url) { switch($type) { case 'mlb': $myXML = new mlbXML($url); break; case 'nba': $myXML = new nbaXML($url); break; case 'nfl': $myXML = new nflXML($url); break; case 'nhl': $myXML = new nhlXML($url); break; } } } class mlbXML extends StatScheduleXML { public function __contstruct() { } } ?> Missing a curly. Lunch always helps the brain. Back to writing this thing. - MT -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
Quick question: why am I getting "syntax error, unexpected T_CLASS, expecting T_FUNCTION" errors from this: <?php abstract class TranslateXML { } class StatScheduleXML extends TranslateXML { private $myXML; public function __construct($type,$url) { switch($type) { case 'mlb': $myXML = new mblXML($url); break; case 'nba': $myXML = new nbaXML($url); break; case 'nfl': $myXML = new nflXML($url); break; case 'nhl': $myXML = new nhlXML($url); break; } } class mlbXML extends StatScheduleXML { public function __contstruct() { } } ?> -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
This is the "skeleton" I'm starting with. Please let me know if this looks about right: <?php class TranslateXML { public function __construct($type,$url) { } function getNewXml() {return $this->scheduleXML;} function setEventVars($myOBJ,$myCount) { $this->myGameID = $myOBJ[$myCount]->getGameID(); $this->myHomeTeamName = $myOBJ[$myCount]->getTeamName('home'); $this->myHomeTeamCity = $myOBJ[$myCount]->getTeamCity('home'); $this->myVisitTeamName = $myOBJ[$myCount]->getTeamName('visit'); $this->myVisitTeamCity = $myOBJ[$myCount]->getTeamCity('visit'); $this->myGameDate = $myOBJ[$myCount]->getGameDate(); $this->myGameTime = $myOBJ[$myCount]->getGameTime(); $this->myVenueID = $myOBJ[$myCount]->getVenueID(); $this->myPerfID = $myOBJ[$myCount]->getPerfID(); $this->myGenre = $myOBJ[$myCount]->getPcomGenre(); } function buildNode() { $tempData = "\t\t<event_id>STATS" . $this->myGameID . "</event_id>\n"; $tempData .= "\t\t<event_title>" . $this->myVisitTeamCity . ' ' . $this->myVisitTeamName . ' (away) vs. ' . $this->myHomeTeamCity . ' ' . $this->myHomeTeamName . " (home)</event_title>\n"; $tempData .= "\t\t<perf_id>" . $this->myPerfID . "</perf_id>\n"; $tempData .= "\t\t<addl_perfs></addl_perfs>\n"; $tempData .= "\t\t<venue_id>" . $this->myVenueID . "</venue_id>\n"; $tempData .= "\t\t<event_desc>" . $this->myVisitTeamCity . ' ' . $this->myVisitTeamName . ' (away) vs. ' . $this->myHomeTeamCity . ' ' . $this->myHomeTeamName . " (home) [" . $this->myGameDate . ' @' . $this->myGameTime . "]</event_desc>\n"; $tempData .= "\t\t<genres>\n"; $tempData .= "\t\t\t<genre>" . $this->myGenre . "</genre>\n"; $tempData .= "\t\t</genres>\n"; $tempData .= "\t\t<showtimes></showtimes>\n"; $tempData .= "\t\t<schedule>\n"; $tempData .= "\t\t\t<performance date=\"" . $this->myGameDate . "\">" . $this->myGameTime . "</performance>\n"; $tempData .= "\t\t</schedule>\n"; $tempData .= "\t</event>\n"; return $tempData; } } class MlbXML extends TranslateXML { } class NbaXML extends TranslateXML { } class NflXML extends TranslateXML { } class NhlXML extends TranslateXML { } ?> - MT -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
Just to update everyone on the thread, I'm going to rewrite the class and repost but it may take me a day or so. Thanks again for all of your help. This is one of those forums I really dig because I've learned so much here. -MT -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
[reading tutorials and responding to this blog at the same time] So I can understand one level of abstraction but why two? In other words, why can't TranslateXML also contain the function setEventVars and all of the variables that are global? - MT -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
I would think that, ideally, it would below to each of the sub-classes but writing that into each one wouldn't make a heck of a lot of sense because then I've just increased my file size unnecessarily, right? If I keep the function outside of the classes, then I need a way to pass in data to them. I can possibly send you everything but the actual data xml (since that is essentially proprietary data). However, unfortunately, this would have to happen "off-forum". Thanks. I think if I take a moment and re-write instead of patch I might see a much clearer picture. - MT -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
Ok, here are the changes I made but the code is giving me errors: <?php class TranslateXML { public function __construct($type,$url) { $data = simplexml_load_file($url); $counter = 0; $sportSchedules = Array(); $myXML; switch($type) { case 'mlb': include 'class/class.MlbSchedule.php'; $this->myXML = new MlbXML($data); break; case 'nba': include 'class/class.NbaSchedule.php'; $this->myXML = new NbaXML($data); break; case 'nfl': include 'class/class.NflSchedule.php'; $this->myXML = new NflXML($data); break; case 'nhl': include 'class/class.NhlSchedule.php'; $this->myXML = new NhlXML($data); break; } } } class MlbXML { public function __construct($data) { $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'baseball-mlb-schedule'}->{'game-schedule'} as $schedule) { $this->scheduleXML .= "\t<event>\n"; $scheduleOBJ = new MlbSchedule($schedule,$data); $sportSchedules[$counter] = $scheduleOBJ; setEventVars($sportSchedules,$counter); $this->scheduleXML .= $this->buildNode(); $counter++; } $this->scheduleXML .= "</events>\n"; } } class NbaXML { public function __construct($data) { $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'nba-schedule'}->{'game-schedule'} as $schedule) { $this->scheduleXML .= "\t<event>\n"; $scheduleOBJ = new NbaSchedule($schedule,$data); $sportSchedules[$counter] = $scheduleOBJ; self::setEventVars($sportSchedules,$counter); $this->scheduleXML .= $this->buildNode(); $counter++; } $this->scheduleXML .= "</events>\n"; } } class NflXML { public function __construct($data) { $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'football-nfl-schedule'}->{'game-schedule'} as $schedule) { $this->scheduleXML .= "\t<event>\n"; $scheduleOBJ = new NflSchedule($schedule,$data); $sportSchedules[$counter] = $scheduleOBJ; self::setEventVars($sportSchedules,$counter); $this->scheduleXML .= $this->buildNode(); $counter++; } $this->scheduleXML .= "</events>\n"; } } class NhlXML { public function __construct($data) { $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'hockey-nhl-schedule'}->{'game-schedule'} as $schedule) { $this->scheduleXML .= "\t<event>\n"; $scheduleOBJ = new NhlSchedule($schedule,$data); $sportSchedules[$counter] = $scheduleOBJ; self::setEventVars($sportSchedules,$counter); $this->scheduleXML .= $this->buildNode(); $counter++; } } } function getNewXml() {return $this->scheduleXML;} function setEventVars($myOBJ,$myCount) { $this->myGameID = $myOBJ[$myCount]->getGameID(); $this->myHomeTeamName = $myOBJ[$myCount]->getTeamName('home'); $this->myHomeTeamCity = $myOBJ[$myCount]->getTeamCity('home'); $this->myVisitTeamName = $myOBJ[$myCount]->getTeamName('visit'); $this->myVisitTeamCity = $myOBJ[$myCount]->getTeamCity('visit'); $this->myGameDate = $myOBJ[$myCount]->getGameDate(); $this->myGameTime = $myOBJ[$myCount]->getGameTime(); $this->myVenueID = $myOBJ[$myCount]->getVenueID(); $this->myPerfID = $myOBJ[$myCount]->getPerfID(); $this->myGenre = $myOBJ[$myCount]->getPcomGenre(); } function buildNode() { $tempData = "\t\t<event_id>STATS" . $this->myGameID . "</event_id>\n"; $tempData .= "\t\t<event_title>" . $this->myVisitTeamCity . ' ' . $this->myVisitTeamName . ' (away) vs. ' . $this->myHomeTeamCity . ' ' . $this->myHomeTeamName . " (home)</event_title>\n"; $tempData .= "\t\t<perf_id>" . $this->myPerfID . "</perf_id>\n"; $tempData .= "\t\t<addl_perfs></addl_perfs>\n"; $tempData .= "\t\t<venue_id>" . $this->myVenueID . "</venue_id>\n"; $tempData .= "\t\t<event_desc>" . $this->myVisitTeamCity . ' ' . $this->myVisitTeamName . ' (away) vs. ' . $this->myHomeTeamCity . ' ' . $this->myHomeTeamName . " (home) [" . $this->myGameDate . ' @' . $this->myGameTime . "]</event_desc>\n"; $tempData .= "\t\t<genres>\n"; $tempData .= "\t\t\t<genre>" . $this->myGenre . "</genre>\n"; $tempData .= "\t\t</genres>\n"; $tempData .= "\t\t<showtimes></showtimes>\n"; $tempData .= "\t\t<schedule>\n"; $tempData .= "\t\t\t<performance date=\"" . $this->myGameDate . "\">" . $this->myGameTime . "</performance>\n"; $tempData .= "\t\t</schedule>\n"; $tempData .= "\t</event>\n"; return $tempData; } ?> -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
Ok, let me see if I understand this correctly (and thanks for taking the time to help explain it; there's a beer waiting for you in Philly if you ever come to town). Currently I have the following classes: - TranslateXML - MlbSchedule - NhlSchedule - NbaSchedule - NflSchedule What you and Aggriv8d are suggesting is simply reformating the code in TranslateXML, not necessarily ingest the specific sport-related classes into the TranslateXML, correct (i.e. so that I'd end up with only one class file)? - MT -
OOP PHP: Where to put a "variable assigning" function
mtorbin replied to mtorbin's topic in PHP Coding Help
... which it is since it doesn't return a value; only processes data. - MT