Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Personally, when using some functions - notably those in the gd libary, i do use some uppercase characters. Since those in the gd library don't use underscores, i find them a little hard to read - imageCreateTrueColor() is easier to read than imagecreatetruecolor() for me.
  2. No, but then learning PHP just by practice isn't likely to cause anyone any harm...
  3. Plently of people get straight As without doing any work - you can still have a good social life and get good grades.
  4. Indeed. But not fool proof. Hence why the only real solution is full validation of the form data.
  5. I disagree. In England, GCSEs are still a qualification, but they're barely worth the paper their written on.
  6. Ah i love my graphical calculator. I still can't quite believe im actually allowed to use it in exams!
  7. The reason why its needed: You enclose the value of your text box in double quotes, yet your value contains a double quote. So, the browser gets confused. Is it the value supposed to terminate with the first double quote it comes across? That is what it does - it doesn't 'nest' the double quotes - afterall, what would happen if the value contained a single double quote. Therefore, we use the html character codes for the quotes inside things like values of elements.
  8. Well, judging from the output of the array at the bottom, something like this should work: <?php $total = 0; for($x=1;$x<=count($array);$x++){ $total += $array[$x]['totalAfterDiscount'.$x]; } echo $total; ?> Where $array is the name of the array we are wroking with. The code was hugely confusing, so i didn't see what the name of the variable actually was. Also, the use of the number on the end of the array keys (e.g. totalAfterDiscount1) rather defeats the purpose of an array. Anyways, it's not your code, so i don't suppose you care. Next time, use tags(without the spaces)
  9. Yep. Some firewalls and some browsers do block the http_referer. It can also be forged. See this post for a discussion on it: http://www.phpfreaks.com/forums/index.php/topic,165553.0.html The solution: validate your forms properly. Do not rely on any html/javascript validation. Just because you have a select box, dont assume the data is one of the options. Just because you set a maximum size of 2, dont assume thats the maximum length you will recieve etc. As long as you properly validate your form data, it doesn't matter where it comes from.
  10. If that's what you're using the referrer for, then it should be fine. Of course, you could also ask people on the signup form how they heard about the website.
  11. Well, either use the code you posted, or use the reset() and then the key() functions. Not sure if there will be any performance difference between the two methods.
  12. Well, that depends on what you're trying to achieve. If you want the first key, you can reset() the array, and then use the key() function. If you want to find the key of a particular value, use the array_search() function - however, im not sure this is what you want, since you have 3 elements with a value of 1. Why are we selecting the key 4, rather than any of the others? Edit: I think the difference in the two replies highlights the ambiguity of the question!
  13. Using your current code, we run into the same problem as before. Imagine that we are the user who is second in your file. The first time the loop runs, we see the error message. The second time the loop runs, we see the logged in message, followed by the break in the loop. With this sort of method, you have to only throw an error after testing all of the data. As for ===, it is the 'identical to' comparison operator. This means it only evaluates to true if the two things being compared are both equal and of the same type. The standard == equality comparison operator checks value only. For example: <?php $var1 = 0; $var2 = '0'; if($var1 == $var2){ //TRUE 0 is the same as 0 } if($var1 ===$var2){ //FALSE whilst 0 is the same as 0, one of our variables is a string, the other an integer. } ?> The reason why i used the === operator in the code is more habit than anything. I tend to use the identical comparison operator when dealing with booleans (true/false). A standard == operator wouldn't have affected the running of the code in the example i gave. Edit: By way of explaining the need for the 'identical to' operator, see the example here on the use of the strpos() function
  14. Well, the javascript function will be something like: <script type="text/javascript"> function changeimage(image){ document.getElementById('largeimage').src='path/to/images/'+image; } </script> It'll then be a case of giving your large image the ID of 'large image', and adding this piece of code into your image tags: onClick="changeimage('imagetoload.jpg')"
  15. This is a job for javascript not php. You'll need to create a javascript function to modify the source of the large image, which is run when a picture is clicked. You'll pass the name of the image to load to the function.
  16. I think you'll need to do two separate queries. Again, from the php manual "To determine the number of rows that will be returned by a SELECT statement, issue SELECT COUNT(*) with the same predicates as your intended SELECT statement and retrieve the value." Which suggest to me that two separate queries is the way to go. Take a look for yourself: www.php.net/db2_num_rows
  17. I only do this to avoid undefined variable notices - whilst most people run php with error reporting set to ignore notices, i think it's good practice to make your code more compatible. It also seems cleaner to me.
  18. I'd just add an order by RAND() clause on the end of your SQL statment: $expSQL = "SELECT experiences_key FROM experiences_teachers_jn WHERE schools_key = $s ORDER BY RAND() LIMIT 1";
  19. Ah, im with you. Try: <?php $sql = "SELECT COUNT(*) as `number`,`school` FROM `yourtable` GROUP BY `school` ORDER BY `number` DESC"; $result = mysql_query($sql) or die(mysql_error()); while(list($number,$school) = mysql_fetch_row($result)){ echo $school.' : '.$number.'<br />'; } ?> Edit: Ideally you should be storing a school ID in this table, and have a separate table of school names.
  20. Where does that data (e.g. the number) come from?
  21. Eugh, flat files. Anyways,the problem is that you cotinue to look through the loop, even after finding a correct username and password. Imagine it in your head: We loop through line by line. The first time, we check and find a matching username and password - great, so we echo 'logged in'. However, the loop keeps running. It runs again, and the user/password doesn't match - so we echo the failure. And so on. Try: <?php if (isset($_POST['Submit']) ) { if (isset($_POST['name']) && isset($_POST['pass'])) { $name = $_POST['name']; $pword = $_POST['pass']; $lines = file('np.txt'); $data = array(); $loggedin = false; //so far, we've not found a match so the person isn't logged in foreach ($lines as $line) { $data = explode(':', $line); $user = $data[0]; $pass = $data[1]; if ($user == $name && $pass == $pword){ echo 'Logged in!'; $loggedin = true;//now we've found a match - the person's login details are correct break;//break out of the foreach loop - we dont need to look any further } } if($loggedin === false){//lets check if their details were correct echo 'user name and/or password incorrect'; } } } ?>
  22. Try: <?php $quantity = array(1,2,3); $price = array(15.45,12.3,23); $totals = array(); for($x=0;$x<count($quantity);$x++){ $totals[] = $quantity[$x]*$price[$x]; } echo '<pre>'; print_r($totals); echo '</pre>'; ?>
  23. The problem is that you're re-assigning a value to $row with the second while statement. Therefore, after the first time the first while loop has executed, $row has been overwrittin, and so the while loop finishes. Try renaming the second $row to something else.
  24. Well, if you're using a web-based service(e.g. hotmail,yahoo,gmail), you could log into the website with curl() and retrieve the data. I believe there are some tutorials around somewhere about logging into yahoo. For example, see: http://www.weberdev.com/get_example-4277.html If you google, you'll probably find more.
×
×
  • 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.