fantomel Posted July 27, 2010 Share Posted July 27, 2010 <?php $query = mysql_query("SELECT DISTINCT `lucrare_nume`, `lucrare_poze` FROM `gallery`"); ?> <div class="gallery"> <?php while ($row = mysql_fetch_assoc($query)) { ?> <div class="project_name"> <h4> <?php echo $row['lucrare_nume'] ?> </h4> </div> <div class="img"> <img src="gallery/thumbnails/<?php echo $row['lucrare_poze']; ?>" /> </div> <?php } ?> </div> My problem is not an error with the above code i want to echo the name of the project only once and i don't have any idea how to do that and i was hoping that someone might help me. In the db for each picture there is an insert with the picture name and project name and i want to show all picture like this: Project Name: Picture1 , picture2, picture3, Project Name: Picture1, picture2, picture3 And so on.. in exchange for each picture i get an echo of the project name can someone explain to me how to solve it ? please Link to comment https://forums.phpfreaks.com/topic/209034-php-problem-echo-data-from-mysql/ Share on other sites More sharing options...
AbraCadaver Posted July 27, 2010 Share Posted July 27, 2010 Something like: <?php $project_name = ''; while ($row = mysql_fetch_assoc($query)) { if($project_name != $row['lucrare_nume']) { ?> <div class="project_name"> <h4><?php echo $row['lucrare_nume'] ?></h4> </div> <?php } ?> <div class="img"> <img src="gallery/thumbnails/<?php echo $row['lucrare_poze']; ?>" /> </div> <?php } Link to comment https://forums.phpfreaks.com/topic/209034-php-problem-echo-data-from-mysql/#findComment-1091851 Share on other sites More sharing options...
fantomel Posted July 27, 2010 Author Share Posted July 27, 2010 Something like: <?php $project_name = ''; while ($row = mysql_fetch_assoc($query)) { if($project_name != $row['lucrare_nume']) { ?> <div class="project_name"> <h4><?php echo $row['lucrare_nume'] ?></h4> </div> <?php } ?> <div class="img"> <img src="gallery/thumbnails/<?php echo $row['lucrare_poze']; ?>" /> </div> <?php } yes something like that.. you see the problems is on a single page i have to get the all the projects and their corresponding pictures(without knowing the project name as in your example ) Link to comment https://forums.phpfreaks.com/topic/209034-php-problem-echo-data-from-mysql/#findComment-1091859 Share on other sites More sharing options...
fantomel Posted July 27, 2010 Author Share Posted July 27, 2010 <div class="gallery"> <?php $query = mysql_query("select lucrare_nume, group_concat( lucrare_poze ) from gallery group by lucrare_nume"); while($row = mysql_fetch_assoc($query)) { $row['group_concat( lucrare_poze )'] = explode(',', $row['group_concat( lucrare_poze )']); ?> <div class="project_name"> <h4><?php echo $row['lucrare_nume'] ?></h4> </div> <?php foreach($row['group_concat( lucrare_poze )'] as $key => $value) { ?> <div class="img"> <img src="gallery/thumbnails/<?php echo $value; ?>" /> </div> <?php } }?> </div> solved the problem like this if anyone needs one day something like this maybe will find this topic Link to comment https://forums.phpfreaks.com/topic/209034-php-problem-echo-data-from-mysql/#findComment-1091877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.