Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


StevenOliver last won the day on November 25 2018

StevenOliver had the most liked content!

Community Reputation

6 Neutral

About StevenOliver

  • Rank
    Regular Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Perfect! I see it now. I ended up following your advice and created an fgetcsv PHP script (which only took me an hour, not the 2 days I anticipated :-) Now instead of the hassle of opening the file in excel, copy-and-pasting into text editor, creating a mySQL lookup, formatting the data to paste back into Excel, etc., all I have to do is open up SSH and type "php my_new_script.php" and voila.
  2. Barand: Thank you (I like the "Hands up" analogy) 😀 I cannot change the table structure (my table has 2 columns "fruit" and "color"), and your table doesn't have colors, and I tried but couldn't figure out how to modify your suggestions. Benanamen: Yes, I can explain. I have an excel spreadsheet, I select the entire "fruit" column, open my text editor and quickly create a mySQL query "Select fruit,color from mytable where fruit = 'apple' or fruit = 'banana' or fruit = 'orange'.... 1000 more fruits." Then I copy-and-paste the mySQL result into excel and I can see which ones match. They never match because every 10 fruits or so, one is missing from my mySQL table... I know I could take a full 2 days off and hack out some PHP code to take a .csv file, parse it for fruit names, create an array, create PHP/mySQL script, etc., I just hoped there would be a way for mySQL to at least do this via SSH command line result using an ifnull or coalesce or some mysterious acronym.... | grape | purple | | apple | 0 ERROR NOT HERE | | banana | yellow | | pomegranite | 0 ERROR NOT HERE |
  3. What is the most efficient way to return results in the same order as I used in my Select Statement, and return "0" if no record is found. Example: "SELECT fruit,color from table where fruit = 'grape' or fruit = 'apple' or fruit = 'banana' or fruit = 'pomegranite'; Current Result: | banana | yellow | | grape | purple | Desired Result: | grape | purple | | apple | 0 | | banana | yellow | | pomegranite | 0 | Thank you.
  4. No -- no warnings. I created the tables with both "primary key col2 (col2)" and "primary key (col2)" and there were no warnings. Then I tried the "alter table" syntax after dropping the primary keys: "alter table Table1 add primary key col2 (col2)" -and- "alter table Table1 add primary key (col2)" ... and neither of those gave any warnings. For all intents and purposes, they seem 100% identical. Perhaps in the olden days the "...primary key col2 (col2)" was how it used to be done, then it got deprecated and now "...primary key (col2)" is how it's done today, with both commands having the same effect. What are your thoughts?
  5. show index from Table1; +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table1 | 0 | PRIMARY | 1 | col2 | A | 0 | NULL | NULL | | BTREE | | | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.007 sec) show index from Table2; +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table2 | 0 | PRIMARY | 1 | col2 | A | 0 | NULL | NULL | | BTREE | | | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.007 sec)
  6. I did -- I did "show index from Table1" and the result was identical to "show index from Table2."
  7. Hmm... I did that, the results are absolutely identical. I created the tables like this: Create table Table1( col1 varchar(3), col2 varchar(3), primary key col2 (col2) ); Create table Table2( col1 varchar(3), col2 varchar(3), primary key (col2) ); What would you think I should be seeing that I'm missing?
  8. Requinix, thank you!! That is exactly what I was looking for. (It actually talks about exactly what I'm asking -- what happens when you delete values, etc.). Thank you!! Regarding question 2... (good idea, by the way.... try both then describe the tables!).... So.... I just now created two tables, one with "...primary key (col3)" and the other with "...primary key col3 (col3)" but they both look the same, so I am still not quite sure what the difference is: describe Table1 +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | col1 | varchar(43) | YES | | NULL | | | col2 | varchar(3) | NO | PRI | NULL | | | col3 | varchar(3) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ describe Table2 +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | col1 | varchar(43) | YES | | NULL | | | col2 | varchar(3) | NO | PRI | NULL | | | col3 | varchar(3) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ I also ran the command "show index from Table1" and it was identical to Table2's index. Thank you.
  9. Requinix, thank you for your answers. Would you please clarify the "mySQL updates the index automatically" part? Given a database with 100000+ records: 1.) with Primary Key, takes .001 seconds to do a lookup. 2.) without Primary Key, takes 20 seconds to do a lookup. 3.) after removing primary key, "Add primary key" takes about 1 minute. If I alter a record, I can immediately do another lookup and it will only take .001 seconds. That must mean mySQL doesn't re-index the entire table when updating the index (because reindexing takes an entire minute, and if my table isn't reindexed yet, the lookup would take forever...). I wonder how and where it updates the index? Would you please clarify your "one key is named automatically" answer? What exactly is happening when I issue this command: ALTER TABLE mytable ADD PRIMARY KEY merchandise (merchandise) (I'm still not understanding the difference between "...add primary key columnName (columnName)" and "...add primary key (columnName)" Thank you!!
  10. Question 1.) When I change a record in a mySQL table with a key, how come I don't need to delete and recreate the entire key? I always assumed that a "key" is some sort of super-condensed index that probably gets loaded into mySQL memory. If that's the case, how come making changes to the records (even small changes) doesn't throw the entire key off? Question 2.) I've seen 2 ways of adding a primary key. Using an example column "merchandise," what are the differences and which way is better: a.) ALTER TABLE mytable ADD PRIMARY KEY (merchandise) b.) ALTER TABLE mytable ADD PRIMARY KEY merchandise (merchandise) Thank you!
  11. Thank you!! I saw an answer on the net using $array[] .= and I had never seen the concatenation operator used with arrays (the answer had lots of upvotes, too), so I thought I'd look into it further before changing my own code :-)
  12. Is there a subtle difference between $array[] = 'item'; vs $array[] .= 'item'; Thank you.
  13. I'm trying to learn the proper workaround to enable Sessions when visitors have their cookies disabled. When I create a PHP session page with ini_set("session.use_trans_sid", 1) and then disable my browser cookies and view browser source code, I see what I expect: a hidden input appended like this: <input type="hidden" name="PHPSESSID" value="abc123456789reallylongstring1234" /> It seems to work (sessions without cookies!). However, I don't see the long URL query strings that I used to see when I experimented with this 10 years ago, and I don't see the long PHPSESSID value appended to all the page links, and I don't see dozens of session variables appended as hidden form inputs. Rather, I just see the one PHPSESSID hidden input described above. Is this because all the session variables are stored on the server itself, and all the server needs is that one single long PHPSESSID value? Or, am I doing it wrong? :-)
  • 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.