Jump to content

gschimek

New Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by gschimek

  1. Wow, I feel silly. As soon as you asked about the form, I realized that this simple program from the book wasn't intended for a website. I just ran it from the CLI and it works fine. Thanks!
  2. I've been doing some limited PHP coding for a while, but never really had any training, just learned by searching for specific needs. So I decided to get a book and start from the beginning to see what else PHP can do that I don't know about. Problem is that I can't even get past the first simple program in the book. I'm just supposed to take input from the user and save it to a variable with this line of code: $name = fgets(STDIN); But when I access that page on my webserver, I get this error: Warning: fgets() expects parameter 1 to be resource, string given in /Users/username/Sites/sitename/index.php There's got to be something simple I'm missing, since this is the easiest task in the book. Any help is appreciated. Thanks!
  3. Can I use the data fetched with the mysql_fetch_assoc command more than once? What I'm trying to do is query a MySQL DB, and print a list of the results by gender. So far I've only been able to do it by querying the DB twice, and I know there's got to be a more efficient way. I think I should be able to go through the array once, print all the males, then go through the array again and print all the females. But I'm stumped as to how to do it. Here's basically what I'm doing to get my results: $cxn=mysqli_connect("localhost","username","password","table_name") or die ("Could not connect to database"); $query= "SELECT * FROM blah blah blah"; $result=mysqli_query($cxn,$query) or die ("Couldn't execute query."); while ( $row = mysqli_fetch_assoc($result)) { extract($row); IF ($gender == 'M') { echo "Here is my data for Males"; } } I basically want to re-run the WHILE statement, but check for $gender == 'F', without having to re-run the $result=mysqli_query command again. But when I do that, nothing is displayed and the script ends. Is it just a matter of moving a pointer to the beginning of an array or something similar? Thanks in advance.
  4. I knew it was something simple. Thanks a lot!
  5. I'm pulling my hair out trying to figure out a simple problem. I've got the following PHP code in an HTML page: $shutoff_date = strtotime($wkend_start_date) - 259200; if ($shutoff_date > $todays_date) { $current_month = date("m");$current_year = date("y");$freshman_eligible = 0;if ($current_month >= 2 && $current_month <=7) { $freshman_eligible = 1; }if ($current_month <= 7) { $seniors = $current_year ; } else {$seniors = $current_year + 1; }$juniors = $seniors + 1;$sophomores = $seniors + 2;$freshman = $seniors + 3;echo "HTML Stuff blah, blah, blah";if ($freshman_eligible = 1) {echo "<option value=\"$freshman\">$freshman</option>";}} The last test to see if $freshman_eligible is equal to 1 is always testing true, and it's actually resetting $freshman_eligible to whatever I put inside the IF statement. No matter what the variable is set to previously, it will reset to whatever I test for in the last section, and hence always tests true. I thought maybe it was an issue with scope, but I'm not sure what the issue would be or how to resolve it. What am I missing???
×
×
  • 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.