0

I have a tabled view in a while loop, where a user can view information on books.

For example, book ISBN, book name, read status...

Basically, when the user sets their 'readstatus' to 'complete' I want that specific table row to become grey! The logic is very straight forward, however I can't get my IF statement to recognise this:

if ($readstatus == 'complete') {
                        echo '<tr class="completed">';
              }

                    else if  ($readstatus != 'complete') {
                        echo '<tr class="reading">';
              } 

I'm obviously doing something wrong here, table content to change if the value of 'readstatus' = 'complete', if not, then output is the default

6
  • This is not answering the question, but you're equally well doing if( a ) { ... } else { ... }, without the test which should obviously return true. Commented Mar 19, 2010 at 12:54
  • Do you have your if sdtatement inside of the loop or, as it stated above, right under $readstatus = $_GET['readstatus']; ? Commented Mar 19, 2010 at 12:54
  • The if statement should at least enter one of the clauses; which one does it enter? Commented Mar 19, 2010 at 12:55
  • its right under the variable declaration (as stated above) Commented Mar 19, 2010 at 12:56
  • it enters the last clause being '!=' Commented Mar 19, 2010 at 12:56

4 Answers 4

1

Why are you using $_GET? Does this information come from an HTML form or a URL etc... ?

I suspect you meant to change $readstatus = $_GET['readstatus']; to $readstatus = $row['readstatus'];.

$_GET is an aray of GET parameters which come from the query string.

$row is a row in your database, so if the information is in the database - which I suspect it is - you want to use $row instead of $_GET.

Sign up to request clarification or add additional context in comments.

Comments

1

Try changing $readstatus = $_GET['readstatus']; to $readstatus = $row['readstatus'];

Comments

0

The $_GET function relies on the value being contained in the query string of the URL, and it has nothing to do with the database. I have a hunch you're trying to get the value from the database here and you're using the wrong function to do it.

1 Comment

$_GET isn't a function though ;)
0

$_GET['readstatus'] says the value is coming from the browser. $row['readstatus'] says the value is coming from the database.

You need to decide which should take precedence-- probably the $_GET['readstatus']` because it's what the user wants to change. If that's the case, you need to update your database with the new readstatus before you requery the db for the dataset.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.