Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. (SELECT * FROM staff WHERE IS_TEACHER = 1 LIMIT 20) UNION ALL (SELECT * FROM staff WHERE IS_TEACHER = 0 LIMIT 20) LIMIT 20 I typed a ( and ) too many. This should work for you.
  2. You can use UNION to join two results: ((SELECT * FROM staff WHERE IS_TEACHER = 1 LIMIT 20) UNION (SELECT * FROM staff WHERE IS_TEACHER = 0 LIMIT 20)) LIMIT 20 This will select 20 teachers (if available) and 20 regular members (in case there are no teachers otherwise lower this number) and limits the entire result to 20 items. Thus if you have 17 teachers it will add 20 regulars and cut if off at 20 leading towards 17 teachers and 3 regulars. Post your code if you need more help.
  3. class Math { public function add() { return array_sum(array_filter(array_map('intval', $a=func_get_args()))); } }
  4. Creating them from the code is nearly impossible, you may get the table name and the names of the columns but not the used data type or length. If they have used views and stored procedures it becomes entirely impossible. Let's hope that those who created your software weren't at all too bright.
  5. What's the name of the forum? Quite possibly it's open-source and you can just download a copy of the database file.
  6. If you are going to pass it through a query you should validate/filter it: $query = "SELECT * FROM `tablename` WHERE `fieldname` IN (" . implode(',', array_filter(array_map('intval', explode(',', $_POST['characterIDList'])))) . " )"; if ( $result = mysql_query($query) ) { // do your mysql_fetch_whatever }
  7. PHP has a directive to disable certain functions
  8. Database prolly for it's data integrity.
  9. $_SESSION['nickname']=$result['username']; Doesn't work as it just assignes NULL to $_SESSION['nickname']; Remove this line and it should work if you are logged in.
  10. Care to elaborate why this is of importance to for()?
  11. When you have a problem related to some functionality your first point: PHP.net manual
  12. Get It Done With MySQL 5&6. Includes all axioms and rules as defined by Dr E.F. Codd. It also has a good library on SQL Query patterns.
  13. And then I close my browser*... all posts marked unread.. darn, I'll have to start all over again (*) I have my browser set to destroy any and all cookies regardless of expiration date.
  14. I wouldn't hold the column in the posts table otherwise it will be flagged read for every user once one opens it.
  15. I noticed, so I accidentally closed the jar... missing some insects?
  16. Indeed. I should have pointed out that I was referring to storing the data in a database in my post.
  17. I think you are looking for an Identity Map: class ServerMap { private $map = array(); public function get($serverID) { if(!array_key_exists($serverID, $this->map)) { $this->map[$serverID] = $this->load($serverID); // returns Server or null } return $this->map[$serverID]; } } class ClusterFactory { private $map; public function __construct(ServerMap $map) { $this->map = $map; } public function getCluster($clusterID) { $cluster = new Cluster(); foreach($this->db->fetchAll('SELECT server_id FROM servers WHERE cluster_id = ' . $clusterID) as $server) { $cluster->addServer($this->map->get($server->server_id)); } return $cluster; } } $map = new ServerMap(); $factory = new ClusterFactory($map); $clusterA = $factory->getCluster('A'); $clusterB = $factory->getCluster('B');
  18. PHP doesn't have pointers only references. All objects are passed by-reference (PHP >= 5).
  19. class Math { public function add() { return array_sum(array_filter(array_map('is_int', func_get_args()))); } } (intval() would have worked too) $math = new Math(); echo $math->add(1,2,3,4,5,'hello','world'); // Output: 15 Don't you just love PHP?
  20. Create a Request class that handles all data coming in from the client. class Request { public function getQuery($offset, $default = null) {} public function getPost($offset, $default = null) {} }
  21. Assuming the PK to be named id is a false-positive, mine actually have the table name prefixed. An anti-pattern some frameworks have picked up. LIMIT 1 is also obsolete, ID is a PK and therefor unique. Also, not every table has a single column as an ID, some are compound.
  22. function update($table, $data, $where) { mysql_query('UPDATE ' . $table . ' SET ' . _create_set_clause($data) . ' WHERE ' . _create_where_clause($where)); } $data and $where are both array's in the format: $column => $value
×
×
  • 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.