php querying

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vinnie

    php querying

    where is the error in a query performed with php in this script?

    <?php
    @ $db=mysql_pconn ect('localhost' , 'database_name' , 'password');
    if (!$db)
    {
    echo 'conneciton eror';
    exit;
    }
    else
    {
    echo 'connection on!';
    }
    mysql_select_db ('books'); //books: table created previously.
    $query="select * from orders"; //orders: a table that i have
    previosly created.
    $result=mysql_q uery($query);
    $num_results=my sql_num_rows($r esult);
    if ($num_results = 0)
    {
    echo'<br><br>no thing to dispaly';
    }
    else
    {
    echo'<br><br>he re are the results: $num_results';
    }
    ?>

  • SrSilveira

    #2
    Re: php querying

    On Jun 4, 12:36 pm, vinnie <centro.ga...@g mail.comwrote:
    where is the error in a query performed with php in this script?
    >
    <?php
    @ $db=mysql_pconn ect('localhost' , 'database_name' , 'password');
    if (!$db)
    {
    echo 'conneciton eror';
    exit;
    }
    else
    {
    echo 'connection on!';
    }
    mysql_select_db ('books'); //books: table created previously.
    $query="select * from orders"; //orders: a table that i have
    previosly created.
    $result=mysql_q uery($query);
    $num_results=my sql_num_rows($r esult);
    if ($num_results = 0)
    {
    echo'<br><br>no thing to dispaly';}
    >
    else
    {
    echo'<br><br>he re are the results: $num_results';}
    >
    ?>
    wrong: if ($num_results = 0)

    right: if ($num_results == 0)

    Comment

    • vinnie

      #3
      Re: php querying

      >
      wrong: if ($num_results = 0)
      >
      right: if ($num_results == 0)
      ok, but why i don't get any results from the query?

      Comment

      • Geoff Berrow

        #4
        Re: php querying

        Message-ID: <1180971416.170 450.273360@k79g 2000hse.googleg roups.comfrom
        vinnie contained the following:
        >where is the error?
        Here
        >if ($num_results = 0)
        = is the assignment operator. You will never display any results since
        this will always evaluate to true.

        Try
        if ($num_results <1)
        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Geoff Berrow

          #5
          Re: php querying

          Message-ID: <1180973062.594 104.39810@m36g2 000hse.googlegr oups.comfrom
          vinnie contained the following:
          >
          >>
          > wrong: if ($num_results = 0)
          >>
          > right: if ($num_results == 0)
          >
          >ok, but why i don't get any results from the query?
          Change this
          echo'<br><br>he re are the results: $num_results';
          to this
          echo '<br><br>here are the results: '.$num_results;

          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • vinnie

            #6
            Re: php querying

            Change this
            echo'<br><br>he re are the results: $num_results';
            to this
            echo '<br><br>here are the results: '.$num_results;
            >
            thanks Geoff, it works perfectly now. But what's the difference? Is
            not the same thing?

            Comment

            • Denis Gerina

              #7
              Re: php querying

              vinnie wrote:
              >Change this
              >echo'<br><br>h ere are the results: $num_results';
              >to this
              >echo '<br><br>here are the results: '.$num_results;
              >>
              >
              thanks Geoff, it works perfectly now. But what's the difference? Is
              not the same thing?
              >
              The difference is that unlike double-quoted strings, single-quoted
              strings do not replace variable names inside the quotes with variable
              values. The version that works concatenates your string with the value
              of $num_results variable.

              You could also have written

              echo "<br><br>he re are the results: $num_results";

              Comment

              • Geoff Berrow

                #8
                Re: php querying

                Message-ID: <46647c6a$1@new s.bihnet.bafrom Denis Gerina contained the
                following:
                >thanks Geoff, it works perfectly now. But what's the difference? Is
                >not the same thing?
                >>
                >
                >The difference is that unlike double-quoted strings, single-quoted
                >strings do not replace variable names inside the quotes with variable
                >values. The version that works concatenates your string with the value
                >of $num_results variable.
                What he said.

                --
                Geoff Berrow (put thecat out to email)
                It's only Usenet, no one dies.
                My opinions, not the committee's, mine.
                Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                Comment

                Working...