Jump to content

SaranacLake

Members
  • Posts

    648
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    New York
  • Age
    40

Recent Profile Visitors

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

SaranacLake's Achievements

Prolific Member

Prolific Member (5/5)

4

Reputation

  1. @Barand Sorry for the late response, but I have been tied up with another part of my website for the last week or so.... Thanks for the sample array above! I am trying to get my head back into things, and am sure I will have follow-up questions. Q1.) For starters, in your multi-dimensional array above, 'title', 'intro', and 'sections' are [keys[/b] for the outermost array, right? Q2.) I forgot, what do you call arrays where the keys are text values like your example? Associative arrays? Q2b.) And what do you call arrays where the keys are numeric? Q3.) I assume that text keys cannot/should not have spaces in them like 'first name', right?
  2. I still hate arrays! πŸ™ Could use some help expanding an array by adding another dimension. (I'm sure this will be super simple for the gurus here!) Currently I have an array that holds my questionnaire questions (HMTL-formt) like this... questionnaireArray array 1 => <li>Question-1 here</li> 2 => <li>Question-2 here</li> 3 => <li>Question-3 here</li> 4 => <li>Question-4 here</li> I want to expand this PHP page so that a series of questions are part of a "Section" that may (or may not) contain some lead-in text. (The idea being that sometimes it is necessary to have a short intro to a series of questions, and that text is better placed next to the questions, as opposed to at the top if the page.) The end result I want would look like this... QUESTIONNARIE <Intro Synopsis> <section-1 intro is blank> Q1.) Q2.) <section-2 intro = "Some text here..."> Q3.) Q4.) <section-3 intro = "Some more text here..."> Q5.) Q6.) So I could use help taking my current array (above), and nesting it within a parent array that will contain each Section's intro text - which could be blank. And to be clear, what I need help with now is *visualizing* what the new array will look like - versus how to create it. (Once I understand what it should look like and what the keys and values are, then i can probably figure out the PHP coding part!) For instance, what is the $key for my parent array? What are the $values for the parent array? And how does my current array (above) fit into this? Thanks!
  3. Good to know. I suppose that I will open many new doors once I learn Javascript?! Hopefully I can get to that later this year or next...
  4. VERY impressive, I must say! 1.) Is that open-source? (I might not feel so bad "cheating" and using someone else's library as long as it is NOT from Google or some other evil corporation!) 2.) So I guess I'd need to know how to do Javascript, right? 3.) And I'd need to know how to use JSON? (Have heard of that but have no clue what it is?!) Thanks for the tip! πŸ‘
  5. True, but even I make mistakes, and guard-rails can be nice. Good point, so let me re-state. I have a "question_type" table that would define a question as say "rating-5pt". To your point, I could store a "5" in the "question_type" lookup so that as I add in hundreds of questions, I am always pulling that "5" from the lookup table thus eliminating the issue I believe you are pointing out. To your earlier question... What could happen? Well, I could end up with an UN-balanced set of choices (e.g. 1-Strongly Disagree, 2-Disagree, 3-Neither, 4-Agree) with "5-Strongly Agree" missing and thus skewing the question and responses. I assume what i want to do could be fairly easily done coding a trigger, but not having any hnds-on experience with triggers or stored procedures I'm not certain. Am hoping someone can at least explain if what i want to do is doable...
  6. Hello. This problem deals with survey questions and their corresponding answer-choices. Let's say I have a satisfaction scale like this... 1 - Strongly Disagree 2 - Disagree 3 - neither 4 - Agree 5 - Strongly Agree I created a new table called "answer_group" to bind together a bunch of related choices... answer_group -||-----|<- answer Here is what I want to happen... In the "answer_group" table, for a given "answer group" (record) there would be a column called: "no-of-choices" and it would have a value like "5". I want MySQL to look at that value of "5" in the parent table/record, and as I add child records in the "answer" table - linked by a foreign key, I want MySQL to prevent the database user from adding/linking more than "5" child records. Why? Because if a "Question" has a 5-Choice satisfaction question, then I don't want to accidentally display 7 Choices?! (Especially since my PHP code paints however many Choices you tell it in the database.) This is actually a pretty easy data-entry / data-linking mistake to make, so I want MySQL to keep me honest! It seems like I would need either a "trigger" or a "stored procedure" (or maybe both) to do this? And I'm not sure how involved something like this is? But it never hurts to ask, and to start investigating things. (For v2.0, another thing I want to do is become proficient with triggers and stored procedures to build a more sophisticated database.) My best guess at how to do this would be to add a "Before Insert" trigger to the (child) "answer" table - on the FK column - and have it count how many new sub-records are created, and once counter >= "answer_group"."no_of_choices" for a FK, then prevent MySQL from adding any more sub-records in the "answer" table. Just my guess...
  7. Yes, I agree that is the harder part. @Barand, WOW! I am blown away by your example below! That is a super good-looking horizontal bar chart! As you mentioned, it takes more work to get adjustable scales, titles, etc, but I think what you have below is more than sufficient for my needs. And I think most users would appreciate a "visual", even if it is a simple one, because that is all I think most people want. I will put your code in my hat to use after I go live with my website. Thanks for the headstart! πŸ‘
  8. Good to hear! Well, not entirely true. It is possible to collect data, but not have it normalized properly, and end up with a real PITA. But data modeling is my strength, and I think I have a good data model. (My only issue is that I am the king of "scope creep", and every time I build something or fix something - like my survey data validation thanks to @maxxd suggestion - I get the urge to add on more functionality! I can see a few things in my current data model that could be a pain down the road, so i am thinking a few steps ahead and making sure my database is scalable.) Valid argument. Yeah, I am pig-headed and I prefer rolling my own solutions. I did a quick Google search during supper, and it looks like it isn't too hard to create decent pie charts and bar charts using CSS3. (I think the hard part is using PHP to grab the data from the database, and dynamically feeding the graph things like adjustable scales so as more people respond the graph adapts. Reporting is a v2.0 thing, or at least a v1.1 thing. But my question for now is more making sure I don't paint myself into a corner that i can't easily fix later. Sounds like at first inspection you think I'm on the right path. And, now I just need to figure out how much I want to "gold-plate" my current database design. πŸ™‚
  9. Well, I don't know exactly what I need since I don't know how to create a bar chart from scratch yet! After posting, here is what I came up with in my head... - In MySQL, create a query using COUNT( ) and GROUP BY to get a query-set that contains the 5 stubs and their count values. 1, Strongly Disagree, 7 2, Disagree, 10 3, Neither, 12 4, Agree, 25 5, Strongly Agree, 41 - Then pull that into a multi-dimensional array in PHP - Then iterate through that array / multi-dimensional array and build my bar chart. In general, does that sound like a good start? Again, the main thing I am worried about is not having what I need on the backend. I have my survey script running now, plus data-validation working, and I have a few data model tweaks in mind, but I want to be sure that I have the tables and relationships to build the graphs/charts/reports that one would expect. Since I will be (hopefully) displaying all survey results visually using PHP, I think that gives me more flexibility than if i could only present data in a tabular format - thus why I now have 'cross-tab" queries in my mind. (If a person wanted to describe survey results using only tables, then I think that would be a hellish query since in my case I have disparate question types - Yes/No, Rating Scales, Multiple Choice, Multi-Response, etc. I think by breaking the data down to a per question basis and using a graph to represent that particular type of data, it will be much easier, and probably not as rigid on the table design side of things.)
  10. This question is part PHP, part MySQL. I have a survey_responses table... - id - survey_id - question_id - member_id - response For satisfaction questions (i.e. 1 = Strongly Disagree, 2 = Disagree, 3 = Neither, 4 = Agree, 5 = Strongly Agree), I'm trying to figure out how to get the counts for each of those responses into PHP so I can then feed them to a Bar Chart I hope to create with HTML/CSS. 1.) Should I create some kind of loop in PHP, and look for each value (e.g. 1 = Strongly Disagree) and one at a time plug them into variables called: $stronglyDisagree, $disagree, $neighter, $agree, $stronglyAgree? 2.) Or do I first need a "cross-tab" query in MySQL? 3.) Would this be easier if the database values were in a PHP array? Not sure where to begin with this, and more importantly, I want to make sure that my data model in MySQL is sufficient so i can do reporting like this!! Thanks.
  11. I just didn't know if this comment...
  12. Not sure if I follow completely what you mean - as in how many nested IF-THEN-ELSE's? Although, I think my IF-THEN-ELSE's would make you turn to violence?! ☺️ I have IF-THEN-ELSE's that cover the majority of some of my scripts, and so they can be well over 1,000 lines of code. (Surprisingly, I have become very adept at reading them, but I'm sure there is an easier way!) Not so much a "God class", but rather a particular "use-case". trouble is, the start-to-finish path of a use-case is often well over 1,00 lines of code. Most of my scripts average 800-1,500 lines of code, and I have over 50 of them. True. (If you want to want to know what's involved with say "checking out", it's all in one script minus a few functions. So while scrolling can be a bitch on my laptop, I never have to go on an Easter egg hunt across 50 files to follow the flow of things.) That is one of many things that scares me about OOP. I probably average one line f comments for one line f code, and my code is some of the prettiest you'll ever see, so preaching to the chior on that one. But still good to be said! Agreed. As mentioned, probably 40-50% of my code is comments, so I get you. (Not to say YOU would understand everything, but it is enough so that I have been able to read and understand 90% of my code from 8-10 years ago! (And the few places I couldn't understand things - mainly some big ass queries - i should have done a better job documenting the business logic?!)
  13. @kicken Thanks for the tips! πŸ‘
  14. @maxxd I was able to take your advice and write a block of code to do what you suggested last night. have gotten error message starting to appear for some question types, but now I need to figure out how to logically incorroate this new code into my old code base which is going to be a bear - but I am getting there!
  15. Not just functions - all of my code. The way I learned to code is procedurally, so I code things based on what you want to do. For instance, my "article.php" script - which displays an article and user comments below and all functionality related to that is a little over 3,000 lines of PHP, because I coded some "use-case" as a single script. (Not the way OOP works.) Bingo! if you were almost done with a decade long project, would you go in and tweak some section for fear it could cascade and break thousands of lines of code? (Of course that can apply to any large system, but more so the way i coded things.) Well, I disagree here. My code isn't poorly written, it is just hard to work with since it is a birth-to-death approach! (I recall reading from some OOP expert that a class should never be more than 100 lines of code.) I have spent the last few weeks walking through my code base line by line and getting my head back into how it works. Except for this current script, i would say that all of my code made sense - although some took a long time to load into my brain and turn on a lightbulb! - and not surprisingly to me, I have only had to tweak a *few* lines of code after reading over 40,000 lines so far. So to an outsider, getting into my code might be scary, i think it reads like a book once you see my coding style. Also, i have my code so heavily commented, most of it is self-explanatory. Also, I want to point out that the reason this site has taken over a decade is that it IS well thought-out. (In fact, a little too much so!) My challenge is to learn how to break a 3,000 line script into 20 components that are shorter, easier to update, and more reusable. Once I go live, I am going to update any architectural designs I have written out on paper, update them, and then start coding a new v2.0 from scratch. That way I have a working site, and I can ferret out all of the annoying things that I want fixed but that would take too much energy to do. (Better to start with a new frame and body versus trying to twist a wreck back into an original!) Most of my functions have 3-4 parameters, so that isn't too bad. What is bad is how I intermingled "presentation' with "business logic". Frankly, I think PHP encourages that kind of bad coding, which is why I'd like to get into something more substantial like Python, but time will tell. Exactly. What is worse, is that i have a single 'functions.php" script with ALL of my functions and it is like 8,000 - 10,,000 lines of code long?! In the future, I am thinking "One function, one script" i sthe way to go, as I think that is how OOP works where they have "One class, one file". I know I need to strengthen my skills in IDE's. I use NetBeans and am probably only using 10% of its features which is sad. In fact, I think THAT is mor eimportant than learning Git - although I am planning on doing that. There is also one other thing you left out... I am 10-15 years older - and more senile - than I was when I started with LAMP, and at my age, those 10-15 years are SIGNIFICANT!!! I'm not dead yet, but I am also no longer 20-something, and I am starting to "appreciate' how my mind isn't as sharp - nor my stamina as strong - as it was in say 2000. That is even more reason to get damn good with IDE's, Git, MVC, OOP, and use generally accepted coding 'best practices" ASAP. In the end, I know a lot more than many people give me credit for, HOWEVER, thee is much I can do to take things "to the next level", and if I want to become a millionnaire, then i better hurry up and start doing those things in v2.0! πŸ˜€
×
×
  • 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.