Jump to content

rghollenbeck

Members
  • Posts

    63
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    Riverside, California, USA

rghollenbeck's Achievements

Member

Member (2/5)

1

Reputation

  1. Posting this topic was premature. I was able to get the database.php file to work right. I am very sorry for the time waster. It was inexperienced newbie stuff like forgetting to put an underscore on $_SESSION['categoryname'] and stuff like that. I have to do at least two things in the future: double check my work before posting to this forum triple check my work before posting to this forum Sorry! and thanks for all the great answers you folks have helped me with in the past. When I get better at this, I hope to return the favor on this forum.
  2. Posting this topic may have been premature. I was able to get the database.php file to read the $_POST['categoryname'] variable that was sent to quiz.php, so I don't know what I was doing wrong before. I don't know how to delete this post. I'm still testing. Maybe I will still need this question answered, but it looks at the moment as if it may be solved. Oops! I haven't yet attempted to do any logic; I only echoed the variable successfully.
  3. I have an attached header (database.php) file which does all the connecting to the MySQL database and has all the db connection variables, etc., and does all the logical heavy lifting. But the form on the previous page (quiz_selector.php) doesn't point to database.php but to the file it's included in (quiz.php). Should that make a difference? Database.php never gets the $_POST data but the file it is included in (quiz.php) gets the data. I'm wondering if I shouldn't just send the form data directly to database.php. Nah. That doesn't seem like the right solution. How do I get the data into database.php? Category_selector.php's form action is set to quiz.php. Quiz.php includes database.php. Database.php does all the work but quiz.php gets all the input from the form on category_selector.php. (I realize I'm asking the same question twice or three times in the same message. Sorry. I'm trying to make sure I clearly state my problem.) I could attach my code here to this thread (I will include relevant parts of the code if asked to do so,) but my code does not seem to be the problem. I believe the problem is that my thinking is all screwed up. If all the logic is done in database.php, how do I get the data there from quiz_selector.php when I am calling quiz.php and database.php is only an included file? (How do I rewrite my code when it's my brain that needs rewiring? But I digress.) This quiz program is in the VERY early stages of development. I'm thinking about including yet a third file. I could open and close the database in database.php, and then move all the logical operations to another included file. Seems simpler. Even then, the same question about where to send the $_POST data would still apply. P.S. I'm using PDO in case that makes any difference. Thanks to all.
  4. Yes, neil.johnson, it is "quick and dirty" and WordPress still thinks it is the original file (perhaps I still need to strip away some code, one statement at a time), but it does the job for now. Thank you very much.
  5. Thanks. I pasted the contents of single.php into my page (eval.php), pushing my content to the bottom. Once I figure out where to insert my content into this new template, I'll do that. But first, I must be missing an include statement or something because my error_log tells me: Line 13 looks like this: <?php get_header(); ?> //line 13 I got a good book on PHP yesterday (Welling and Thompson 4th edition) and I'll start reading it today. Meanwhile, I'll study that other clue (http://codex.wordpress.org/Theme_Development) to learn more about how WordPress is organized. Thanks andrew_biggart. You helped me start finding the way, but I'm not quite there yet. I would still like to get this resolved. I now plan to use single.php, as per your suggestion, as a clue to help me get started, but I need to make it work first.
  6. NEWBIE ALERT. Here comes another newbie question... Most Internet searches I have made regarding my next question indicate many people are trying to learn how to make their WordPress theme look like the rest of their website. They want to make the theme's fonts, etc. match the look and feel of their existing site. I am trying to do just the opposite. I'm using the latest "Attitude" theme by Theme Horse and I like it very much. It is clean and minimalistic--exactly what I am looking for. However, I am developing/running a quiz program in PHP that uses pages that were not generated by WordPress. I would like these pages to have the same "look and feel" as the native WordPress pages. It appears to me that there is rarely, if ever, any such thing as a single "page" in WordPress because all the "pages" are actually generated on-the-fly by a maze of interconnected php files, MySQL databases, and stylesheets. What a complicated thing it is! Are there a few lines of code which I could insert into a header or something like that to make these pages mimic the "look and feel" of their surrounding WordPress pages? If not, maybe I could at least figure out how to use the fonts from the theme to make my PHP pages look like they belong to the rest of the WordPress installation. If I had it my way, I would run my quiz program from within the native WP pages, making this a moot request, but I haven't yet figured out how to do that either. In addition to studying any replies to this question, I also plan to study the recommendations posted by QuickOldCar on 17 October 2013 - 04:42 PM to BorysSokolov regarding the anatomy of a WordPress theme, etc. That's for the bigger answer, but I'll keep this question here too because it is more specifically for the answer I'm looking for. Probably, if I could learn to write my own WP theme, I could figure out how to adapt my non-WordPress pages to behave well in a WP playground and/or make my non-WP content work within the WP framework and display correctly inside WP pages. Thanks.
  7. Thanks, AbraCadaver. Good point. I don't have to randomize the record numbers; randomizing the query results accomplishes the same thing.
  8. shuffle($questionIds); How awesome! This function had my problem in mind exactly. I was pondering how to randomize non-sequential integers--an impossible task. Shuffle() solves this problem nicely. Thank you ignace.
  9. (This question might need to go to a different forum, because it is more of a general programming logic question than a specific PHP question, but I don't know where else to ask. I am writing the program in PHP, so this is the first place I thought of to ask. If I need to move this question somewhere else, please advise. Thanks.) The short version (straight to the point): I need to generate a list of non-sequential integers and then randomize that list. The longer version: I am writing a Bible quiz program and the first page has an HTML form where the user selects a question category (i.e. a book from the Bible.) Once that selection is made, Each question in the MySQL database has an auto-increment questionID (integer) and a categoryname (string) as well as a question and an answer and some other fields. I will need to gather a list of QuestionIDs corresponding to the chosen category, then ask the questions from that category, one-at-a-time--preferably in a random order. The QuestionID is auto-incremented and new questions from 66 categories (66 books in the Bible) will be added daily. I know how to use the rand() function on sequential integers, but this list will not be sequential. Perhaps when I run the for each loop, I can add some code to stuff an array with the QuestionID for each of these questions. I could then randomize that array, put that array into a session variable, and then ask questions from that array of QuestionIDs. Does that sound like a good solution? That solution seems easier to ask than to code, but before attempting to tackle that idea, I thought it would be better to run it by some "PHP Freaks" first. Better ideas out there? Thanks.
  10. The field "categoryname" is a string. So, I had to put $cat in single quotes: "SELECT * FROM QuestionsAnswers WHERE categoryname = '$cat'"; Thank you Ch0cu3r. A classroom setting would have been handy because this topic would have surely been covered in a lecture. But you directed me to http://php.net/pdo where more information was available. That website can be overwhelming, but with patience, much useful data can be found there.
  11. Thank you Ch0cu3r. Actually, I did have the variable ($cat = $_POST['category'] declared but I failed to show it in my question. I changed my query as you recommended: $sql = "SELECT * FROM QuestionsAnswers WHERE category = " . $cat; foreach ($db->query($sql) as $row) { // this is line 27 print '<p>' . $row['question'] .' <br /> '. $row['displaystring'] . '</p>'; } but, fearing I may have inadvertently picked a reserved word as a column name, I changed category to categoryname in the database, in the form, and in my php file. Everything else is the same. Here's what happened in the error_log, both before and after the column name change: "Acts" was the value of "categoryname", not a column. I'm still getting something screwed up, but thanks to you, I'm much closer. I will keep working on it after a nice nap. I really need to get this working so I won't quit. I'd rather use a prepared statement if that is better, but the answer you gave me didn't work at all. I can continue studying and learning about prepared statements to get them to work right, but at this moment, my database is worthless and I just need something--anything--to work. Oh! Another change I made was to use double quotes (") for string items like "</p>"; etc. and single quotes (') or apostrophes to identify field names, etc., like $row['question'] to avoid confusion. Thank you again. I am still on this case.
  12. I have a MySQL database on justhost with a field called "category" that I want to use in a WHERE query. The database opens fine without any WHERE clause. It's only when I begin to use a WHERE clause that I begin to get into trouble. All the "Gurus" out there tell me I need to be shifting over to PDO, so here is my attempt to get up to speed. The previous page (select_category.php) had a form with a selection drop-down box for category. I addressed it in the next file (quiz.php) like this: $cat = $_POST['category']; Now I want to query the data: $db = new PDO('mysql:host=localhost;dbname=' . $dbname , $dbusername, $pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql->prepare("SELECT * FROM QuestionsAnswers WHERE category = " . $cat); //This is line 23 foreach ($db->query($sql) as $row) { print '<p>' . $row['question'] .' <br /> '. $row['displaystring'] . '</p>'; } but I'm getting errors: I have been around and around on this for two days. Does anybody see what I am obviously missing? Thanks.
  13. Wow! It looks like it's mac_gyver to the rescue once again! Not only did you solve my problem, you answered the question I didn't know how to ask. Yes, Prior to today, I didn't even know about session variables; I knew about cookies, if you remember my original question from yesterday. I was storing variables in text files on the server. Okay, here's a scenario: User A gets a question posed to her and the question number is stored in a text file. User B comes along and does the same thing, changing the data in the text file. User A answers the question that has been changed by user B. See? No bueno. I cannot store it in a text file. The answer to my question is, "Yes." I need to replace that text file with a session variable. That will fix the problem. Thank you again! To jazzman1's question about why I would want to do this, I was only testing my code against possible problems. If I hadn't used two separate computers and/or two separate instances such as another browser at the same time, I might not have discovered the error in my thinking. I would have discovered it after the quiz hit the streets. That would have been more embarrassing.
  14. When I run my quiz program from one computer, it works okay. If I run it from another computer it works okay there too. But when I'm running both computers on the same program, they interfere with each other--the quiz running on one computer is waiting for an answer that was just asked on the other computer, etc. My guess is that by turning ALL my variables into session variables, I will solve that particular problem. Is this correct? Or are there other things I need to do to prevent multiple users from confusing any server-side PHP-based quiz? Thanks
  15. All the browsers are now keeping and using session variables. Thanks to everybody. I don't know if Fiddler 2 did the trick or if I just got lucky, but I installed a missing jqiery library that was referenced even though I never called it, and I added the session_start() to the other .php files even though I wasn't going to them at the time I had the problem.. Whatever it was, it is now working great all over.
×
×
  • 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.