Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print out results from a MySQL Query

    Rather new to php so I'm trying to learn how to print out some results. The column I want to query has 24,113 rows so it has a lot of data but I want to sort it via a specific field so Im trying this. Sorting I know ASC DSC but I will learn how to do this another way just want to get past the basic part.

    Code:
    <?
    $dbhost = 'localhost';
    $dbuser = 'zackman_;
    $dbpass = '1083';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    $dbname = 'zackman_';
    mysql_select_db($dbname);
    $data = mysql_query("SELECT * FROM userfield ORDER BY field55 LIMIT 0,20;") or die(mysql_error());
    
    echo "$data";
    mysql_close($conn);
    ?>
    Problem is I am getting a Resource ID 3 error which I am not familar with. I realize there is a lot of data to print so I want to learn how to to format it to look a little more nicer when it is viewed on the web which Ill figure out eventually but I can't get past this part. I have MySQL5 and apache2/php5 this is my own server so I can configure it any way I like in the event the problem is more then just a coding/syntax error

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    A similar problem is in MySQL forum count??
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ive read the manual and still dont really get it, at best I im guessing I need to define an array?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Scroll down to see some examples
    PHP Code:
    $data mysql_query("SELECT * FROM userfield ORDER BY field55 LIMIT 0,20;") or die(mysql_error());
    while (
    $row mysql_fetch_assoc($data)) {
        echo 
    $row['firstname'];
        echo 
    $row['lastname'];
        echo 
    $row['address'];
        echo 
    $row['age'];

    Last edited by abduraooft; 11-03-2007 at 02:13 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I changed it to

    Code:
    $data = mysql_query("SELECT * FROM userfield ORDER BY field55 ASC LIMIT 0,20;") or die(mysql_error());
    $info = mysql_fetch_array( $data );
    
    while ($info = mysql_fetch_array($data)) {
    echo '<p><pre>';
    print_r($info);
    echo '</pre>';
    }
    Result

    Array
    (
    [0] => 11257
    [userid] => 11257
    [1] =>
    [field1] =>
    [2] => Michigan
    [field2] => Michigan
    [3] =>
    [field3] =>
    [4] =>
    [field4] =>
    [5] => 93 Z28 a4
    [field5] => 93 Z28 a4
    [6] =>
    [field6] =>
    [7] =>
    [field50] =>
    [8] =>
    [field51] =>
    [9] =>
    [field52] =>
    [10] =>
    [field53] =>
    [11] =>
    [field54] =>
    [12] =>
    [field55] =>
    [13] =>
    [field56] =>
    [14] =>
    [field57] =>
    [15] =>
    [field58] =>
    [16] =>
    [field59] =>
    [17] =>
    [field60] =>
    [18] =>
    [field61] =>
    [19] =>
    [field62] =>
    [20] =>
    [field63] =>
    [21] =>
    [temp] =>
    )



    Array

    And that worked Now I need to learn how to format it nicely where could I read up on that stuff. Basically Ill need to set this information to print horizontally rather then vertically

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Instead of print_r(), just print your values of fields like
    Code:
    echo $info['name_field1'];
    echo '<br/>'.$info['name_field2'];
    (use your table'd filed names.)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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