Forum Moderators: coopster

Message Too Old, No Replies

Selectively showing dynamic text

PHP&MySQL dynamic text

         

megajam02

6:45 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



This is another one that has been a thorn in my side..

Lets say, for example that I have 4 columns in my recordset:

id, event_name, event_location, event_charge

Now, I want to query the table and display the records with dynamic text on a page like so:

Event Name: User Group Meeting
Event Location: Hawaii
Event Charge: $100

If there is no value in the event_charge field, I'd like to not display either the event_charge value or the "Event Charge:" label on the page, because it's just not needed. I have been able to figure out how to not show the entire row if something is blank, but can anyone point me in the correct direction for not showing a particular column of a row? I'm using PHP.

I have been attempting to do this with an if statement, but so far that hasnt worked out.

Does this make sense?

Thanks,
Chris

lorax

6:53 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if ($result_array['eventcharge']!= "")
echo "<tr><td>Event Charge</td><td>$result_array['eventcharge']</td></tr>";

This would go inside the loop where you're iterating through the results. The var $result_array is derived from the mysql_fetch_array() function:

$result_array = mysql_fetch_array($resourceid);

vincevincevince

8:40 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



your exisitng table </tr>
".(($result[event_charge])?("<tr><td>...blah ".$result[event_charge]." blah </td></tr>))." the rest of your table

the (condition)?(True):(False) construct is an inline IF statement