how can I display more than one image in my table???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • scaleautostyle
    New Member
    • Aug 2009
    • 14

    how can I display more than one image in my table???

    Hi everybody???

    I work on a search engine for my site. everything going good except for one thing. I have multiple image for each item to show. but each item have a different number of picture.

    how can I display them. also what will be the way to store them.

    actually i store 1 image in my database ( in fact it the path of the picture not the picture itself )

    and my code goes like that..

    Code:
    <?php
    
    include_once("db_connection.php");
       if(isset($_POST['submit'])){   
       if(isset($_GET['go'])){   
       if(preg_match("/^[  a-zA-Z]+/", $_POST['name'])){   
       $name=$_POST['name'];   
          
         //-query  the database table   
       $sql="SELECT  kit_id, kit_number, kit_name, description, manufacturer_kit, manufacturer_reel, engine_detail, year_prod_kit, year_prod_reel, scale, image_id  FROM kit WHERE kit_name LIKE '%" . $name ."%' OR description LIKE '%" . $name .  "%' OR manufacturer_kit LIKE '%" . $name ."%'";  
     
     
      //-run  the query against the mysql query function   
       $result=mysql_query($sql);  
       
      //-make the header of the table   
       
       echo "  <table align=center width=\"100%\" border=\"\">\n";
       echo "    <tr>\n";
       echo"  <td nowrap align=center width='95'>  kit manufacturer  \n";		
       echo"  <td nowrap align=center width='55'>	scale \n";		
       echo"  <td nowrap align=center width='90'>	kit number \n";		
       echo"  <td nowrap align=center width='290'>	kit name \n";		
       echo"  <td nowrap align=center width='400'>	description \n";		
       echo"  <td nowrap align=center width='70'>	year of reel production of car \n";		
       echo"  <td nowrap align=center width='70'>	complete engine detail\n";		
       echo"  <td nowrap align=center width='75'>	Select Picture to get bigger\n";
       echo "    <tr>\n";
    
       //-create  while loop and loop through result set   
       while($row=mysql_fetch_array($result)){   
             $description  =$row['description'];   
             $manufacturer_kit=$row['manufacturer_kit'];   
             $kit_id=$row['kit_id']; 
    		 $kit_number=$row['kit_number'];
    		 $kit_name=$row['kit_name'];
    		 $engine_detail=$row['engine_detail'];
    		 $year_prod_reel=$row['year_prod_reel'];
    		 $scale=$row['scale'];
    		 $image_id=$row['image_id'];
    		   
       //-create  table of item during the while loop
       
    echo "  <table align=center width=\"100%\" border=\"\">\n";		   
    echo"  <td nowrap align=center width='95'>  $manufacturer_kit  \n";		
    echo"  <td nowrap align=center width='55'>	$scale \n";		
    echo"  <td nowrap align=center width='90'>	$kit_number \n";		
    echo"  <td nowrap align=center width='290'>	$kit_name \n";		
    echo"  <td nowrap width='400'>	$description \n";		
    echo"  <td nowrap align=center width='70'>	$year_prod_reel \n";		
    echo"  <td nowrap align=center width='70'>	$engine_detail \n";		
    echo"  <td nowrap width='75'> <a href=".$image_id.">   <img src='".$image_id."' width='75' height='50'/>";		
    echo "    </tr>\n";
    echo "    </table>\n"; 
    echo "    </tr>\n";
    echo "    </table>\n"; 
    
       }   
       }  
       else{   
       echo  "<p>Please enter a search query</p>";   
       }   
       }   
       }
     ?>

    So what will be the best way to do my need.

    yours

    sebastien
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Well, I imagine that you don't want to have a limited number fo pictures for each item, so all I can think of is making a string of related pictures in the single database cell.

    It's easier if you said for example there is a maximum number of 3 pictures per item, and then have 3 columes in your database for pic1, pic2 and pic3 (which you can call quite easily).

    However, if you have an unknown number and it could be between 0 and 10,000 then you will need something more complicated.

    Seeing as you're storing the path instead of the pictures, this is a bit easier. You can store the paths as a string and then separate them using explode().

    So you would have a value in the database like:
    "pics/pic1.jpeg , pics/pic2.jpeg , pics/pic3.jpeg"
    and then explode it into an array with:
    Code:
    $pics = explode(" , ", $database_pics_string);
    And then you can cycle through the $pics[] array to output all the elements as pictures.

    Hope that helps.

    Comment

    • scaleautostyle
      New Member
      • Aug 2009
      • 14

      #3
      thank I will try that and let you know

      yours

      sebastien

      Comment

      Working...