Jump to content

aschk

Staff Alumni
  • Posts

    1,245
  • Joined

  • Last visited

    Never

Everything posted by aschk

  1. Firstly you probably want a rewrite rule to force all page requests through index.php Secondly you'll want your index.php to decide what actions it's called based on the URL that has been sent through.
  2. The collection would probably be more meaningful in another context, however I was merely showing that you can use a collection to perform group operations on multiple people. I mangled it slightly so it returns an array, which by definition should invalidate the interface. A better example would be the function "dance()", whereby you could perform dancing for a group of people. e.g. <?php interface iPerson { // ... previous code implementation public function dance(); } class People implements iPeople { // ... previous code implementation public function dance(){ foreach($this->_persons as $person){ $person->dance(); } } } ?>
  3. You sort of want to separate this logic out a little bit: You want a simple class for Person, which represents and individual (not a collection of people). We'll start by defining an interface for a Person to conform to. <?php interface iPerson { public function setName($name); public function getName(); } ?> Then we'll define a solid object of "Person" whom implements the interface for iPerson <?php class Person implements iPerson { private $_name; public function setName($name) { $this->_name = $name; } public function getName() { return $this->_name; } } ?> Then we'll define a collection of Persons, this implements the iPerson interface also to make sure it has the same methods and can be used just like a individual Person. <?php class People implements iPerson { private $_persons = array(); public function addPerson(Person $person){ $this->_persons[] = $person; } public function setName($name) { throw new Exception("You can't set 'name' for People"); } public function getName() { $data = array(); foreach($this->_persons as $person){ $data[] = $person->getName(); } return $data; } } ?> Now we also need a DataObject to populate our Person object. <?php class PersonDAO { private $db; private $_raw; private $_people; public function __construct($db){ $this->db = $db; } public function load(){ $sql = "SELECT * FROM users"; $query = mysql_query($sql, $this->db); while($row = mysql_fetch_assoc($query)){ $this->_raw[$row['id']] = $row; } } public function getPersonById($id){ if(isset($this->_people[$id])){ return $this->_people[$id]; } return $this->_people[$id] = $this->getPersonFromRaw($id); } public function getAllPeople(){ $people = new People(); foreach(array_keys($this->_raw) as $id){ $people->addPerson($this->getPersonById($id)); } return $people; } private function getPersonFromRaw($id){ if(isset($this->_raw[$id])){ $person = new Person(); $person->setName($this->_raw[$id]['name']); return $person; } return null; } } ?> Now some code to test it all. <?php $db = mysql_connect("localhost", "username", "password"); mysql_select_db("databaseName", $db); $dao = new PersonDAO($db); $dao->load(); $person = $dao->getPersonById(1); echo $person->getName(); $people = $dao->getAllPeople(); $names = $people->getName(); foreach($names as $name){ echo $name; } ?> Hopefully that will give you a bit of an insight into what is possible.
  4. Breaking it down for you: Count the number of entries by price SELECT price , COUNT(*) as 'num' FROM <insert table name here> GROUP BY price Find all UNIQUE bids SELECT price, COUNT(*)AS 'num' FROM <insert table name here> GROUP BY price HAVING num = 1 Select lowest minimum bid. SELECT MIN(price) FROM (SELECT price, COUNT(*)AS 'num' FROM <insert table name here> GROUP BY price HAVING num = 1) t1
  5. Try this out: SELECT `time` ,IF(SUM(IF(`id`=1, `status`,0))=1,'GOOD','BAD') AS 'id1' ,IF(SUM(IF(`id`=2, `status`,0))=1,'GOOD','BAD') AS 'id2' ,IF(SUM(IF(`id`=3, `status`,0))=1,'GOOD','BAD') AS 'id3' FROM <insert table name here> GROUP BY `time`;
  6. I think there are probably too many variables in this equation for us to give you a sensible answer. Here are some questions: 1) Have you done a DSL speed test to verify your line speed. 2) Does Navicat just take a long time to connect, or are queries slow also? 3) Does Navicat give you a breakdown on query time. 4) Who maintains the servers, what firewalls are in place, do you connect directly to an external IP are you using SSH tunnelling?
  7. Ah yes indeed. It would appear I misinterpreted the question. So, you might wish to consider doing this in batches instead. Take 10 records, collate all the data for them, and do an insert containing 10 items. Doing lots of inserts will be time consuming.
  8. Indeed, print_r() outputs to screen unless you supply a boolean 2nd parameter (true).
  9. Umm... Assuming test1.php contains a variable called "$myvar" Maybe something like this? <?php for($i=0; $i<5; $i++){ $myvar = "myvar equals {$i}"; include("test1.php"); } ?> The above code will "include" the content of test1.php 5 times, and change $myvar 5 times. What is it you're planning on putting in test1.php anyway?
  10. This will either be your incoming or outgoing MTA adding this line. Indeed phpORcaffine appears to be pursuing the correct resolution: determine whatit doesn't like about your sent mail. Post your mail message including all the headers you're sending and we may be able to help a little more.
  11. You need to set your character set and encoding to a case insensitive version. What is your current table character encoding?
  12. Don't use PHP to do this. Use the mysqldump tools to dump the data from the table, and then use mysql to import the data.
  13. Honestly i wouldn't bother using ENUM as they're non-SQL92 compliant. And if anything it just demonstrates a lack of effort regarding normalisation of data. Just create a table called "vehicle_type" or something of that ilk, to store your types in, and then reference their ids in your primary table.
  14. What is TBL_NEWS ? Also, if you want to know the number of records in a table you want to change your SQL query really. SELECT COUNT(*) as 'num' FROM <table name here> WHERE newsid = '{$newsid}' Make sure to fill in the missing parts from above. Also echo mysql_error(); to see if you get an error from your SQL query.
  15. Go to paypal.com and search their site for their developer/api documentation.
  16. Indeed, what line is the parse error on?
  17. I'm guessing your file looks a bit like this: text, text, text, text, text, text, text, text, text, text, text, text, etc... So you just want to output each of those comma separated values? If so try the following: <?php $filename = "<the name of the data file.txt>"; $data = file_get_contents($filename); $data = explode(",", $data); if(count($data)){ echo "<ul>"; foreach($data as $line){ echo "<li>{$line}</li>"; } echo "</ul>"; } ?> The above piece of code will output the data as an html list. n.b. make sure to change the code above to include the name of your data file (1st line).
  18. Just to clarify here, because it's a rather convoluted question: what is it you want? Are you asking for all the open & closed items for a particular user? If this is the case, please let us know what your schema is. If this isn't the case then I think you need to clarify your question some more.
  19. find the error: <?php echo odbc_errormsg($con); ?>
  20. Actually i believe it is possible, and it requires 2 things. 1) You detect a call to premature halt of your script 2) You detect byte count of delivered files. I messed around with something along these lines quite a while ago, but don't recall if i ever got it working.
  21. This is an antequated function now. You should be using mysql_query() instead. Nevertheless try this instead: <?php $query = "INSERT INTO {$database}.{$table}(`key_id`) VALUES ('%s')"; mysql_db_query($database, sprintf($query,mysql_real_escape_string($_SESSION["key_id"]))) or die("Failed Query of " .$query); ?>
  22. It depends if you're doing the sequence yourself or relying on MySQL auto_increment to provide you with the number. If the latter, then you can retrieve this information only AFTER a new record has been inserted. There's no guarantee that by adding +1 to the last ID that that will be your next id.
  23. Also note that you'll be infringing copyright law by attempting to do this without google's permission. Passing off google photo albums as your own is illegal basically. So be warned.
  24. I suspect your recursive while loop isn't working as you suspect it is. You're changing the internal $this->dirname variable when you do your recursive call, meaning that dirname is maintained in the calling loop. And I suspect because it's doing an ascending alphabetical read, it does b.php, f.php, helloworld (dir), helloworld/helloworld.php, (at this point dirname is helloworld), so it calls helloworld/z.php
×
×
  • 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.