|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
Some MySQL and PHP code not working as it should
I am trying to get my webpage to list titles of articles in a select box on an HTML form. THe only ones that should be showing are those of three types. Yet it still shows every article. HERE is the Code
PHP Code:
As far as I can tell it should work. I have echoed out the type on the initial query and it kept grabbing the correct article first.But when I click on the arrow to show the choices it shows me all the articles from the first row it grabs to the last article in the DB no matter what type of article it is
__________________
CHornJr "One day I'll know what I am doing" ![]() My Blog Suanhacky Lodge #49 Rebel Squadrons |
|
#2
|
|||
|
|||
|
Try changing this line:
PHP Code:
to this: PHP Code:
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
||||
|
||||
|
That did not solve the problem but it didn't make things worse as far as I can tell either.
My best guess is that my error is somewhere in the if statement. PHP Code:
Last edited by CHornJr : June 26th, 2003 at 11:19 PM. |
|
#4
|
||||
|
||||
|
Now I am certain it is teh If statement
I set up a quick page for debugging this code using similar code as to my original except there is no form. Here is the first batch of code I used PHP Code:
This code produced the same results as when I had the form. It got the first row correct but then showed all the subsequent rows no matter what type it should be showing Here is the second set of code I used PHP Code:
This gave me a blank page. To me this means it is not evaluating properly the statement in the parenthesis '()' of the if statement . I unfortunetly have no lcue as to why On the Database column type is a tinyint with a length of 1 'tinyint(1)' and is unsigned and indexed. |
|
#5
|
||||
|
||||
|
Yahoo! I got it working properly
I started playing around with it some more and started looking through the PHP manual to see if I can find why it wasn't working. I read the while statement info and in the comments someone mentioned while loops with brackets didn't work but it did with the alternative syntax. It gave me the same results. Then I tried a do...while loop. Same results as witht he while loop. I then tried using a switch statement. At first it gave me a problem the seconde time around it almost worked corectly. in the DB right now there were 6 articles that matched the type and it gave the first 3 that matched the type twice (ie. article 1, article 1, article 2, article 2) then just reading around I found out (which I didn't know before cause I didn't have need to use it) that php supported break statements and I got it to work. here is the final code I ended up with PHP Code:
I posted this code so if anyone has this problem in the future with nesting if statements in while loops an answer is already here for them to refer to. I do have a question however. Have any of you nested if statements in while loops and got it to work correctly (with either normal or alternative syntax) just out of curiosity |
|
#6
|
|||
|
|||
|
Yes, actually, what you were doing should have worked. I've written code similar and had it work.
I'll see if I can find some. In the meantime, I think your original problem could have been solved making absolute sure you were evaluating equality between the same types. The easiest way to accomplish this for me is to just do a var_dump on any questionable type. In your case: PHP Code:
would be a good start. If it comes back as anything other than an integer you have found your original problem. |
|
#7
|
|||
|
|||
|
In looking at your code even further, I can see that your new code is better. A case statement does better delimit your statements and allows for better flow.
Simply put, it is just better code IMHO. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Some MySQL and PHP code not working as it should |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|