Jump to content


Photo

Possibly a problem with my logical operators?


  • Please log in to reply
2 replies to this topic

#1 contrabandheart

contrabandheart
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 10 September 2006 - 06:16 PM

So. Here's my problem. The first section of my code(Ex. 1) works properly. It displays how it should (it echos all of the correct information, it displays properly, etc.)
Ex. 1:
     if(!isset($entry_year) and !isset($entry_month)){
      echo "<p>Select the year and entry that you posted the entry you want to edit from below...</p>\n";
      $sql = "SELECT DISTINCT entry_year,entry_month FROM `entries` ORDER BY `entry_year` AND `entry_month` ASC;";
      $result = mysql_query($sql) or die(mysql_error());
      while($qd = mysql_fetch_row($result)){
       echo "<p><a href='" . $REQUEST_URI . "&entry_year=$qd[0]&entry_month=$qd[1]'>$qd[0] | " . $month[$qd[1]] . "</a></p>\n";
      }

It's the second section of code(Ex. 2), which should find and display the relevent information from the database, based on the "entry_year" and "entry_month" columns.
Ex. 2:
      $sql = "SELECT entry_id,entry_year,entry_month,entry_day,entry_title FROM `entries` WHERE `entry_year` = '$entry_year' AND `entry_month` = '$entry_month' ORDER BY `entry_id` ASC;";
      $result = mysql_query($sql) or die(mysql_error());
      while($qd = mysql_fetch_row($result)){
       "<p><a href='" . $REQUEST_URI . "?entry_id=$qd[0]'><strong>$qd[3] " . $month[$qd[2]] . ", $qd[1]</strong> | &quot;$qd[4]&quot;</a></p>\n";

I know it's not a MySQL connection problem, because the first section works correctly. The only thing I can figure is that my operators (my "||"s and "and"s) are configured incorrectly. Any help is appreciated.

Complete Code:
   elseif($action == "editentry"){
    connect2db("cass_blog");
    echo "<h2>Edit Blog Entry</h2>\n";
    if(!isset($entry_id) || empty($entry_id)){
     if(!isset($entry_year) and !isset($entry_month)){
      echo "<p>Select the year and entry that you posted the entry you want to edit from below...</p>\n";
      $sql = "SELECT DISTINCT entry_year,entry_month FROM `entries` ORDER BY `entry_year` AND `entry_month` ASC;";
      $result = mysql_query($sql) or die(mysql_error());
      while($qd = mysql_fetch_row($result)){
       echo "<p><a href='" . $REQUEST_URI . "&entry_year=$qd[0]&entry_month=$qd[1]'>$qd[0] | " . $month[$qd[1]] . "</a></p>\n";
      }
     } else {
      $sql = "SELECT entry_id,entry_year,entry_month,entry_day,entry_title FROM `entries` WHERE `entry_year` = '$entry_year' AND `entry_month` = '$entry_month' ORDER BY `entry_id` ASC;";
      $result = mysql_query($sql) or die(mysql_error());
      while($qd = mysql_fetch_row($result)){
       "<p><a href='" . $REQUEST_URI . "?entry_id=$qd[0]'><strong>$qd[3] " . $month[$qd[2]] . ", $qd[1]</strong> | &quot;$qd[4]&quot;</a></p>\n";
      }
     }
    }

You are the weakest Uniform Resource Locator... Goodbye.

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 10 September 2006 - 06:57 PM

2 things:

1) make sure all the variables that you are doing conditioning on are holding what you expect them to (or not to be) holding, by echoing them out before your conditions.  Your conditions may be failing because the variables are not holding what they are supposed to be holding.  If this is the case, then the bug is not in your conditions, but somewhere else, like not setting the variables correctly or something.

2) in order for us to even begin to guess whether your conditions are correct, you are going to have to explain what all the variables are supposed to be for, and what exactly you're trying to accomplish with these conditions.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 contrabandheart

contrabandheart
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 September 2006 - 09:08 PM

Eh. I just took a good, long look at my code and realized what the problem was. I accidentally closed out a block before I should have, and set the wrong trigger.

And Crayon Violent, I'm sorry for making those mistakes in my post (those are actually my pet peeves as well).

Thanks for taking the effort to at least read the post.
You are the weakest Uniform Resource Locator... Goodbye.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users