[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

PHP Question

The attached code pulls data from a MySQL database & displays it in a browser. As you can see in the code, "'.$row[15].'" usually has data in the database but rows 16 - 19 may not all of the time...My question is, is there any way for me to edit this code so it will pulls the data out of the database if there is text in there, but if no I need to have N/A displayed in this field....any help will be appreciated!
<td>
<br>
<b>Who is Responsible for the 1st Sent Date Change? <input type="text" value = "'.$row[15].'"> 
</select> </td>
<br>
<td>
<b>Who is Responsible for the 2nd Sent Date Change? <input type="text" value = "'.$row[16].'">
</select> </td>
</tr>
<br>
<td>
<b>Who is Responsible for the 3rd Sent Date Change? <input type="text" value = "'.$row[17].'"> 
</select> </td>
</tr>
<br>
<b>Who is Responsible for the 4th Sent Date Change? <input type="text" value = "'.$row[18].'"> 
</select> </td>
</tr>
<br>
<b>Who is Responsible for the 5th Sent Date Change? <input type="text" value = "'.$row[19].'"> 
</select> </td>
</tr>
<br>

Open in new window

0
wantabe2
Asked:
wantabe2
  • 2
1 Solution
 
Ray PaseurCommented:
Might help if we could see the rest of the code and the CREATE TABLE statement.

One design might be to initialize all of the positions of the $row array with 'N/A' then copy the positions that are not NULL to overwrite the corresponding positions.
0
 
zappafan2k2Commented:
Have a look at the COALESCE function
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_coalesce

If row 16 were named row_16, then it may look something like this:
select COALESCE(`row_16`, 'N/A') as row_16  from ...

Open in new window

0
 
zappafan2k2Commented:
I should have mentioned that COALESCE will work if the field is NULL.  If it is an empty string, i.e. '', then you should use the CASE operator
http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#operator_case
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now