Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: help me to solve this problem

  1. #1
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help me to solve this problem

    i have a table in mysql DB.
    table is

    name age phone
    -----------------------------
    sam 24 18191
    joseph 30 62781
    mary 19 54271
    jancy 24 78236
    michel 29 78152


    this is the table. iam using dream wear 8.
    i connected the db with php page,

    <?php require_once('Connections/db2.php'); ?>
    <?php
    mysql_select_db($database_DB2, DB2);
    $query_Recordset1 = "SELECT * FROM test";
    $Recordset1 = mysql_query($query_Recordset1, $DB2) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>

    and then i have
    created the recordset. (name of the recordset is recordset1)

    here i want to display all rows in the "name" colum one by one in my output page like

    sam
    joseph
    mary
    jancy
    michel

    iam using the command

    <p><?php echo $row_Recordset1['name']; ?></p>

    but here i can get only the first record (row) of the "name" colum;

    how can i get all other rows in the "name" colum in single page.

    please post the code to access all the rows or tell me how to do this please help me.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
      while($row_Recordset1 = mysql_fetch_array($query_Recordset1)) {
    ?>
    <p><?php echo $row_Recordset1['name']; ?></p>
    <?php
      }
    ... although a table may be more suitable.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    TWEy.... thany you for your reply. but i cant understand wht your telling. where i have to write this code. whts that "although table may be more suitable.

    please explain me. iam very very new to this

  4. #4
    Join Date
    May 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    <?php require_once('Connections/db2.php'); ?>
    <?php
    mysql_select_db
    ($database_DB2DB2);
    $query_Recordset1 "SELECT * FROM test";
    $Recordset1 mysql_query($query_Recordset1$DB2) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);

    while(
    $row_Recordset1 mysql_fetch_array($query_Recordset1)) {
    ?>
    <p><?php echo $row_Recordset1['name']; ?></p>
    <?php
      
    }
    ?>
    Above is where you should place the code. Twey said it would be better to use a table because that's what you are creating, his is a short example which uses the <p> tag.

    Below is an example of how you can do this in a table:
    PHP Code:
    <table>
    <tr><td>Name</td><td>Age</td><td>Phone</td></tr>
    <?php require_once('Connections/db2.php'); ?>
    <?php
    mysql_select_db
    ($database_DB2DB2);
    $query_Recordset1 "SELECT * FROM test";
    $Recordset1 mysql_query($query_Recordset1$DB2) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);

    while(
    $row_Recordset1 mysql_fetch_array($query_Recordset1)) {
    ?>
    <tr>
    <td><?php echo $row_Recordset1['name']; ?></td>
    <td><?php echo $row_Recordset1['age']; ?></td>
    <td><?php echo $row_Recordset1['phone']; ?></td>
    </tr>
    <?php
      
    }
    ?>
    </table>

  5. #5
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for your replies.....i think i didnt said the problem clearly...
    here i tell the problem.. please help me

    name age phone
    -------------------------------
    sam 24 18191
    joseph 30 62781
    mary 19 54271
    jancy 24 78236
    michel 29 78152

    this is table....................

    <p><?php echo $row_Recordset1['name']; ?></p>

    this will give output as -----------> sam

    now i want the second row "joseph" in the next line i mean output should be

    sam
    joseph
    marry
    jancy
    michel OK?

    simpley said...


    i have a table in my DB
    using PHP i want to display that table in my dynamic web page.
    when we use <?php echo $row_Recordset1['name']; ?> i can only access the first row record. how can i acces the second row record as well as 3rd roww and all. wht is the php code for this.

    <?php echo $row_Recordset1['name']; ?> will give first row of "name" colum---> sam
    ?????????????????????????????????????? will give second row of "name" colum---> joseph

    whts this ????????????????????????

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You also need to remove this line:
    Code:
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    from all the code above, since otherwise it will "pop" the topmost row from the stream and it won't appear in the output.
    <?php echo $row_Recordset1['name']; ?> will give first row of "name" colum---> sam
    ?????????????????????????????????????? will give second row of "name" colum---> joseph

    whts this ????????????????????????
    The same statement, after you've used mysql_fetch_array() (which combines the functions of mysql_fetch_row() and mysql_fetch_assoc(), rendering the latter two effectively but not officially obsolete) to pop another row from the recordset.
    Code:
    $row_Recordset1 = mysql_fetch_array($Recordset1);
    print $row_Recordset1['name']; // sam
    $row_Recordset1 = mysql_fetch_array($Recordset1);
    print $row_Recordset1['name']; // joseph
    $row_Recordset1 = mysql_fetch_array($Recordset1);
    print $row_Recordset1['name']; // mary
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    May 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Unless I'm not understanding correctly, you want to show all the records, not just the first?
    If so the code that me and Twey posted should work fine. They both use the while function which will loop through all the records found in the database.

    For example,
    PHP Code:
    <table>
    <tr><td>Name</td><td>Age</td><td>Phone</td></tr>
    <?php require_once('Connections/db2.php'); ?>
    <?php
    mysql_select_db
    ($database_DB2DB2);
    $query_Recordset1 "SELECT * FROM test";
    $Recordset1 mysql_query($query_Recordset1$DB2) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);

    while(
    $row_Recordset1 mysql_fetch_array($query_Recordset1)) {
    ?>
    <tr>
    <td><?php echo $row_Recordset1['name']; ?></td>
    <td><?php echo $row_Recordset1['age']; ?></td>
    <td><?php echo $row_Recordset1['phone']; ?></td>
    </tr>
    <?php
      
    }
    ?>
    </table>
    Would output:
    <table>
    <tr>
    <td>Name</td>
    <td>Age</td>
    <td>Phone</td>
    </tr>
    <tr>
    <td>Person 1 name</td>
    <td>Person 1 age</td>
    <td>Person 1 phone</td>
    </tr>
    <tr>
    <td>Person 2 name</td>
    <td>Person 2 age</td>
    <td>Person 2 phone</td>
    </tr>
    etc...
    </table>
    Last edited by jonnyynnoj; 07-26-2007 at 07:12 PM.

  8. #8
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thank you TWEY
    your idea works great. i got the result.

    but same time, i can access only the first colum rows.
    here i want to print all the rows from all the colums

    that means i want to display all the table records randomly. that is the important thing here.

  9. #9
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    name age phone
    -----------------------------
    sam 24 18191
    joseph 30 62781
    mary 19 54271
    jancy 24 78236
    michel 29 78152

    this is DB table....

    here i want to display the phone number 78152 ie 3rd colum (phone), 4th row..

    then age 19 2nd colum(age), 3rd row....

    like this i want to randomly display in my page.....

    please give me the solution.....

    how can i do this.

  10. #10
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    anybody know the solution?
    please reply me.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •