175 users online (0 members and 175 guests)  

Thread: PHP question


  Results 1 to 3 of 3

Related

  1. css question    Forum: CSS Forum
    Replies: 2
  2. Yet another question?    Forum: HTML Forum
    Replies: 3
  3. AnOtHeR QuEsTiOn    Forum: HTML Forum
    Replies: 1
  4. Question    Forum: HTML Forum
    Replies: 2
  5. another question...    Forum: HTML Forum
    Replies: 6
  1. #1
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    PHP question

    hello,

    i'm working on a small scale journal program written in PHP. i've been reading a few tut's and i peiced together a script that's working fairly well.

    there's something i'm trying to do but can't figure out. when the user inputs an entry there's 5 entries for the database: subject, entry, mood, music, timestamp.

    it's displaying everything fine, prints like:

    subject
    entry


    mood: mood
    music: music

    BUT, if the user doesn't input a 'mood' the i don't want the "mood:" to print.

    i'm not sure how to code this.

    here's what i have for the display page...

    Code:
    // generate and execute query
    $query = "SELECT subject, entry, mood, music, timestamp FROM robert_journal WHERE id = '$id'";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
    
    // get resultset as object
    $row = mysql_fetch_object($result);
    
    
    // print details
    if ($row)
    {
    ?>
    	<p>
    	<b><? echo $row->subject; ?></b>
    	<p>
    	<font size="-1"><? echo nl2br($row->entry); ?></font>
    	<p><br>
    	mood: <? echo $row->mood; ?><br>
    	<br>
    	music: <? echo $row->music; ?><br>
    
    	<font size="-2"><? echo formatDate($row->timestamp); ?>. For more information, please contact <? echo $name ?></font>
    <?
    }
    else
    {
    ?>
    	<p>
    	<font size="-1">That press release could not be located in our database.</font>
    robert koons

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    hello again,

    Easiest was would be to check the the db variable is not empty, and dont display if it isn't

    Code:
    if ($row->mood != "")
    {
    ?>
    mood: <? echo $row->mood; ?><br>
    	<br>
    <?
    }
    The 'proper' way is to use isset to check for it, but not sure it would work. Try it first, if it doesnt work use above -

    Code:
    if (isset($row->mood))
    {
    ?>
    mood: <? echo $row->mood; ?><br>
    	<br>
    <?
    }

    I have not checked this code, written quickly while I am cooking dinner please point out any typos
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76
    i tried the "proper" way, but the "easier" way worked.

    i'm sure i'll be stuck again soon...

    thanks for the help!
    robert koons



Tags for this Thread