Problem in Else part

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kavithadevan
    New Member
    • Jul 2007
    • 23

    Problem in Else part

    Hi,
    Here is the script which i am working in this script i am trying to search some events for that i developed this .Its working but if there is no events means i want to display there is no event found like this in else part if i added like this

    else
    {
    echo"No events found"
    }

    it wont consider that is else its displaying else part also from the begining so tell me in this script how to give else part.





    <html>
    <form name="form1" method="post" action="">
    <p>&nbsp;</p>
    <table width="200" border="0" align="center">
    <tr>
    <td>Select </td>
    <td><?php
    //here can give any range, even a to z, jan to dec etc
    $a = range(01,31);

    //var_dump($a);

    echo'<select name="date">';

    foreach($a as $date)
    {

    echo'<option>'. $date.'</option>';

    }

    echo'</select>';


    $a = range(01,12);

    //var_dump($a);

    echo'<select name="month">';

    foreach($a as $month)
    {

    echo'<option>'. $month.'</option>';

    }

    echo'</select>';
    $a = range(2000,2010 );

    //var_dump($a);

    echo'<select name="year">';

    foreach($a as $year)
    {

    echo'<option>'. $year.'</option>';

    }
    echo'</select>';
    ?>&nbsp;</td>
    </tr>
    </table>
    <p align="center">
    <input type="submit" name="Submit" value="Submit">
    </p>
    <p align="center"> &nbsp;</p>
    <p align="center"> &nbsp; </p> <br>
    <table width="900" border="0" align="center">
    <div align="center"> <b>Search Details</b></div>
    <tr bgcolor="#E1E1E 1">
    <td width="246">Eve nts</td>
    <td width="246">Cou ntryname</td>
    <td width="215">Dat e</td>
    <td width="217">Mon th</td>
    <td width="194">Yea r</td>
    </tr>
    <?PHP
    include('connec t.php');
    if($_POST['Submit'])
    {

    $edit="select * from addevent where date='$_POST[date]' AND month='$_POST[month]'";
    echo $edits=mysql_qu ery($edit);
    //$row = mysql_fetch_row ($edits);
    $number = mysql_num_rows( $edits);
    while ($rows=mysql_fe tch_assoc($edit s))
    {
    print "<tr bgcolor=\"#CCCC CC\">
    <td bgcolor=\"#FFFF FF\">" . $rows['event'] ."</td>
    <td bgcolor=\"#FFFF FF\">" .$rows['countryname'] ."</td>
    <td bgcolor=\"#FFFF FF\">" .$rows['date'] . "</td>
    <td bgcolor=\"#FFFF FF\">" .$rows['month'] . "</td>
    <td bgcolor=\"#FFFF FF\">" . $rows['year'] . "</td>
    </tr>";
    }
    echo"<B>Totally $number events are found</B><br>";
    }
    //var_dump(($_POS T['date'])!=$edif['date']);
    ?>
    </table>
    <p>&nbsp;</p>
    </form>
    </html>
  • kvijayhari
    New Member
    • Jul 2007
    • 24

    #2
    hi

    $edit="select * from addevent where date='$_POST[date]' AND month='$_POST[month]'";
    echo $edits=mysql_qu ery($edit);
    $number = mysql_num_rows( $edits);
    if($number!=0) // here the number of rows returned by the query is checked //and then process is continued
    {
    while ($rows=mysql_fe tch_assoc($edit s))
    {
    print "<tr bgcolor=\"#CCCC CC\">
    <td bgcolor=\"#FFFF FF\">" . $rows['event'] ."</td>
    <td bgcolor=\"#FFFF FF\">" .$rows['countryname'] ."</td>
    <td bgcolor=\"#FFFF FF\">" .$rows['date'] . "</td>
    <td bgcolor=\"#FFFF FF\">" .$rows['month'] . "</td>
    <td bgcolor=\"#FFFF FF\">" . $rows['year'] . "</td>
    </tr>";
    }
    echo"<B>Totally $number events are found</B><br>";
    }
    else
    echo"<B>No events are found</B><br>";

    //var_dump(($_POS T['date'])!=$edif['date']);
    ?>



    Try this change and then come again if any doubts persists

    Comment

    • kavithadevan
      New Member
      • Jul 2007
      • 23

      #3
      if i give like wat u send it shows error but if i give
      else
      {
      echo "no events found";
      }

      like this but its not working (else part is not working).can u tell me some other idea

      thanks



      Originally posted by kvijayhari
      hi

      $edit="select * from addevent where date='$_POST[date]' AND month='$_POST[month]'";
      echo $edits=mysql_qu ery($edit);
      $number = mysql_num_rows( $edits);
      if($number!=0) // here the number of rows returned by the query is checked //and then process is continued
      {
      while ($rows=mysql_fe tch_assoc($edit s))
      {
      print "<tr bgcolor=\"#CCCC CC\">
      <td bgcolor=\"#FFFF FF\">" . $rows['event'] ."</td>
      <td bgcolor=\"#FFFF FF\">" .$rows['countryname'] ."</td>
      <td bgcolor=\"#FFFF FF\">" .$rows['date'] . "</td>
      <td bgcolor=\"#FFFF FF\">" .$rows['month'] . "</td>
      <td bgcolor=\"#FFFF FF\">" . $rows['year'] . "</td>
      </tr>";
      }
      echo"<B>Totally $number events are found</B><br>";
      }
      else
      echo"<B>No events are found</B><br>";

      //var_dump(($_POS T['date'])!=$edif['date']);
      ?>



      Try this change and then come again if any doubts persists

      Comment

      • dafodil
        Contributor
        • Jul 2007
        • 389

        #4
        Originally posted by kavithadevan
        Hi,
        Here is the script which i am working in this script i am trying to search some events for that i developed this .Its working but if there is no events means i want to display there is no event found like this in else part if i added like this

        else
        {
        echo"No events found"
        }

        it wont consider that is else its displaying else part also from the begining so tell me in this script how to give else part.




        ...............
        ..............
        How about replacing echo"<B>Totally $number events are found</B><br>";
        with these:

        If($number!=0){
        echo"<B>Totally $number events are found</B><br>";}
        else
        {
        echo"No events found";
        }

        Comment

        • kavithadevan
          New Member
          • Jul 2007
          • 23

          #5
          Hi,
          thank u
          now my code is working with else part
          Originally posted by dafodil
          How about replacing echo"<B>Totally $number events are found</B><br>";
          with these:

          If($number!=0){
          echo"<B>Totally $number events are found</B><br>";}
          else
          {
          echo"No events found";
          }

          Comment

          • kavithadevan
            New Member
            • Jul 2007
            • 23

            #6
            Hi


            Again i got the problem that is else part is working but if i give like this


            if($total!=0)
            {
            echo"<B>Totally $total events are found</B><br>";
            }
            else
            {
            echo"<center><b >no events found</b>";
            }

            if i run the search script then it shows no events found (without clicking submit) button but after clicking submit button if there is no records then only i want to display no found pls help me how to do this.If i gave if($_POST['submit']) its working.How to give else part without using $_POST['submit']
            help me
            thanks

            Originally posted by kavithadevan
            Hi,
            thank u
            now my code is working with else part

            Comment

            Working...