Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: help me to solve this problem

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

    Default

    thank you friends for help me to solve a part of my probs;

    i got the solution....................

    name age
    -------------------
    sam 22
    john 32
    peter 45
    george 12 this is the DB table. table name is "TEST"


    here is the code.
    DB and PHP connection
    -----------------------
    <?php require('Connections/DB1.php'); ?>
    <?php
    mysql_select_db($database_DB1, DB1);
    $query_Recordset1 = "SELECT * FROM test";
    $Recordset1 = mysql_query($query_Recordset1, $DB1) or die(mysql_error());
    $tot_Rec = mysql_num_rows($Recordset1);
    ?>

    operation
    ---------

    <?php
    for($i=0;$i<$tot_Rec;$i++)
    {
    $row_Recordset1 = mysql_fetch_array($Recordset1);
    $tot_Col = sizeof($row_Recordset1);
    for ($j=0;$j<$tot_Col;$j++)
    {
    if($j=2){
    echo $row_Recordset1[$j];
    echo "<br>";
    }
    else { echo "bye <br>";}
    }
    }
    ?>


    the output is:

    sam
    john
    peter
    george




    22
    32
    45
    12

    but wht i want is not this.....

    i want some thing different. here we can get data in order.
    but i want to print randomly. for examle if we have M row N coll.
    i want to display
    (3rd row, 2nd coll) then (1st row, 4th coll)..............like this i want to acess data randamly. in diff palce of my out put page.

    once again thank you friends for help me to solve a part of my probs;
    please help me to solve this whole problem. thank you.

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

    Default

    Code:
    <p>
    <?php
      require('Connections/DB1.php');
      mysql_select_db($database_DB1);
      $rs = mysql_query('select * from test order by rand()') or die(mysql_error());
      $alldata = array();
      while($row = mysql_fetch_array($rs))
        $alldata = array_merge($alldata, $row);
      usort($alldata, create_function('$a,$b', 'return rand() - 0.5;'));
      foreach($alldata as $x) {
    ?>
      <?php echo $x; ?>
    <?php } ?>
    </p>
    Last edited by Twey; 07-27-2007 at 05:18 PM.
    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. #13
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hi TWEY

    you are helping lot. thank you your help.

    i cant understand the code. please explzin it........

    plzzzzzzzzzzzzzzzzzzzzzz

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

    Default

    It gets all the data, puts it in a big array, randomises it, then spits it out.

    If you have a lot of data, this will be horribly inefficient, since you'll need to store all the data in memory.
    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!

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

    Default

    i got error

    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '()' at line 1

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

    Default

    Sorry, it's rand(), not random(). Edited.
    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. #17
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    anyway

    i had done it in diff way. very very thank you TWYN

    <?php require('Connections/DB.php'); ?>
    <?php
    mysql_select_db($database_DB, $DB);
    $query_Recordset1 = "SELECT * FROM test";
    $Recordset1 = mysql_query($query_Recordset1, $DB) or die(mysql_error());
    $tot_Rec = mysql_num_rows($Recordset1);
    ?>



    <?php
    for($i=0;$i<$tot_Rec;$i++)
    {
    $row_Recordset1 = mysql_fetch_array($Recordset1);
    $tot_Col = sizeof($row_Recordset1);
    for ($j=0;$j<$tot_Col;$j++)
    {
    $out[$i][$j]=$row_Recordset1[$j];
    }
    }
    ?>
    <?php echo $out[0][0]; ?> <br>
    <?php echo $out[1][5]; ?> <br>
    <?php echo $out[0][3]; ?> <br>
    <?php echo $out[1][0]; ?>

    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>



    this is the full source code, in this code you can access any data anywhere....

    thank you all for helped me...................

    is it right TWYN?

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
  •