Thread: php pring mysql results into 3 div's

Results 1 to 9 of 9
  1. #1 php pring mysql results into 3 div's 
    Community Veteran

    Patawic's Avatar
    Join Date
    Dec 2006
    Age
    26
    Posts
    1,950
    Thanks given
    40
    Thanks received
    150
    Rep Power
    2463
    THIS THREAD HAS BEEN UPDATED. SCRIPT HAS JUST BEEN CHANGED

    Im trying to print several image url's and names from an sql database into 3 columns,

    Aiming to get it to go

    1,2,3
    4,5,6
    7,8,9

    etc etc. but for some reason myne is going

    1,2,3
    3,4,6
    6


    Code:
    <?php
    include 'config.php';
    mysql_connect($host, $user, $pass) or die(mysql_error());
    mysql_select_db($database) or die(mysql_error());
    $result = mysql_query("SELECT * FROM tracks ORDER BY id ASC");
    $num = mysql_num_rows($result);
    $arr = array();
    while($row = mysql_fetch_array($result)) {
        $arr[$row['id']] = $row;
    }
    echo '<div id="left_wrapper">';
    for($i=1; $i<$num; $i+=2) {
        $row = $arr[$i];
        $id = $row['id'] + 1;
        echo "<img src='Thumbnails/" . $id .".gif'></img><br />";
        echo $row['name']. "<br />";
    }
    echo "</div>";
    echo '<div id="middle_wrapper">';
    for ($i=2; $i<$num; $i+=2) {
        $row = $arr[$i];
        $id = $row['id'] + 1;
        echo "<img src='Thumbnails/" . $id .".gif'></img><br />";
        echo $row['name']. "<br />";
    }
    echo "</div>";
    echo '<div id="right_wrapper">';
    for ($i=3; $i<$num; $i+=2) {
        $row = $arr[$i];
        $id = $row['id'] + 1;
        echo "<img src='Thumbnails/" . $id .".gif'></img><br />";
        echo $row['name']. "<br />";
    }
    echo "</div>";
    ?>
    I NEED HALP
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Renown Programmer

    Nikki's Avatar
    Join Date
    Aug 2008
    Posts
    3,993
    Thanks given
    553
    Thanks received
    1,077
    Rep Power
    5000
    Code:
    <?php
    include 'config.php';
    mysql_connect($host, $user, $pass) or die(mysql_error());
    mysql_select_db($database) or die(mysql_error());
    $result = mysql_query("SELECT * FROM tracks");
    $num = mysql_num_rows($result);
    $perdiv = $num/3;
    echo '<div id="left_wrapper">';
    for ($i=0;$i<$perdiv;$i++) {
        $row = mysql_fetch_array($result);
        $id = $row['id'] + 1;
        echo "<img src='Thumbnails/" . $id .".gif'></img><br />";
        echo $row['name']. "<br />";
    }
    echo "</div>";
    echo '<div id="middle_wrapper">';
    for ($i=0;$i<$perdiv;$i++) {
        $row = mysql_fetch_array($result);
        $id = $row['id'] + 1;
        echo "<img src='Thumbnails/" . $id .".gif'></img><br />";
        echo $row['name']. "<br />";
    }
    echo "</div>";
    echo '<div id="right_wrapper">';
    for ($i=0;$i<$perdiv;$i++) {
        $row = mysql_fetch_array($result);
        $id = $row['id'] + 1;
        echo "<img src='Thumbnails/" . $id .".gif'></img><br />";
        echo $row['name']. "<br />";
    }
    echo "</div>";
    ?>
    Please don't add/pm me asking for RSPS help!

    Links:
    - [Only registered and activated users can see links. ]
    - [Only registered and activated users can see links. ]

    Reply With Quote  
     

  3. #3  
    Community Veteran

    Patawic's Avatar
    Join Date
    Dec 2006
    Age
    26
    Posts
    1,950
    Thanks given
    40
    Thanks received
    150
    Rep Power
    2463
    dun werk
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jun 2010
    Age
    33
    Posts
    4,337
    Thanks given
    4
    Thanks received
    274
    Rep Power
    0
    Heres an idea,
    I usually use include, But I find require is faster and better.
    And I will fix this script for you then post new one in a little.
    Reply With Quote  
     

  5. #5  
    Community Veteran

    Patawic's Avatar
    Join Date
    Dec 2006
    Age
    26
    Posts
    1,950
    Thanks given
    40
    Thanks received
    150
    Rep Power
    2463
    i dont care whether you use require or include, i just need to fix my fucking sql output
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #6  
    Community Veteran

    Songoty's Avatar
    Join Date
    Dec 2007
    Posts
    2,741
    Thanks given
    207
    Thanks received
    1,022
    Rep Power
    2351
    Code:
    $i+=2
    1 + 2 != 4 it equals 3 yo, change it to += 3 and that should fix it.

    also why are you changing the id to id+1?

    also it shouldnt be < $num because it will keep on going until there are no more images for that collum, resulting in duplicates.
    Reply With Quote  
     

  7. #7  
    Community Veteran

    Patawic's Avatar
    Join Date
    Dec 2006
    Age
    26
    Posts
    1,950
    Thanks given
    40
    Thanks received
    150
    Rep Power
    2463
    its alright, i got it thanks to bens help
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Oct 2008
    Posts
    865
    Thanks given
    75
    Thanks received
    56
    Rep Power
    483
    Quote Originally Posted by Zazo View Post
    Heres an idea,
    I usually use include, But I find require is faster and better.
    And I will fix this script for you then post new one in a little.
    They are the exact same method. Require just makes sure that if there's an error trying to include the file, the script doesn't execute any further.
    Reply With Quote  
     

  9. #9  
    Community Veteran

    Patawic's Avatar
    Join Date
    Dec 2006
    Age
    26
    Posts
    1,950
    Thanks given
    40
    Thanks received
    150
    Rep Power
    2463
    exactly
    [Only registered and activated users can see links. ]
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [delta] admins can only wield pring
    By Coder Alex in forum Snippets
    Replies: 15
    Last Post: 07-05-2009, 08:20 AM
  2. SOT2W #2 Results
    By Beh3moth in forum General
    Replies: 9
    Last Post: 03-29-2008, 08:46 PM
  3. SOTM/W #1 Results!
    By Beh3moth in forum General
    Replies: 6
    Last Post: 03-19-2008, 08:30 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •