hello guys how are you sorry i have another question

i want to display images on left side and right side on my website
for example in this code i have 9 images and i want to spread them 4 on the left side and 4 on the right side how can i do it

$display_image2=mysql_query("select id_topic,topic_title,image2 from topics where image2  not like ''  order by id_topic desc limit 8")or die (mysql_error());
Member Avatar for diafol

So you've got your 8 images, just split them on the while loop:

if($num = mysql_num_rows($display_image2)){

    $split_on = ceil($num/2); //4
    $i = 1;
    while($data = mysql_fetch_assoc($display_image2)){
        if($i <= $split_on){
            $left[] = $data['image2'];
        }else{
            $right[] = $data['image2'];
        }
        $i++;
    }

    //do something with $left image array and $right image array
}

That's just an idea.

thank you diafol it is good idea but what about if i wan to put between these images news

this is an image clarify wat do i want to do
http://oi50.tinypic.com/wsok1t.jpg

and this is html

<html>
<head>
</head>
<body>

<table border='1' width='100%'>

<tr>
<td valign='top' width='13%' > 
<img src='http://test.crispme.com/wp-content/uploads/20201.jpg' width='150' height='113'/><hr></hr>
<img src='http://test.crispme.com/wp-content/uploads/20201.jpg' width='150' height='113'/><hr></hr>

</td>
<td valign='top' width='74%'>
<ul>
<li>Tom Stalker: Who remembers me? </li>
<li>Can Watson get the best from Tiger?</li>


</ul>
</td>
<td valign='top' width='13%'> 
<img src='http://test.crispme.com/wp-content/uploads/20201.jpg' width='150' height='113'/><hr></hr>
<img src='http://test.crispme.com/wp-content/uploads/20201.jpg' width='150' height='113'/><hr></hr>

</td>

</tr>


</table>

</body>
</html>
Member Avatar for diafol

I don't see the problem. $left and $right hold the contents for these sides, what you put into the main column is up to you.

Avoid tables for layout. This is 90s. Not good. Use divs

i mean how can i put between $left and $right "new" using your code,
sorry i am still begnner and i do not have complete info about php
i want to use table to put left and right side and center as i mentioned in above image
if there is better way to do that i am ready because i am understand from your last comment i could use div

<?php 
        if($num = mysql_num_rows($display_image2)){
        $split_on = ceil($num/2); //4
        $i = 1;
        while($data = mysql_fetch_assoc($display_image2)){
        if($i <= $split_on){
        $left[] = $data['image2'];
        // here left side
        }

        //i want to put between left side and right side  "news" as i mentioned in above image 
        should i 
        else{
        $right[] = $data['image2'];
        //here right side
        }
        $i++;
        }
        //do something with $left image array and $right image array
        }

?>
Member Avatar for diafol
<div id="container">
    <div id="headarea">
        ...
    </div>
    <div id="left">
        <?php echo $leftimages;?> 
    </div>
    <div id="main">
        ...
    </div>
    <div id="right">
        <?php echo $rightimages;?>
    </div>
    <div id="footer>
        ...
    </div>
</div>

That's a xhtml skeleton, but you could use footer tags etc for html5. Once you create the html for the images - store it in $leftimages and $rightimages.

E.g.

$leftimages = ''; $rightimages = '';
foreach($left as $l){
    $leftimages .= "<img src='$l' />";
}
foreach($right as $l){
    $rightimages .= "<img src='$r' />";
}

That's very simplistic, but it'll give you an idea.

thank diafol i will try it

hello diaforl i haved tried it and it is works well
but what about if i want to put the title of the images and id as i select
id_topic,topic_title

as you sea in this liknk

<a href='shownews.php?full=news&id_topic=$row_image2->id_topic'>

<img src='$row_image2->image2' width='150' height='113' title='$row_image2->topic_title'/>
</a>

this link is old that i haved used on old site

Member Avatar for diafol
$left ='';
$right = '';
if($num = mysql_num_rows($row_image2)){
    $split_on = ceil($num/2); //4
    $i = 1;

    while($data = mysql_fetch_assoc($row_image2)){
        $to_add = "<a href='shownews.php?full=news&id_topic={$row_image2->id_topic}'><img src='{$row_image2->image2}' width='150' height='113' title='{$row_image2->topic_title}'/></a>";

        if($i <= $split_on){
            $left .= $to_add
        }else{
            $right .= $to_add;
        }
        $i++;
    }
    //do something with $left image array and $right image array
}

However, I'm assuming that you'll be using a foreach loop instead of while?

thank diafol i am sorry but how it will works with foreach loop ?

Member Avatar for diafol

Which type of loop are you using? foreach or while?

i am using foreach

this code is works perfect however i want to put title and id for the images as i mentioned

<?php 



$display_image2=mysql_query("select id_topic,topic_title,image2 
from topics where image2  not like '' order 
by id_topic desc limit 20")or die (mysql_error());




        if($num = mysql_num_rows($display_image2)){
    $split_on = ceil($num/2); //4
    $i = 1;
    while($data = mysql_fetch_assoc($display_image2)){
    if($i <= $split_on){
    $left[] = $data['image2'];
    }else{
    $right[] = $data['image2'];
    }
    $i++;


    }
    //do something with $left image array and $right image array

    }



?>



<div id='left'>
<?php 
  foreach($left as $l){

echo "
<a href='shownews.php?full=news&id_topic=here i want to put the id'>

<img src='$l'  width='150' height='113' title='here i want to put the title'/>
</a>
";

    }
    ?>
</div>


<div id='right'>
<?php 


  foreach($right as $r){

echo "
<a href='shownews.php?full=news&id_topic=here i want to put the id''>

<img src='$r'  width='150' height='113' title='here i want to put the title'/>
</a>
";

    }

    ?>

</div>

thank diafol again and again proplem has been solved as you mentioned no need to use while

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.