-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Have you tried implementing the "Sieve of Eratosthenes"
-
my first PHP script, form not returning output
Barand replied to CherryLips's topic in PHP Coding Help
try <input type="submit" name="submit" value="calculate"> -
I'd say you need an extra couple of tables in addition to Person, Team, Role and Member viz. Table: task +------------------+-------------+------+-----+---------+-------------------------+ | Field | Type | Null | Key | Default | Extra | +------------------+-------------+------+-----+---------+-------------------------+ | idtask | int(11) | NO | PRI | NULL | auto_increment | | task_description | varchar(45) | YES | | NULL | | | task_value | int(11) | YES | | NULL | | | special_date | date | YES | | NULL | | | task_type | char(1) | YES | | NULL | I(nd), S(pecial), T(eam)| +------------------+-------------+------+-----+---------+-------------------------+ Table: completed_task +------------+---------+------+-----+---------+-----------------------------------+ | Field | Type | Null | Key | Default | Extra | +------------+---------+------+-----+---------+-----------------------------------+ | idcomptask | int(11) | NO | PRI | NULL | auto_increment | | idperson | int(11) | YES | MUL | NULL | NULL if team task | | idteam | int(11) | YES | MUL | NULL | | | idtask | int(11) | YES | MUL | NULL | | | task_date | date | YES | | NULL | | +------------+---------+------+-----+---------+-----------------------------------+ You wouldn't need the weekly dates table as you can group into weeks using the date fields (unless you use non-standard weeks)
-
Your neighbour table would be redundant as it can be derived by query Given this data mysql> SELECT * FROM house; +---------+-------+-------+ | idhouse | gridx | gridy | +---------+-------+-------+ | 1 | 1 | 0 | | 2 | 3 | 0 | | 3 | 2 | 1 | | 4 | 4 | 1 | | 5 | 2 | 2 | | 6 | 3 | 2 | | 7 | 5 | 2 | +---------+-------+-------+ Then this query will produce the neighbours of each house SELECT h1.idhouse as house , h2.idhouse as neighbour FROM house h1 INNER JOIN house h2 ON h1.idhouse <> h2.idhouse AND h2.gridx BETWEEN h1.gridx-1 AND h1.gridx+1 AND h2.gridy BETWEEN h1.gridy-1 AND h1.gridy+1 +-------+-----------+ | house | neighbour | +-------+-----------+ | 1 | 3 | | 2 | 3 | | 2 | 4 | | 3 | 1 | | 3 | 2 | | 3 | 5 | | 3 | 6 | | 4 | 2 | | 4 | 6 | | 4 | 7 | | 5 | 3 | | 5 | 6 | | 6 | 3 | | 6 | 4 | | 6 | 5 | | 7 | 4 | +-------+-----------+
-
It isn't the same problem so requires a different solution. In your original post you were trying to join with a single user record based on two possible matching columns. In the second you are trying to join to two different user records. In this case you would join twice to the user table but use aliases to treat it as two logical tables. SELECT pm.user1 , u1.real_name as sender , pm.user2 , u2.real_name as receiver FROM global_pm as pm INNER JOIN users as u1 ON pm.user1 = u1.id INNER JOIN users as u2 ON pm.user2 = u2.id However, given that you want a single list of users, I would use a UNION in this instance SELECT DISTINCT pm.user1 as id , u.real_name as username FROM global_pm as pm INNER JOIN users as u ON pm.user1 = u.id UNION SELECT DISTINCT pm.user2 as id , u.real_name as username FROM global_pm as pm INNER JOIN users as u ON pm.user2 = u.id ORDER BY username
-
The checkboxes are not inside the form
-
Where does $_POST['favdelete'] get sent from? And I do not see a form anywhere.
-
You are trying to use a mix of mysql and mysqli. You have to use one or the other, preferably mysqli
-
Disregard previous comment. I'm still trying to get my mind around what you want
-
It looks to me like you have your LEFT JOINS the wrong way round. You need to join the id of the category to the parent_id of the child category
-
OK here's the spoonfed versions $sql = "SELECT DISTINCT contact.email, users.id, users.real_name FROM contact INNER JOIN users ON users.email IN (contact.email, contact.work_email) WHERE contact.userid = {$thisJRUser->id} "; $sql = "SELECT DISTINCT contact.email, users.id, users.real_name FROM contact INNER JOIN users ON (users.email = contact.email) OR (users.email = contact.work_email) WHERE contact.userid = {$thisJRUser->id} ";
-
Good. That's result you want - none with a count > 1 . That means there are no duplicates. If you remove "HAVING dupes > 1" you should get them all listed with counts of 1 each mysql> SELECT item, COUNT(*) as dupes -> FROM afaaro -> GROUP BY item -> HAVING dupes > 1; Empty set (0.07 sec)
-
This code will generate unique, 11 char keys for each record assuming each one currently has a unique id (or other unique value) at the moment. If it hasn't, ALTER the table and add an auto_incrementing id first. You can remove it later if not required. (Substitute your table and column names) $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); // use your credentials error_reporting(-1); function randomkey() { $str = str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_'); return substr($str, 0, 11); } /************************************** * create an array * using table ids as the keys ***************************************/ $sql = "SELECT id FROM afaaro"; $res = $db->query($sql); while ($row = $res->fetch_row()) { $keys[$row[0]] = ''; } /************************************* * for each id, generate a unique key **************************************/ foreach ($keys as &$v) { do { $k = randomkey(); } while (in_array($k, $keys)); $v = $k; } /***************************************** * build case statements for table update ******************************************/ foreach ($keys as $id => $key) { $case[] = " WHEN id = $id THEN '$key'\n"; } $sql = "UPDATE afaaro SET item = CASE \n" . join('', $case) . " END"; $db->query($sql) or die($db->error); The generated update query looks like this UPDATE afaaro SET item = CASE WHEN id = 1 THEN 'Rbr1EMqHhU9' WHEN id = 2 THEN 'iaR69Cxs3n5' WHEN id = 3 THEN 'uOqRShXgZeb' WHEN id = 4 THEN '3VjtS1TUQKa' WHEN id = 5 THEN 'Eu+LqNpOkar' . . . WHEN id = 995 THEN 'f7jJMVnBrLe' WHEN id = 996 THEN 'LIWhxlA-EQb' WHEN id = 997 THEN 'Niq8eEwplZG' WHEN id = 998 THEN 'DzkRevCmL1U' WHEN id = 999 THEN '+MKNiDCOum3' WHEN id = 1000 THEN '5mDcSgGrdU_' END
-
mysql add to existing row where part of number equals part of number.
Barand replied to kathygriffin's topic in MySQL Help
I would recommend that instead of patching you take a step back and do a thorough data analysis exercise and construct a correct, working, normalized data model (with sensible code structure ). It may sound like hard work but it pays off down the line by vastly simplifying the processing required. -
You still haven't answered .josh's question about whether they need to be unique values. I was merely pointing out that they weren't, just in case.
-
mysql add to existing row where part of number equals part of number.
Barand replied to kathygriffin's topic in MySQL Help
This one will append junktwo to updated_stuff where the last two sections of the code are matching UPDATE crossdata1 t1 INNER JOIN cross_pull t2 ON SUBSTRING_INDEX(t1.id,'-',-2) = SUBSTRING_INDEX(t2.id, '-', -2) SET t1.updated_stuff = CONCAT(t1.updated_stuff, ' ', t2.junktwo) PS Why are you denormalizing the data? -
mysql add to existing row where part of number equals part of number.
Barand replied to kathygriffin's topic in MySQL Help
This definitely an object lesson in why you shouldn't create compound codes where different sections of the code are essentially sub-fields. Create them as separate fields and concatenate on output. Also, the object of this exercise seems to be de-normalization of your data? Those comments aside, which part/s of the code need to match? -
mysql add to existing row where part of number equals part of number.
Barand replied to kathygriffin's topic in MySQL Help
try UPDATE table1 t1 INNER JOIN table2 t2 USING (id) SET t1.updated_stuff = CONCAT(t1.updated_stuff, ' ', t2.junktwo) -
I have just written a 1000 records to a table using your "random" value generator, ie using $sql = "INSERT INTO afaaro (item) VALUES (CONCAT(SUBSTR('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_', FLOOR(1+RAND()*62), 11)))"; There were many duplicate value. Here are the duplicated values and the number of times they were duplicated mysql> SELECT item, COUNT(*) as dupes -> FROM afaaro -> GROUP BY item -> HAVING dupes > 1; +-------------+-------+ | item | dupes | +-------------+-------+ | 0123456789+ | 16 | | 123456789+- | 15 | | 23456789+-_ | 18 | | 3456789+-_ | 22 | | 456789+-_ | 17 | | 56789+-_ | 16 | | 6789+-_ | 20 | | 789+-_ | 18 | | 89+-_ | 12 | | 9+-_ | 17 | | ABCDEFGHIJK | 31 | | BCDEFGHIJKL | 39 | | CDEFGHIJKLM | 35 | | defghijklmn | 31 | | EFGHIJKLMNO | 43 | | fghijklmnop | 29 | | ghijklmnopq | 34 | | hijklmnopqr | 32 | | ijklmnopqrs | 34 | | JKLMNOPQRST | 32 | | KLMNOPQRSTU | 27 | | lmnopqrstuv | 35 | | mnopqrstuvw | 31 | | nopqrstuvwx | 13 | | opqrstuvwxy | 37 | | PQRSTUVWXYZ | 30 | | QRSTUVWXYZ0 | 17 | | qrstuvwxyzA | 11 | | RSTUVWXYZ01 | 17 | | rstuvwxyzAB | 15 | | STUVWXYZ012 | 14 | | stuvwxyzABC | 15 | | TUVWXYZ0123 | 13 | | tuvwxyzABCD | 24 | | UVWXYZ01234 | 16 | | uvwxyzABCDE | 19 | | VWXYZ012345 | 19 | | vwxyzABCDEF | 11 | | WXYZ0123456 | 20 | | wxyzABCDEFG | 13 | | XYZ01234567 | 11 | | xyzABCDEFGH | 6 | | YZ012345678 | 16 | | yzABCDEFGHI | 19 | | Z0123456789 | 21 | | zABCDEFGHIJ | 19 | +-------------+-------+ Also, 122 had values shorter than 11 chars mysql> SELECT COUNT(*) as shortvals -> FROM afaaro -> WHERE LENGTH(item) < 11; +-----------+ | shortvals | +-----------+ | 122 | +-----------+ FYI
-
I agree with Mikosiko. That is one of the worst table designs I've seen in a long time. SQL tables are NOT spreadsheets. With that design you will need to use UNIONS mysql> use idiot; Database changed mysql> SELECT ui.account, i.id, i.item, i1 as numItems -> FROM items i JOIN user_items ui ON i.id = 1 -> UNION -> SELECT ui.account, i.id, i.item, i2 as numItems -> FROM items i JOIN user_items ui ON i.id = 2 -> UNION -> SELECT ui.account, i.id, i.item, i3 as numItems -> FROM items i JOIN user_items ui ON i.id = 3; +----------+----+--------+----------+ | account | id | item | numItems | +----------+----+--------+----------+ | freid001 | 1 | Cheese | 0 | | freid001 | 2 | Ham | 1 | | freid001 | 3 | Tomato | 5 | +----------+----+--------+----------+
-
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_'; $str = str_shuffle($str); $randstr = substr($str,0,11); echo $randstr;
-
How would i center this login form code for my website
Barand replied to martin2014's topic in PHP Coding Help
Use CSS. Set the form style left and right margins to "auto" -
$visitDate = "{$_POST['year']}-{$_POST['month']}-{$_POST['day']}"; Then put the date variable in quotes in your query $sql = "INSERT INTO mytable(visitdate) VALUES ('$visitDate')";