How to rewrite the code so do the loop in this case?

<?php

require("connect.php");

                                  $banner1 = mysql_query("SELECT * FROM banner WHERE bannerid ='1'");
                                  $row1 = mysql_fetch_assoc($banner1);
                                  $bannerpath1 = ($row1['bannerpath']);
                                  $bannerheight1 = ($row1['bannerheight']);
                                  $bannerwidth1 = ($row1['bannerwidth']);
                                  $bannerdescription1 = ($row1['bannerdescription']);  

                                  $banner2 = mysql_query("SELECT * FROM banner WHERE bannerid ='2'");
                                  $row2 = mysql_fetch_assoc($banner2);
                                  $bannerpath2 = ($row2['bannerpath']);
                                  $bannerheight2 = ($row2['bannerheight']);
                                  $bannerwidth2 = ($row2['bannerwidth']);
                                  $bannerdescription2 = ($row2['bannerdescription']);  


                                  $banner3 = mysql_query("SELECT * FROM banner WHERE bannerid ='3'");
                                  $row3 = mysql_fetch_assoc($banner3);
                                  $bannerpath3 = ($row3['bannerpath']);
                                  $bannerheight3 = ($row3['bannerheight']);
                                  $bannerwidth3 = ($row3['bannerwidth']);
                                  $bannerdescription3 = ($row3['bannerdescription']);  


?>



<style type="text/css">

#marqueecontainer{
position: relative;
width: 615px; /*marquee width */
height: 100px; /*marquee height */
background-color: black;
overflow: hidden;
border: 2px Solid Purple;
padding: 2px;
padding-left: 2px;
}

</style>

<script type="text/javascript">

/***********************************************
* Cross browser Marquee II- c Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var delayb4scroll=2000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?

////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''

function scrollmarquee(){
if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
else
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}

function initializemarquee(){
cross_marquee=document.getElementById("vmarquee")
cross_marquee.style.top=0
marqueeheight=document.getElementById("marqueecontainer").offsetHeight
actualheight=cross_marquee.offsetHeight
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
cross_marquee.style.height=marqueeheight+"px"
cross_marquee.style.overflow="scroll"
return
}
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}

if (window.addEventListener)
window.addEventListener("load", initializemarquee, false)
else if (window.attachEvent)
window.attachEvent("onload", initializemarquee)
else if (document.getElementById)
window.onload=initializemarquee


</script>


<div id="marqueecontainer" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">
<div id="vmarquee" style="position: absolute; width: 98%;">

<!--YOUR SCROLL CONTENT HERE-->

<h4>


<img src='<?php echo"$bannerpath1"; ?>' width='<?php echo"$bannerwidth1"; ?>' height='<?php echo"$bannerheight1"; ?>' border='0'> <?php echo"<font color='#8D38C9'>$bannerdescription1"; ?>
<br><br><br><br><br><br>

<img src='<?php echo"$bannerpath2"; ?>' width='<?php echo"$bannerwidth2"; ?>' height='<?php echo"$bannerheight2"; ?>' border='0'> <?php echo"<font color='#8D38C9'>$bannerdescription2"; ?>
<br><br><br><br><br><br>

<img src='<?php echo"$bannerpath3"; ?>' width='<?php echo"$bannerwidth3"; ?>' height='<?php echo"$bannerheight3"; ?>' border='0'> <?php echo"<font color='#8D38C9'>$bannerdescription3"; ?>
<br><br><br><br><br><br>

</h4>

<!--YOUR SCROLL CONTENT HERE-->

</div>
</div>

Recommended Answers

All 10 Replies

The main part is below

<?php

require("connect.php");

            $banner1 = mysql_query("SELECT * FROM banner WHERE bannerid ='1'");
            $row1 = mysql_fetch_assoc($banner1);
            $bannerpath1 = ($row1['bannerpath']);
            $bannerheight1 = ($row1['bannerheight']);
            $bannerwidth1 = ($row1['bannerwidth']);
            $bannerdescription1 = ($row1['bannerdescription']);  

            $banner2 = mysql_query("SELECT * FROM banner WHERE bannerid ='2'");
            $row2 = mysql_fetch_assoc($banner2);
            $bannerpath2 = ($row2['bannerpath']);
            $bannerheight2 = ($row2['bannerheight']);
            $bannerwidth2 = ($row2['bannerwidth']);
            $bannerdescription2 = ($row2['bannerdescription']);  


            $banner3 = mysql_query("SELECT * FROM banner WHERE bannerid ='3'");
            $row3 = mysql_fetch_assoc($banner3);
            $bannerpath3 = ($row3['bannerpath']);
            $bannerheight3 = ($row3['bannerheight']);
            $bannerwidth3 = ($row3['bannerwidth']);
            $bannerdescription3 = ($row3['bannerdescription']);  


?>

......

<h4>


<img src='<?php echo"$bannerpath1"; ?>' width='<?php echo"$bannerwidth1"; ?>' height='<?php echo"$bannerheight1"; ?>' border='0'> <?php echo"<font color='#8D38C9'>$bannerdescription1"; ?>
<br><br><br><br><br><br>

<img src='<?php echo"$bannerpath2"; ?>' width='<?php echo"$bannerwidth2"; ?>' height='<?php echo"$bannerheight2"; ?>' border='0'> <?php echo"<font color='#8D38C9'>$bannerdescription2"; ?>
<br><br><br><br><br><br>

<img src='<?php echo"$bannerpath3"; ?>' width='<?php echo"$bannerwidth3"; ?>' height='<?php echo"$bannerheight3"; ?>' border='0'> <?php echo"<font color='#8D38C9'>$bannerdescription3"; ?>
<br><br><br><br><br><br>

</h4>
Member Avatar for diafol
<?php
$output = "";
$rs = mysql_query("SELECT * FROM banner WHERE bannerid BETWEEN 1 AND 3);
while($d = mysql_fetch_assoc($rs)){
  $path = $d['bannerpath'];
  $height = $d['bannerheight'];
  $width = $d['bannerwidth'];
  $desc = $d['bannerdescription'];

$output .= "\n<img src=\"$path\" width=\"$width\" height=\"$height\" border=\"0\">\n<p class=\"desc\">$desc</p>";
}
?>

<h4>...</h4>
<?php echo $output;?>

Can't see why you want to keep all the html inside a h4. Also get rid of font and all the br. Give the description a class, so you can style it in CSS with font-color and margin-bottom.

Thanks! it is very useful!

If i want to add fix size border line to the output, how can i rewrite the code?

$output .= "\n<div style=\width=\615 \height=\100 \border-style=\solid \border-width=\1\><img src=\"$path\" width=\"$width\" height=\"$height\" border=\"1\"><font color='#8D38C9'>$desc<br><br></div>\n";

If i want to add fix size table with border line to each banner, how can i rewrite the code. it seems the banner out of table?

$output .= "\n<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-style: solid\" bordercolor=\"##8D38C9\" width=\"615px\" height=\100px\"><img src=\"$path\" width=\"$width\" height=\"$height\" border=\"1\"><font color='#8D38C9'>$desc</table><br><br><br>\n";
Member Avatar for diafol

Don't use attributes for styling tables leave it to CSS.
I don't understand why you're even using a table. You don't have any rows or cells.
If you really have to put it in a container use a div.

<div class = "rspics">
  <img src="..." height="..." width="..." />
  <p>...</p>
  <img src="..." height="..." width="..." />
  <p>...</p>
  <img src="..." height="..." width="..." />
  <p>...</p>
</div>

You could even div up the img+p pairs if you wanted them to appear adjacent to each other as opposed to on top.

The img and p elements can now be accessed via CSS:

#rspics{
 /* e.g. border, width, height, padding, margin, backgrounds */
}

#rspics img{
 /* e.g. border, padding, margin */
}

#rspics p{
 /* e.g. font attributes, padding, margin, background, border
}

I stil dunno how to use it. It seems not match the case of while loop output?

Member Avatar for diafol

Je m'excuse, je ne comprends pas

??? sorry i really don't know how to use? Can you teach me? I am so stupid to the javascripts!

Member Avatar for diafol

I don't know what you don't understand.

You have the script.

You have a div container which matches the name in the script.

I couldn't tell you why it doesn't work.

Try the js forum.

put it into an array and a foreach loop

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.