TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   man,aging the outputs , need urgent help (http://www.talkphp.com/absolute-beginners/2466-man-aging-outputs-need-urgent-help.html)

webtuto 03-12-2008 04:24 PM

man,aging the outputs , need urgent help
 
hey i have a problem with organizing the outputs from database

for exemple i want to be in a row 5 names then come to the other ligne and put other 5 rows

here is my code

PHP Code:

while($row mysql_fetch_array($reesul))
 {
    echo 
$row['name'];
    echo 
"<img src='$row[photo]'>";
 } 

thans in advance , i really need the answer thanks

freenity 03-12-2008 05:19 PM

maybe this??

PHP Code:

while($row mysql_fetch_array($reesul))
 {
    for(
$i=0;$i<5;$i++)
    {
        
$row mysql_fetch_array($reesul);
        echo 
$row['name'];
        echo 
"<img src='$row[photo]'>";
    }
 } 


webtuto 03-12-2008 05:23 PM

no , for exemple
the name of the singer then his photo under the name
5 photos and name on one ligne
then it come to the other ligne and post 5 other , .....

freenity 03-12-2008 05:25 PM

ah, then I think you have to while the whole results put names in one array, and photos in another.
After that just print 5 names from the first array, then 5 photos on the other lines from the second array, and so on...

ReSpawN 03-12-2008 06:46 PM

Then I could suggest to make it a 3D array.

array contains an array for the first value of the first array, and then in that array the information from the value you're trying to access. I will 'map' it out later, got to go!

DeMo 03-12-2008 08:53 PM

From your first post it seems the photos also come from the database.
How is the data returned by your SQL query organized?

If it returns 5 rows for each artist (name repeats but the photo changes) you could do it like this:
PHP Code:

// Some helper variables
$counter 0;
$last_name '';

while (
$row mysql_fetch_array($reesul) {
  ++
$counter;

  
// Check if we have a new name
  
if ($row['name'] != $last_name) {
    
// Yes, we have a new name so we print it
    
echo $row['name'], '<br />';
    
// And we also update $last_name to the current name.
    
$last_name $row['name'];
  }
  
  
// Here we print the image tag
  
echo '<img src="'$row['photo'], '" />';

  
// If we looped through 5 records it's time to print a line break (<br />)
  
if ($counter == 0) {
    echo 
'<br />';
  }



xenon 03-12-2008 09:16 PM

I'd go with CSS. Something like:

PHP Code:

echo '<ul id="listing">';
while( 
$row mysql_fetch_array($result) )
{
    
// this would be a loop through all the entries
    
echo '<li>
<div>'
.$row['title'].'</div>
<div><img src="'
.$row['photo'].'" /></div>
</li>'
;
}
echo 
'<li class="clear">&nbsp;</li></ul>'

And the CSS:

Code:

#listing { width:600px;}
#listing li { width:100px; float:left;}
#listing li.clear { float:none; clear:both; height:1px; overflow:hidden; line-height:1px;}


webtuto 03-13-2008 07:40 PM

thanks but the name and photo changes


All times are GMT. The time now is 06:59 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0