urgent help...

Thread Solved

Join Date: Jan 2009
Posts: 8
Reputation: SkyVValker is an unknown quantity at this point 
Solved Threads: 0
SkyVValker SkyVValker is offline Offline
Newbie Poster

urgent help...

 
0
  #1
Jan 3rd, 2009
I m new in php.i want some help in my code..plz..
i have 15 image in mysql table .and i want to retreive atleast 3 images in first row.den other 3 in second row..how can i make it possible..
the code is given below..!

  1. <?php
  2. include "dbconfig.php";
  3. ?>
  4.  
  5. <link href="main.css" rel="stylesheet" type="text/css" />
  6. <table border="1" cellpadding="0" cellspacing="0" bordercolor="#BCC5C7">
  7.  
  8. <tr><?php
  9. $results = "SELECT * FROM files WHERE menu_item_id='5' limit 5";
  10. $Img_result = mysql_query ($results, $conn);
  11. if (mysql_num_rows ($Img_result) >= 0){
  12. $Img_menu = array();
  13. while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC)){
  14.  
  15. $realname = $rows ['filename'];
  16. $small_preview = 'download/wallpapers/'.$realname.'';
  17. $large_preview = 'download/wallpapers/'.$realname.'';
  18.  
  19. ?><td><?php echo "<a href='$large_preview' target='_blank'><img width='120' height='200' src='$small_preview' border='0'></a>";?>
  20. <br /><div class="pic"><strong>Name :</strong> <?php echo $rows ['title']; ?></div></td><? } } ?></tr>
  21.  
  22. </table>
Last edited by peter_budo; Jan 6th, 2009 at 2:04 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 45
Reputation: DiGSGRL is an unknown quantity at this point 
Solved Threads: 4
DiGSGRL's Avatar
DiGSGRL DiGSGRL is offline Offline
Light Poster

Re: urgent help...

 
0
  #2
Jan 3rd, 2009
Are you saying you want 3 images per table row?
If this is what you want to do, you may also want to change your limit on the query results to 6.

Then you would put your table creation inside of a php loop:
  1. <?php
  2. $totalResults=mysql_num_rows($yourQuery);
  3. $numberOfImagesPerRow=3;
  4. $numberOfRows=$totalResults/$numberOfImagesPerRow;
  5. echo "<table">;
  6. for($x=0;$x<$numberOfRows;$x++)
  7. {
  8. echo "<tr>";
  9. for($i=0;$i<$numberOfImagesPerRow;$i++)
  10. {
  11. echo "<td>";
  12. //picture display code here
  13. echo "</td>;
  14. }
  15. echo"</tr>";
  16. }
  17. echo "</table>";
  18. ?>
  19.  

And if that isn't what you want to do, well now you know how to do that!
Last edited by DiGSGRL; Jan 3rd, 2009 at 7:16 pm. Reason: Forgot a bracket
A little clarification goes a long way.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: SkyVValker is an unknown quantity at this point 
Solved Threads: 0
SkyVValker SkyVValker is offline Offline
Newbie Poster

Re: urgent help...

 
0
  #3
Jan 4th, 2009
Thanx DisGSGurl...!i got it..thanx a billion
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: SkyVValker is an unknown quantity at this point 
Solved Threads: 0
SkyVValker SkyVValker is offline Offline
Newbie Poster

Re: urgent help...

 
0
  #4
Jan 4th, 2009
there is an other prob..it repeat 1 image various times..n i want to retri all images from database.this code showing 3 images per row..
plz chk ma array n loop..
==========
  1. <?php
  2. $results = "SELECT * FROM files WHERE menu_item_id='5' order by rand()";
  3. $Img_result = mysql_query ($results, $conn);
  4. $totalResults=mysql_num_rows($Img_result);
  5. $numberOfImagesPerRow=3;
  6. $numberOfRows=$totalResults/$numberOfImagesPerRow;
  7.  
  8. if (mysql_num_rows ($Img_result) >= 0){
  9. $Img_menu = array();
  10. while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC)){
  11.  
  12.  
  13. echo "<table>";
  14. for($x=0;$x<$numberOfRows;$x++)
  15. {
  16. echo "<tr>";
  17. for($i=0;$i<$numberOfImagesPerRow;$i++)
  18. {
  19. echo "<td>";
  20. //PREVIEW IMAGE IF EXISTS
  21. $realname = $rows ['filename'];
  22. $small_preview = 'download/wallpapers/'.$realname.'';
  23.  
  24. echo "<div align='center'><img src='$small_preview' border='0'></div><BR>";
  25.  
  26.  
  27. echo "</td>";
  28. }
  29.  
  30. }
  31. echo "</tr>";
  32. }
  33. }
  34. echo "</table>";
  35.  
  36. ?>

===============
Last edited by peter_budo; Jan 6th, 2009 at 2:04 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 45
Reputation: DiGSGRL is an unknown quantity at this point 
Solved Threads: 4
DiGSGRL's Avatar
DiGSGRL DiGSGRL is offline Offline
Light Poster

Re: urgent help...

 
0
  #5
Jan 4th, 2009
The reason you are only showing one file over and over is due to this line:
  1. $realname = $rows ['filename'];
You need to tell it to iterate through the results array. You should keep a counter and append the number onto that line:
  1. $i=0;(outside of your while loop)
  2. $realname = $rows ['filename'][$i];
  3. $i++;
  4.  
  5. WHERE menu_item_id='5'
Your where clause determines how many records are going to be returned. If you are having trouble after trying the first suggestion of moving through your array, then make sure the where is what you need it to be.
A little clarification goes a long way.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: SkyVValker is an unknown quantity at this point 
Solved Threads: 0
SkyVValker SkyVValker is offline Offline
Newbie Poster

Re: urgent help...

 
0
  #6
Jan 4th, 2009
all recordes..
let me explain..!
if i have 12 images in my db..den
1 image repeat 12 time.den 2nd image repeat 12 times,..
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 45
Reputation: DiGSGRL is an unknown quantity at this point 
Solved Threads: 4
DiGSGRL's Avatar
DiGSGRL DiGSGRL is offline Offline
Light Poster

Re: urgent help...

 
0
  #7
Jan 4th, 2009
Take the table out of the while loop.
Use the while loop to create your image array.
  1. $i=0;
  2. while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC))
  3. {
  4. $imageArray=$rows['filename'][$i};
  5. $i++;
  6. }

Then inside your table where you display your filename:
  1. $c=0;(outside of the for loop)
  2. $realname = $rows ['filename'][$c];
  3. $c++;
A little clarification goes a long way.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: SkyVValker is an unknown quantity at this point 
Solved Threads: 0
SkyVValker SkyVValker is offline Offline
Newbie Poster

Re: urgent help...

 
0
  #8
Jan 4th, 2009
DiGSGurl...would u like to eidt ur suggestion in ma code plz ..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC