SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL repeating data

    Hello, this code I'm using seems to just repeat the data for how ever much of the data I have, for example if I have fives rows of data, it will repeat itself 5 times and here is the PHP I'm using:

    PHP Code:
    $dir =            'images/anime_shows/';
    $file_display = array('jpg''jpeg''png''gif');


    if (
    file_exists($dir) == false
    {
    echo 
    'Folder \''$dir'\' not found!';

        else 
        {
        
    $dir_contents scandir($dir);

            foreach (
    $dir_contents as $file
            {
            
    $file_type strtolower(end(explode('.'$file)));
                
                    if (
    $file !== '.' && $file !== '..' && in_array($file_type$file_display) == true
                    {
                    
    $animeimg '<img src="' $dir '/' $file '" alt="' $file '" width="80px;" height="100px" />';
                    
                    
    $template->assign_block_vars('anime.img', array(
                        
    'IMG'    => $animeimg,
                        ));
                        
                    
    $sql "SELECT name, description FROM phpbb_anime" ;
                    
    $result $db->sql_query($sql);

                    while ((
    $row $db->sql_fetchrow($result))>0)
                    {
                        
    $template->assign_block_vars('anime', array(
                            
    'ANIME_NAME'    => $row['name'],
                            
    'ANIME_DESC'    => $row['description'],
                        ));
                    }
                    }
            }
        } 

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your SQL query is located inside a foreach loop that seems to run for each file you have in a certain directory, but your query doesnt seem to change depending on the file your processing, therefore if you have 5 files the same query will run 5 times.




    edit:

    and you dont need the >0 on the end of the while statement, PHP while will step through all the elements of the array then stop automatically.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Translation: Query needs a WHERE clause. (and probably an ORDER BY too.)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •