Jump to content

php problem echo data from mysql.


fantomel

Recommended Posts

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

<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 :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.