what do you think, why that?

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

    #1

    what do you think, why that?

    it only displays the name, but the last name and the address seems not
    to exist! why?

    <?php
    @ $db=mysql_pconn ect('host', 'UserID', 'PWD');
    if (!$db)
    {
    echo 'conneciton eror';
    exit;
    }
    else
    {
    echo 'connection on!';
    }
    mysql_select_db ('list');
    $query="select * from index";
    $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;
    }
    for ($i<0; $i<$num_results ; $i++)
    {
    $row=mysql_fetc h_array($result );
    echo '<br>name: ';
    echo htmlspecialchar s(stripslashes( $row['name']));
    echo '<br>last name: ';
    echo htmlspecialchar s(stripslashes( $row['last']));
    }
    ?>

  • Floortje

    #2
    Re: what do you think, why that?

    vinnie wrote:
    it only displays the name, but the last name and the address seems not
    to exist! why?
    echo '<br>name: ';
    echo htmlspecialchar s(stripslashes( $row['name']));
    echo '<br>last name: ';
    echo htmlspecialchar s(stripslashes( $row['last']));
    Because you tell the script to display the name, not the adres

    try var_dump($row); to see what's in the row

    Comment

    • Denis Gerina

      #3
      Re: what do you think, why that?

      vinnie wrote:
      it only displays the name, but the last name and the address seems not
      to exist! why?
      >
      <?php
      @ $db=mysql_pconn ect('host', 'UserID', 'PWD');
      if (!$db)
      {
      echo 'conneciton eror';
      exit;
      }
      else
      {
      echo 'connection on!';
      }
      mysql_select_db ('list');
      $query="select * from index";
      $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;
      }
      for ($i<0; $i<$num_results ; $i++)
      {
      $row=mysql_fetc h_array($result );
      echo '<br>name: ';
      echo htmlspecialchar s(stripslashes( $row['name']));
      echo '<br>last name: ';
      echo htmlspecialchar s(stripslashes( $row['last']));
      }
      ?>
      >
      You don't seem to be printing address anywhere. As for last name, check
      the name of the column in your table (index).

      And, to avoid notices, the code

      for ($i<0; $i<$num_results ; $i++)

      should be

      for ($i=0; $i<$num_results ; $i++)


      Although I would probably write something like

      while ($row = mysql_fetch_arr ay($result))
      {
      ....
      }

      Comment

      • mypetprogrammer@gmail.com

        #4
        Re: what do you think, why that?

        On Jun 4, 5:53 pm, Denis Gerina <denisREMOVET.. .@cced.bawrote:
        vinnie wrote:
        it only displays the name, but the last name and the address seems not
        to exist! why?
        >
        <?php
        @ $db=mysql_pconn ect('host', 'UserID', 'PWD');
        if (!$db)
        {
        echo 'conneciton eror';
        exit;
        }
        else
        {
        echo 'connection on!';
        }
        mysql_select_db ('list');
        $query="select * from index";
        $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;
        }
        for ($i<0; $i<$num_results ; $i++)
        {
        $row=mysql_fetc h_array($result );
        echo '<br>name: ';
        echo htmlspecialchar s(stripslashes( $row['name']));
        echo '<br>last name: ';
        echo htmlspecialchar s(stripslashes( $row['last']));
        }
        ?>
        >
        You don't seem to be printing address anywhere. As for last name, check
        the name of the column in your table (index).
        >
        And, to avoid notices, the code
        >
        for ($i<0; $i<$num_results ; $i++)
        >
        should be
        >
        for ($i=0; $i<$num_results ; $i++)
        >
        Although I would probably write something like
        >
        while ($row = mysql_fetch_arr ay($result))
        {
        ...
        >
        }
        See, and I would avoid the inevitable out of bounds on that with:
        while( ($row = mysql_fetch_arr ay($result)) != null)
        {

        So as not to be operating on a null on the last iteration of the loop.
        Agree with the while, though.

        ~A!

        Comment

        • Denis Gerina

          #5
          Re: what do you think, why that?

          mypetprogrammer @gmail.com wrote:
          On Jun 4, 5:53 pm, Denis Gerina <denisREMOVET.. .@cced.bawrote:
          >vinnie wrote:
          >>it only displays the name, but the last name and the address seems not
          >>to exist! why?
          >><?php
          >>@ $db=mysql_pconn ect('host', 'UserID', 'PWD');
          >>if (!$db)
          >> {
          >> echo 'conneciton eror';
          >> exit;
          >> }
          >>else
          >> {
          >> echo 'connection on!';
          >> }
          >>mysql_select_ db('list');
          >>$query="selec t * from index";
          >>$result=mysql _query($query);
          >>$num_results= mysql_num_rows( $result);
          >>if ($num_results == 0)
          >>{
          >> echo'<br><br>no thing to dispaly';
          >>}
          >>else
          >>{
          >> echo'<br><br>he re are the results: '.$num_results;
          >>}
          >> for ($i<0; $i<$num_results ; $i++)
          >>{
          >> $row=mysql_fetc h_array($result );
          >> echo '<br>name: ';
          >> echo htmlspecialchar s(stripslashes( $row['name']));
          >> echo '<br>last name: ';
          >> echo htmlspecialchar s(stripslashes( $row['last']));
          >>}
          >>?>
          >You don't seem to be printing address anywhere. As for last name, check
          >the name of the column in your table (index).
          >>
          >And, to avoid notices, the code
          >>
          > for ($i<0; $i<$num_results ; $i++)
          >>
          >should be
          >>
          > for ($i=0; $i<$num_results ; $i++)
          >>
          >Although I would probably write something like
          >>
          >while ($row = mysql_fetch_arr ay($result))
          >{
          >...
          >>
          >}
          >
          See, and I would avoid the inevitable out of bounds on that with:
          while( ($row = mysql_fetch_arr ay($result)) != null)
          {
          >
          So as not to be operating on a null on the last iteration of the loop.
          Agree with the while, though.
          >
          ~A!
          >
          Interesting. Do explain, please, in light of the docs.


          Fetch a result row as an associative array, a numeric array, or both


          Returns an array of strings that corresponds to the fetched row, or
          FALSE if there are no more rows.

          Comment

          • Jerry Stuckle

            #6
            Re: what do you think, why that?

            mypetprogrammer @gmail.com wrote:
            On Jun 4, 5:53 pm, Denis Gerina <denisREMOVET.. .@cced.bawrote:
            >vinnie wrote:
            >>it only displays the name, but the last name and the address seems not
            >>to exist! why?
            >><?php
            >>@ $db=mysql_pconn ect('host', 'UserID', 'PWD');
            >>if (!$db)
            >> {
            >> echo 'conneciton eror';
            >> exit;
            >> }
            >>else
            >> {
            >> echo 'connection on!';
            >> }
            >>mysql_select_ db('list');
            >>$query="selec t * from index";
            >>$result=mysql _query($query);
            >>$num_results= mysql_num_rows( $result);
            >>if ($num_results == 0)
            >>{
            >> echo'<br><br>no thing to dispaly';
            >>}
            >>else
            >>{
            >> echo'<br><br>he re are the results: '.$num_results;
            >>}
            >> for ($i<0; $i<$num_results ; $i++)
            >>{
            >> $row=mysql_fetc h_array($result );
            >> echo '<br>name: ';
            >> echo htmlspecialchar s(stripslashes( $row['name']));
            >> echo '<br>last name: ';
            >> echo htmlspecialchar s(stripslashes( $row['last']));
            >>}
            >>?>
            >You don't seem to be printing address anywhere. As for last name, check
            >the name of the column in your table (index).
            >>
            >And, to avoid notices, the code
            >>
            > for ($i<0; $i<$num_results ; $i++)
            >>
            >should be
            >>
            > for ($i=0; $i<$num_results ; $i++)
            >>
            >Although I would probably write something like
            >>
            >while ($row = mysql_fetch_arr ay($result))
            >{
            >...
            >>
            >}
            >
            See, and I would avoid the inevitable out of bounds on that with:
            while( ($row = mysql_fetch_arr ay($result)) != null)
            {
            >
            So as not to be operating on a null on the last iteration of the loop.
            Agree with the while, though.
            >
            ~A!
            >
            Denis's code is correct. There will be no out of bounds error in Denis's
            code.

            mysql_fetch_arr ay() is a function which returns either an array or
            false. It does not return null. Denis's code will continue to fetch
            rows as long as the exist; after the last row has been fetched, the next
            call to mysql_fetch_arr ay() returns false, stopping the loop.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            Working...