Jump to content

denno020

Members
  • Posts

    761
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by denno020

  1. I've only just started playing with join statements, but maybe you could give this a try: SELECT pat_id,pat_lname,pat_fname,pat_date,pat_loc,pat_show, (SELECT office_name FROM offices WHERE offices.office_id = patients.pat_ins) AS name_office FROM patients I don't have your database code, so I can't really test that, but the idea is that the SELECT within the parenthesis will grab the office_name from the table offices where office_id in offices matches pat_ins from patients (I think I got the fields right for what you were after?), and put it into the results as name_office. But like I said, I could be way off base here. Hopefully that'll give you something else to look into. Denno
  2. That's the reason I'm here, teaching people as they ask questions . I hope you do get that A!
  3. Well done getting it finished.. One thing I would like to mention though, I hope you're not getting graded on your styling.. It's rather difficult to read with that background and the font colours. But at least the core of your program works.
  4. Sorry I've been out all day.. Anyway, I've gone from my code that I posted earlier, and implemented a start button. Compare this with your code to see where you've done things differently, so you know what to do in the future. <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if(isset($_POST['start_game']) || isset($_POST['myGuess'])){ if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); //This is used for debugging - keeping track of what each value is when the submit button is pressed if(isset($_POST['choice'])){ print_r($_POST); } //This following block of code doesn't do anything in the game, so not sure why it is here? $show_submit = true; if(!isset($_SESSION['number_to_guess'])){ $num = rand(1, 100); $_SESSION['number_to_guess'] = $num; } else{ $num = $_SESSION['number_to_guess']; } if(isset($_POST['btn_new'])){ session_destroy(); session_unset($_SESSION['number_guess']); header("location: index.php"); } $form = "showOptions"; }else{ $form = "showStart"; } if($form == "showOptions"){ ?> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> </form> <p>Guess: <?php print $myGuess;?> <?php } else{ ?> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <form method="post" action="" name="choice"> <input type="submit" name="start_game" id="start_game" value="Start Game"/> </form> <?php } ?> </body> </html> Needless to say that I've tried this and it's working perfectly. Denno
  5. I can't see where "select area" is that you remove?
  6. Where's the if statement that will determine which part is showing? Right now everything is shown at once.. You want either the form with the submit button to show (which you want to show by default), or you want the form with the radio buttons and reset link showing (which will show only once the Start button has been pressed)
  7. I did try the game, it works as expected. The browser shouldn't matter with this, so not sure why it would get stuck on Safari.. Because this is all server-side, the browser merely shows what data it's given. You would usually only test browsers when you have CSS and javascript that needs checking. PHP will not care about browser. I'm not exactly sure what was making it go back to 1, but it was probably something to do with the script not knowing what it had previous guessed, so setting high and low variables was kinda pointless. For implementing a 'start' button, you will need a second form, with only a submit button in it. Then you need to use PHP to determine which form is going to show. So the if condition will need to check if the start button has been pressed or not. Give that a crack and post back with some code that you come up with and I'll guide you from there.
  8. Here you go: <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); //This is used for debugging - keeping track of what each value is when the submit button is pressed if(isset($_POST['choice'])){ print_r($_POST); } //This following block of code doesn't do anything in the game, so not sure why it is here? $show_submit = true; if(!isset($_SESSION['number_to_guess'])){ $num = rand(1, 100); $_SESSION['number_to_guess'] = $num; } else{ $num = $_SESSION['number_to_guess']; } if(isset($_POST['btn_new'])){ session_destroy(); session_unset($_SESSION['number_guess']); header("location: index.php"); } ?> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> </form> <p>Guess: <?php print $myGuess;?> </body> </html> There are a few things I had to change: //Before $myGuess = isset($_POST['correct']) ? $_POST['correct'] : 0; //After $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; You had it right in your original post, but not sure why it was changed. <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> These are all used to keep track of the previous guess, current highest and lowest numbers, and also how many attempts have been made. They're the main things, and your guessing game will now work. Have a look at the code and make sure you understand it. Feel free to ask more questions if you're not sure about anything. Also, remove the debugging when you are finished, as that isn't needed for the final version, but it's handy for using while developing. Denno
  9. put this at the top of your code if(isset($_POST['choice'])){ var_dump($_POST); die(); That will print out the contents of $_POST once you have made an incorrect guess. This way you can see what values are coming through. Also, you may want to add name="highest/lowest" to each of the hidden input fields.. I can never remember which value is passed through the $_POST variable, so I usually put both, however I obviously forgot when I typed that example code before..
  10. Add these after the inputs you already have (but still within the form tags: <input type="hidden" id="highest" value="<?php echo $highest ?>"/> <input type="hidden" id="lowest" value="<?php echo $lowest ?>"/>
  11. Where do you actually set 'highest' and 'lowest' in your form? It looks like that will always be resetting to 100 and 1 respectively. You should add two hidden input fields in your form which will store the previous highest and lowest values, that way this code $highest = isset($_POST['highest']) ? $_POST['highest'] : 100; $lowest = isset($_POST['lowest']) ? $_POST['lowest'] : 1; Will actually be true on subsequent guesses. Also, I'm not sure how this is working, because you don't have the input fields inside the form tags yet.. That won't fix your problem of it only increasing by 1 each time.. Could you put at the top of your code print_r($_POST); and make sure that it actually has something in there when you hit the submit button
  12. I can see a few problems in your code. You should only have one <!DOCTYPE .......> tag on a page. You've got two if statements checking the same condition but doing different things, both of which has a header redirect. I don't think the second if statement will ever be reached if the condition is true, because the first one will have already initiated the redirect. if(isset($_POST['btn_new'])){ session_destroy(); header("location: index.php"); } if(isset($_POST['btn_new'])){ session_unset($_SESSION['number_guess']); header("location: index.php"); } I could be wrong on that, maybe the code will still execute, but even if it does, you should move the session_unset() to the first if, and just remove the second one, I don't see any point in having them separate. You also need to put your input fields inside the <form> tags, it looks like you have them above with only a <br/> inside. If you can fix all that up and come back, we'll see what's happening with it then. Denno
  13. I think you need to specify both the name of the variable client side, and what it will appear as server side. So where you have this in your ajax function: data: pic_data change it to: data: {pic_data: pic_data} Oh, and also make sure that you set the type back to POST. And when returning information from the server, I always use json_encode(). Denno
  14. Oh sorry didn't see that you had replied.. You wouldn't do that with PHP, you would do that with javascript.. As for a generic add button, you could do that. If you surround your entire table with the form tags and place your add button at the bottom of the table. Then you will have to loop through each text field in your php once you submit the form (by pressing the add button). (I'm intentionally being a little bit vague with instructions on how to do things, as I want to try and get you going first, and then I'll help you with whatever code you come up with ). Hopefully that will give you the right idea!
  15. I'm not really sure what you mean, but if you just want it to go to the same page as it was before, when the price wasn't being added, then just make the action of the form the same as your href that you had original for your add link. So <form action="ret_addprod.php?id=$row[prod_id]" ......>
  16. Put the add button inside the form as well. You'll obviously sacrifice putting the add button in it's own table row, but it'll make it easier to submit the form, without having to play around with javascript. And also, make the Add button an actual button, and not a link.. (unless you really want to keep it a link, in which case you'll need some javascript to be able to submit the form). So the add button will be like this <input type="submit" value="add" id="add"/>
  17. You need to put your input field inside form tags, give that form and make sure that you set the method for that form as POST
  18. So the Faral Error that was just thrown is exactly what I had in my code, so that means $_POST['prod_price'] isn't set. You will need to check the id of the text field that you're putting the price into. Can you show that code here?
  19. With the lack of error information that you've given, I can only guess that the variable $prod_price isn't being set to the value from the form. Either the value hasn't come through the form correctly, or the field has a different name. You can try this to see if that's the source of the problem: if(isset($_POST['prod_price'])){ $prod_price = $_POST['prod_price']; }else{ throw new \Exception("prod_price wasn't set correctly in the form"); } Give that a try..
  20. This is how you could do it, a quick and dirty way: <input type="submit" name="submit" id="submit" style="background-image:url('path_to_image/add_to_cart.jpg')"/> If you do it that way, then you'd probably also want to set the width and height of the button to match that of the dimensions of the image you're using, otherwise it won't display correctly. Denno
  21. a very simple way would be to do a preg match to match for greater-than and less-than symbols, which would indicate opening and closing tags. Something very simple like this would be a start: preg_match("/.*<.*>.*/", $input); Put that in an if condition, as it will return true if it matches. Hope that helps. Denno
  22. I'm not sure this is exactly how the htaccess is supposed to be used.. Well it's not how I use it anyway. With my site, I use urls that are "mysite.com/one/two/three". In my htaccess, I grab that url, and rewrite it so it's "mysite.com/index?first=one&second=two&third=three". (I have a MVC setup, so the first one usually corresponds to the controller, the second to the function, and the third is a parameter for that function.) While my htaccess does this rewrite, it doesn't actually change the url that the user sees. So your best bet, I think, is to use your shortened URLs as you want them (make them the hrefs of links/form actions etc) but then write rules that will rewrite them to be job.php?ref=$1 etc. That way you can access 'ref' through $_GET in your php script, but it won't actually change the way that the URL looks to the user.. I really hope that makes sense and I haven't confused you :/.. Denno
  23. rowCount is for PDO, which you're not using. But yes, with the closing bracket a the end of $result, that is how you use it.
  24. Well if you want to use mysql_connect, which again, I suggest you dont, but if you do, then that will create a connection to the database. You will then use that in another function, mysql_query(), which will take a string as the first paramater, which is the query, and the second parameter is your $con variable (which represents the connection to the database). But seriously, you should learn to use PDO. It's really not hard, and will mean your code won't become useless when these functions are eventually removed from php..
×
×
  • 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.