| | |
urgent help...
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jan 2009
Posts: 8
Reputation:
Solved Threads: 0
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..!
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)
<?php include "dbconfig.php"; ?> <link href="main.css" rel="stylesheet" type="text/css" /> <table border="1" cellpadding="0" cellspacing="0" bordercolor="#BCC5C7"> <tr><?php $results = "SELECT * FROM files WHERE menu_item_id='5' limit 5"; $Img_result = mysql_query ($results, $conn); if (mysql_num_rows ($Img_result) >= 0){ $Img_menu = array(); while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC)){ $realname = $rows ['filename']; $small_preview = 'download/wallpapers/'.$realname.''; $large_preview = 'download/wallpapers/'.$realname.''; ?><td><?php echo "<a href='$large_preview' target='_blank'><img width='120' height='200' src='$small_preview' border='0'></a>";?> <br /><div class="pic"><strong>Name :</strong> <?php echo $rows ['title']; ?></div></td><? } } ?></tr> </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.
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:
And if that isn't what you want to do, well now you know how to do that!
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)
<?php $totalResults=mysql_num_rows($yourQuery); $numberOfImagesPerRow=3; $numberOfRows=$totalResults/$numberOfImagesPerRow; echo "<table">; for($x=0;$x<$numberOfRows;$x++) { echo "<tr>"; for($i=0;$i<$numberOfImagesPerRow;$i++) { echo "<td>"; //picture display code here echo "</td>; } echo"</tr>"; } echo "</table>"; ?>
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.
•
•
Join Date: Jan 2009
Posts: 8
Reputation:
Solved Threads: 0
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..
==========
===============
plz chk ma array n loop..
==========
php Syntax (Toggle Plain Text)
<?php $results = "SELECT * FROM files WHERE menu_item_id='5' order by rand()"; $Img_result = mysql_query ($results, $conn); $totalResults=mysql_num_rows($Img_result); $numberOfImagesPerRow=3; $numberOfRows=$totalResults/$numberOfImagesPerRow; if (mysql_num_rows ($Img_result) >= 0){ $Img_menu = array(); while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC)){ echo "<table>"; for($x=0;$x<$numberOfRows;$x++) { echo "<tr>"; for($i=0;$i<$numberOfImagesPerRow;$i++) { echo "<td>"; //PREVIEW IMAGE IF EXISTS $realname = $rows ['filename']; $small_preview = 'download/wallpapers/'.$realname.''; echo "<div align='center'><img src='$small_preview' border='0'></div><BR>"; echo "</td>"; } } echo "</tr>"; } } echo "</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.
The reason you are only showing one file over and over is due to this line:
You need to tell it to iterate through the results array. You should keep a counter and append the number onto that line:
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.
PHP Syntax (Toggle Plain Text)
$realname = $rows ['filename'];
PHP Syntax (Toggle Plain Text)
$i=0;(outside of your while loop) $realname = $rows ['filename'][$i]; $i++; WHERE menu_item_id='5'
A little clarification goes a long way.
Take the table out of the while loop.
Use the while loop to create your image array.
Then inside your table where you display your filename:
Use the while loop to create your image array.
PHP Syntax (Toggle Plain Text)
$i=0; while ($rows = mysql_fetch_array ($Img_result, MYSQL_ASSOC)) { $imageArray=$rows['filename'][$i}; $i++; }
Then inside your table where you display your filename:
PHP Syntax (Toggle Plain Text)
$c=0;(outside of the for loop) $realname = $rows ['filename'][$c]; $c++;
A little clarification goes a long way.
![]() |
Similar Threads
- pls heeeeeeeeelp its urgent. (C)
- Urgent! (C++)
- URGENT: Need help on I/O code! (Java)
- Urgent help (Networking Hardware Configuration)
- Homepage keeps switching back to a porn site (Web Browsers)
- Importing SQL Script File - Urgent !! (Database Design)
Other Threads in the PHP Forum
- Previous Thread: result of 1 query parametre to other..
- Next Thread: Website to CSV
| Thread Tools | Search this Thread |
advanced ajax apache api array basics beginner binary broken cakephp check checkbox class cms code combobox cookies cron curl database date datepart display dynamic echo email error file files folder form forms function functions google head href htaccess html image include includingmysecondfileinthechain insert integration ip java javascript job joomla js limit link login mail menu mlm multiple mysql oop parse password paypal pdf php problem procedure query radio random recursion regex remote script search server sessions smarty smash sms soap source space sql stored syntax system table traffic tutorial unicode up-to-date update upload url validator variable video web xml youtube





