ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
SELECT * WHERE else IF ROWS LESS than 20 SELECT something else
ignace replied to jimmyoneshot's topic in MySQL Help
(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. -
SELECT * WHERE else IF ROWS LESS than 20 SELECT something else
ignace replied to jimmyoneshot's topic in MySQL Help
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. -
class Math { public function add() { return array_sum(array_filter(array_map('intval', $a=func_get_args()))); } }
-
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.
-
What's the name of the forum? Quite possibly it's open-source and you can just download a copy of the database file.
-
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 }
-
PHP has a directive to disable certain functions
-
Database prolly for it's data integrity.
-
Yes? Did you try it?
-
$_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.
-
What's the difference between echo and print in for's expr3?
ignace replied to dilong's topic in PHP Coding Help
Care to elaborate why this is of importance to for()? -
When you have a problem related to some functionality your first point: PHP.net manual
-
What's in database.php?
-
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.
-
How do forums check if you've read a post or not?
ignace replied to LanceT's topic in PHP Coding Help
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. -
How do forums check if you've read a post or not?
ignace replied to LanceT's topic in PHP Coding Help
I wouldn't hold the column in the posts table otherwise it will be flagged read for every user once one opens it. -
How do forums check if you've read a post or not?
ignace replied to LanceT's topic in PHP Coding Help
I noticed, so I accidentally closed the jar... missing some insects? -
How do forums check if you've read a post or not?
ignace replied to LanceT's topic in PHP Coding Help
Indeed. I should have pointed out that I was referring to storing the data in a database in my post. -
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');
-
PHP doesn't have pointers only references. All objects are passed by-reference (PHP >= 5).
-
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?
-
How do forums check if you've read a post or not?
ignace replied to LanceT's topic in PHP Coding Help
A forum marks a post read when you opened it. -
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) {} }
-
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.
-
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