943,962 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 449
  • PHP RSS
Jan 3rd, 2009
0

urgent help...

Expand Post »
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..!

php Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 14
Solved Threads: 0
Light Poster
SkyVValker is offline Offline
28 posts
since Jan 2009
Jan 3rd, 2009
0

Re: urgent help...

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:
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 4
Light Poster
DiGSGRL is offline Offline
45 posts
since May 2008
Jan 4th, 2009
0

Re: urgent help...

Thanx DisGSGurl...!i got it..thanx a billion
Reputation Points: 14
Solved Threads: 0
Light Poster
SkyVValker is offline Offline
28 posts
since Jan 2009
Jan 4th, 2009
0

Re: urgent help...

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..
==========
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 14
Solved Threads: 0
Light Poster
SkyVValker is offline Offline
28 posts
since Jan 2009
Jan 4th, 2009
0

Re: urgent help...

The reason you are only showing one file over and over is due to this line:
PHP Syntax (Toggle Plain Text)
  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:
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Light Poster
DiGSGRL is offline Offline
45 posts
since May 2008
Jan 4th, 2009
0

Re: urgent help...

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,..
Reputation Points: 14
Solved Threads: 0
Light Poster
SkyVValker is offline Offline
28 posts
since Jan 2009
Jan 4th, 2009
0

Re: urgent help...

Take the table out of the while loop.
Use the while loop to create your image array.
PHP Syntax (Toggle Plain Text)
  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:
PHP Syntax (Toggle Plain Text)
  1. $c=0;(outside of the for loop)
  2. $realname = $rows ['filename'][$c];
  3. $c++;
Reputation Points: 10
Solved Threads: 4
Light Poster
DiGSGRL is offline Offline
45 posts
since May 2008
Jan 4th, 2009
0

Re: urgent help...

DiGSGurl...would u like to eidt ur suggestion in ma code plz ..
Reputation Points: 14
Solved Threads: 0
Light Poster
SkyVValker is offline Offline
28 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: result of 1 query parametre to other..
Next Thread in PHP Forum Timeline: Website to CSV





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC