0

I currently have this code that's working just fine:

while ($row = mysqli_fetch_array($popupResult)) {
  $popupQuote     = $row['quoteNumber'];
  $popupExp       = $row['quoteCustomer'];
  $popupCost      = $row['quoteExpirationDate'];
  }

My only issue is that the data in my table that contains what I want in $popupQuote COULD have quoteNumber populated, or it could have debitNumber populated - but it will never have both. I need this basically:

  $popupQuote     = $row['quoteNumber'] or $row['debitNumber']

If I use $popupQuote = $row['quoteNumber'];, I get 6 results. If I use $popupQuote = $row['debitNumber']; I can 4 results. I want the output to display all 10 results in a single variable.

1
  • Thanks for the edit... darn copy & paste :) Commented Dec 18, 2014 at 17:02

3 Answers 3

3

If you guarantee that one of the two fields will always be populated, and never will there be a record with both or neither, then:

$poupQuote = !empty($row['quoteNumber']) ? $row['quoteNumber'] : $row['debitNumber'];

e.g. check if quotenumber has a value. if it does, use that value, otherwise use the debitnumber. Of course, you'll probably want some better checking, since empty() will bite you in the rump if quotenumber can be 0 - empty(0) is true.

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

1 Comment

There needs to be a closing bracket though on ['quoteNumber']
0

Use a conditional expression:

$popupQuote = $row['quoteNumber'] ? $row['quoteNumber'] : $row['debitNumber'];

Comments

0

What you need is a Ternary operator

And test if there is a value

$popupQuote = ($row['quoteNumber'] != "") ? $row['quoteNumber'] : $row['debitNumber'];

2 Comments

isset wouldn't work. the field will always be present in the result row... it just might not have a value.
Oh, I see you have something similar.

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.