Help in displaying all the record instead of 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rocky86
    New Member
    • Jun 2007
    • 93

    Help in displaying all the record instead of 1

    Hi ppl I need help with my php basically I manage to get my php to display the uname that matches the sql condition however it only return 1 record when there are 2 record that match the condition how do I make it display all record that matches the condition instead of displaying just one?
    This is my code:
    [PHP]
    $resultpostal=m ysql_query("SEL ECT location.uname, location.uid FROM location,distri cts WHERE districts.distr ictno ='56' AND
    location.lat BETWEEN districts.start lat AND districts.endla t AND location.lng BETWEEN districts.start lng AND districts.endln g");

    $counterx=0;
    if($row=mysql_f etch_array($res ultpostal)){
    foreach($row as $col_value){
    $temp[$counterx]=$col_value;
    $counterx++;
    }





    $report.="uid". "=".$temp[0]."&";
    $report.="uname "."=".$temp[1]."&";




    echo $report;


    [/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Rocky.

    Change this line:
    [code=php]
    if($row=mysql_f etch_array($res ultpostal)){
    [/code]

    to:
    [code=php]
    while($row=mysq l_fetch_assoc($ resultpostal)){
    [/code]

    s/if/while/
    s/array/assoc/

    Comment

    • Rocky86
      New Member
      • Jun 2007
      • 93

      #3
      Originally posted by pbmods
      Heya, Rocky.

      Change this line:
      [code=php]
      if($row=mysql_f etch_array($res ultpostal)){
      [/code]

      to:
      [code=php]
      while($row=mysq l_fetch_assoc($ resultpostal)){
      [/code]

      s/if/while/
      s/array/assoc/

      Hey pbmods I did what you mention but it does not seen to work at all it just basically return me the value "3"

      while($row=mysq l_fetch_array($ resultpostal)){

      After I change back then it still return me one record but when I do a testing on the SQL statement it return me 2 record but in php it just return me 1

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Rocky.

        Let's organize your code real quick:

        [code=php]
        $temp = array();

        while($row = mysql_fetch_ass oc($resultposta l))
        {
        $temp[] = $row;
        }

        print_r($temp);
        [/code]

        Put this right after your MySQL query and get rid of everything else below it.

        Comment

        • Rocky86
          New Member
          • Jun 2007
          • 93

          #5
          Originally posted by pbmods
          Heya, Rocky.

          Let's organize your code real quick:

          [code=php]
          $temp = array();

          while($row = mysql_fetch_ass oc($resultposta l))
          {
          $temp[] = $row;
          }

          print_r($temp);
          [/code]

          Put this right after your MySQL query and get rid of everything else below it.
          I did as you suggest it now return me nothing at all worse then just now this statement iszit to check if it return all the recordS?

          Comment

          • jx2
            New Member
            • Feb 2007
            • 228

            #6
            Originally posted by Rocky86
            I did as you suggest it now return me nothing at all worse then just now this statement iszit to check if it return all the recordS?
            pbmods is right!!

            insted of giving u the answer i try to explain you how it works

            it dosnt return just one record!!(if there are records matching your criteria) it return THE FIRST RECORD ONLY!!!
            if u want the second record u need to call mysql_fetch_arr ay() or mysql fech row() again and again

            therefore pbmods sugested you to change "if" to "while"

            there is ofcurse posible your query doesnt math anything

            i sugest to try somthing simplier at the begining and modify it to your needs later

            [PHP]
            $result = mysql_query(" SELECT * FROM yourtable");
            echo "<table>";
            while($record = mysql_fetch_row ($result))
            {
            //notice i do not compare it i asign it (single "=" not "==")
            // the statment above is true as long as thre are records to read
            // $record is an array!! therefore:
            echo "<tr>";
            foreach($record as $var){
            echo "<td>$var</td>";
            }
            echo "</tr>";
            }
            echo "</table>";
            [/PHP]

            that should display all records in your table
            you can modify the query to your need later

            i hope that helps
            jx2

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, Rocky.

              Originally posted by Rocky86
              I did as you suggest it now return me nothing at all worse then just now this statement iszit to check if it return all the recordS?
              I put up that code to help you understand what the code is doing.

              The solution to your problem is actually quite simple, but only if you know how your code works.

              Comment

              • Rocky86
                New Member
                • Jun 2007
                • 93

                #8
                Originally posted by pbmods
                Heya, Rocky.



                I put up that code to help you understand what the code is doing.

                The solution to your problem is actually quite simple, but only if you know how your code works.
                Hey pbmods that code you put is just returning the record that match my sql statement that all what is the solution to my problem plss help

                Comment

                • Rocky86
                  New Member
                  • Jun 2007
                  • 93

                  #9
                  Originally posted by jx2
                  pbmods is right!!

                  insted of giving u the answer i try to explain you how it works

                  it dosnt return just one record!!(if there are records matching your criteria) it return THE FIRST RECORD ONLY!!!
                  if u want the second record u need to call mysql_fetch_arr ay() or mysql fech row() again and again

                  therefore pbmods sugested you to change "if" to "while"

                  there is ofcurse posible your query doesnt math anything

                  i sugest to try somthing simplier at the begining and modify it to your needs later

                  [PHP]
                  $result = mysql_query(" SELECT * FROM yourtable");
                  echo "<table>";
                  while($record = mysql_fetch_row ($result))
                  {
                  //notice i do not compare it i asign it (single "=" not "==")
                  // the statment above is true as long as thre are records to read
                  // $record is an array!! therefore:
                  echo "<tr>";
                  foreach($record as $var){
                  echo "<td>$var</td>";
                  }
                  echo "</tr>";
                  }
                  echo "</table>";
                  [/PHP]

                  that should display all records in your table
                  you can modify the query to your need later

                  i hope that helps
                  jx2
                  hey jx2 basically the code you post is returning all the record which not what I want to acheive for my case I need to compare the value and return the uname and uid of whoever that matches my sql condition right now my code is able to just return 1 record instead of all the record that matches the condition trying to make it display not just 1 but all the record that matches the sql condition

                  Comment

                  • kovik
                    Recognized Expert Top Contributor
                    • Jun 2007
                    • 1044

                    #10
                    Originally posted by Rocky86
                    hey jx2 basically the code you post is returning all the record which not what I want to acheive for my case I need to compare the value and return the uname and uid of whoever that matches my sql condition right now my code is able to just return 1 record instead of all the record that matches the condition trying to make it display not just 1 but all the record that matches the sql condition
                    He's not writing the code for you, he's giving you an example of how to retrieve data from a query result. If you want it to match your SQL, then replace the query he gave to you with your query.

                    I really suggest that you go back and read some beginner's tutorials. You seem to keep thinking that everyone is writing your code for you when all we're doing is trying to teach you, and if you understood the code instead of just copying and pasting it, you'd know that. There's are plenty of books available as well to help you 'break out' of being a novice programmer into an intermediate stage.

                    Comment

                    • Rocky86
                      New Member
                      • Jun 2007
                      • 93

                      #11
                      Originally posted by volectricity
                      He's not writing the code for you, he's giving you an example of how to retrieve data from a query result. If you want it to match your SQL, then replace the query he gave to you with your query.

                      I really suggest that you go back and read some beginner's tutorials. You seem to keep thinking that everyone is writing your code for you when all we're doing is trying to teach you, and if you understood the code instead of just copying and pasting it, you'd know that. There's are plenty of books available as well to help you 'break out' of being a novice programmer into an intermediate stage.
                      I understand the mysql_fetch_arr ay is only able to fetch the first row but not the second or third and so on But I reallx want to know how to do that? able to fetch not just the first row but all the row that match the sql condition pls help

                      Comment

                      • dafodil
                        Contributor
                        • Jul 2007
                        • 389

                        #12
                        Hey man. You should really study. I checked all your posts. It seems you're not really interested in learning. I adviced you already in your previous thread. Are you using this site to create your own project? Its not good.

                        This site is a good start for learning: http://w3schools.com/

                        you can also try this: http://movielibrary.lynda.com/html/modPage.asp?ID=435

                        Your previous thread already came up to 28 posts with simple questions that's not hard to understand...

                        With a thread title how to use logic for my code?. That's shows how lazy you are, you even want us to solve the logic of your program.

                        When all you need to learn is the syntax of the language and the logic is the application of it!!!!!

                        Comment

                        • Rocky86
                          New Member
                          • Jun 2007
                          • 93

                          #13
                          how come the uid is undefined value on the actionscripts? the uname is able to be display but the uid is undefinded I don't see any wrong with my code but I don't know why it return undefinded value?
                          [PHP]
                          $counterx=0;
                          if($row=mysql_f etch_array($res ultpostal)){
                          foreach($row as $col_value){
                          $temp[$counterx]=$col_value;
                          $counterx++;
                          }





                          $report.="uid". "=".$temp[0]."&";
                          $report.="uname "."=".$temp[1]."&";




                          echo $report;


                          [/PHP]

                          Comment

                          • kovik
                            Recognized Expert Top Contributor
                            • Jun 2007
                            • 1044

                            #14
                            You need to start doing some debugging. Make your ActionScript display everything from the PHP file, and start making the PHP file echo out everything that you can. There is no magic solution... You HAVE to put forth some effort.

                            Comment

                            • Rocky86
                              New Member
                              • Jun 2007
                              • 93

                              #15
                              Originally posted by volectricity
                              You need to start doing some debugging. Make your ActionScript display everything from the PHP file, and start making the PHP file echo out everything that you can. There is no magic solution... You HAVE to put forth some effort.
                              I understand I will do it thx

                              Comment

                              Working...