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 9 of 9
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql database,row and dvide

    I need to get the amount of rows of the table in mysql datbase, and then devide them through 3, and print them in each of them separately.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <?php

    $testDB 
    mysql_connect('localhost''root''');
    $naamDB 'test';
    @
    mysql_select_db($naamDB) or die ( " kan database niet vinden ");

    for (
    $i $i 10 $i++)
     {
    $resultaat mysql_query("SELECT * FROM test WHERE id = $i ");
    if (!
    $resultaat) {
       die(
    'Ongeldige query: ' mysql_error());
    }

    while(
    $a mysql_fetch_row($resultaat)) {


    $teller count($a[0]); 
    print 
    $a[0];
    }

    }

     

    //  print "<TD>$a</TD>";
    //$result = mysql_fetch_array(mysql_query("SELECT * FROM test WHERE id = $i "));

     


    ?>

    <body>
    </body>

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,747
    Thanks
    18
    Thanked 155 Times in 146 Posts
    what exactly you need to do isnt clear, but you'll at least need to use some aplication of mysql_num_rows() : http://us3.php.net/manual/en/functio...l-num-rows.php
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got a db called 'test'. I want to calculate how many entry's it has, then devide the result of that into 3, and print 3 times for each the result.

  • #4
    New Coder
    Join Date
    Feb 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone?

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,747
    Thanks
    18
    Thanked 155 Times in 146 Posts
    and print 3 times for each the result.
    print what 3 times???
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #6
    New Coder
    Join Date
    Feb 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    when i divide the entry's of the mysql db into 3 pieces, i want to print each piece seperatly next to each other.

  • #7
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,747
    Thanks
    18
    Thanked 155 Times in 146 Posts
    I think you want something like this, but I'm really having a hard time understanding what you want exactly:

    PHP Code:
    <table>
    <tr>

    <?

    $query 
    "SELECT * FROM table";
    $result mysql_query($query);

    $num_rows mysql_num_rows($result);
    $column_count round($num_rows 3);
    $count 1;

    if (
    $num_rows >= 1)
    {
        while (
    $row mysql_fetch_assoc($result))
        {         
            if (
    $count == 1)
            {
                echo 
    '<td>';
            }
            
            echo 
    '<p>' $row['data'] . '</p>';
            
            if (
    $count == $column_count)
            {
                echo 
    '</td>';
                
    $count 0;
            }
            
            if (
    $count == $num_rows)
            {
                echo 
    '</td>';
            }
            
            
    $count++;
        }
    }

    ?>

    </tr>
    </table>
    Last edited by chump2877; 06-11-2006 at 06:31 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #8
    New Coder
    Join Date
    Feb 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    this is what I made of it, altough, I can't make the following work:

    - I asked all from ontwikkelacties, now I want to print everything from 'ontwikkelacties'. Dived into 3 seperated rows.

    PHP Code:
    <table>
    <tr>

    <?
            $database 
    'ambrosia';
            
    mysql_connect('localhost''ambrosia''popeye');
            @
    mysql_select_db($database) or die( "Kan database niet vinden");

    $query mysql_fetch_array(mysql_query("SELECT * FROM ontwikkelacties WHERE id = '1'"));
    //$result = mysql_query($query);
    //echo $query['tekst'];

    $link =mysql_connect('localhost''ambrosia''popeye');
    mysql_select_db("database"$link);

    $result mysql_query("SELECT * FROM ontwikkelacties"$link);
    $num_rows mysql_num_rows($result);

    //echo "$num_rows Rows\n";


    //$num_rows  = mysql_num_rows($result);
    $column_count  ceil($num_rows 3);
    $count 1;
    echo 
    $column_count;

  • #9
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,747
    Thanks
    18
    Thanked 155 Times in 146 Posts
    PHP Code:
    <table>
    <tr>

    <?

    $database 
    'ambrosia';
    $link mysql_connect('localhost''yourUsername''yourPassword');
    if (!
    $link
    {
       die(
    'Could not connect: ' mysql_error());
    }
    mysql_select_db($database$link) or die( "custom error message"); 

    $query "SELECT * FROM ontwikkelacties";
    $result mysql_query($query);

    $num_rows mysql_num_rows($result);
    $column_count round($num_rows 3);
    $count 1;

    if (
    $num_rows >= 1)
    {
        while (
    $row mysql_fetch_assoc($result))
        {         
            if (
    $count == 1)
            {
                echo 
    '<td>';
            }
            
            echo 
    '<p>' $row['data'] . '</p>';
            
            if (
    $count == $column_count)
            {
                echo 
    '</td>';
                
    $count 0;
            }
            
            if (
    $count == $num_rows)
            {
                echo 
    '</td>';
            }
            
            
    $count++;
        }
    }

    ?>

    </tr>
    </table>
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

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