Jump to content

Need help displaying multiple rows within a while loop.


McBryver

Recommended Posts

So here is what I a trying to do:

 

 
<?php

/**
* @author 
* @copyright 2010
*/
$res = mysql_query("SELECT * FROM `planetsTable` WHERE `section` = '1' LIMIT 9 ASC");
while($row = mysql_fetch_array($res)){ ?>
  
  
            <li>
            <span id="sun">Solar System Star</span>
            <p>The Sun is a star, a hot ball of glowing gases at the heart of our solar system. Its influence extends far beyond the orbits of distant Neptune and Pluto. Without the Sun's intense energy and heat, there would be no life on Earth. And though it is special to us, there are billions of stars like our Sun scattered across the Milky Way galaxy.</p>
            </li>
  
        <li>
            <span id="mercury"><?php echo $row[0]['name']; ?></span>
            <p>Sun-scorched Mercury is only slightly larger than Earth's Moon. Like the Moon, Mercury has very little atmosphere to stop impacts and it is covered with craters. Mercury's dayside is super heated by the Sun, but at night temperatures drop hundreds of degrees below freezing. Ice may even exist in craters. Mercury's egg-shaped orbit takes it around the Sun every 88 days.</p>

            </li>
            
            <li>
            <span id="venus"><?php echo $row[1]['name']; ?></span>
            <p>Venus is a dim world of intense heat and volcanic activity. Similar in structure and size to Earth, Venus' thick, toxic atmosphere traps heat in a runaway 'greenhouse effect.' The scorched world has temperatures hot enough to melt lead. Glimpses below the clouds reveal volcanoes and deformed mountains. Venus spins slowly in the opposite direction of most planets.</p>
            </li>
            
            <li>
            <span id="earth"><?php echo $row[3]['name']; ?></span>

            <p>Earth is an ocean planet. Our home world's abundance of water - and life - makes it unique in our solar system. Other planets, plus a few moons, have ice, atmospheres, seasons and even weather, but only on Earth does the whole complicated mix come together in a way that encourages life - and lots of it.</p>
            </li>
            
            <li>
            <span id="mars"><?php echo $row[4]['name']; ?></span>
            <p>Though details of Mars' surface are difficult to see from Earth, telescope observations show seasonally changing features and white patches at the poles. For decades, people speculated that bright and dark areas on Mars were patches of vegetation, that Mars could be a likely place for life-forms, and that water might exist in the polar caps. When the Mariner 4 spacecraft flew by Mars in 1965, many were shocked to see photographs of a bleak, cratered surface. Mars seemed to be a dead planet. Later missions, however, have shown that Mars is a complex member of the solar system and holds many mysteries yet to be solved.</p>
            </li>
            
            <li>

            <span id="jupiter"><?php echo $row[5]['name']; ?></span>
            <p>The most massive planet in our solar system, with four large moons and many smaller moons, Jupiter forms a kind of miniature solar system. Jupiter resembles a star in composition. In fact, if it had been about 80 times more massive, it would have become a star rather than a planet.</p>
            </li>
            
            <li>
            <span id="saturn">Saturn</span>
            <p>Saturn was the most distant of the five planets known to the ancients. Like Jupiter, Saturn is made mostly of hydrogen and helium. Its volume is 755 times greater than that of Earth. Winds in the upper atmosphere reach 500 meters (1,600 feet) per second in the equatorial region. These super-fast winds, combined with heat rising from within the planet's interior, cause the yellow and gold bands visible in the atmosphere.</p>
            </li>

            
            <li>
            <span id="uranus">Uranus</span>
            <p>The first planet found with the aid of a telescope, Uranus was discovered in 1781 by astronomer William Herschel. The seventh planet from the Sun is so distant that it takes 84 years to complete one orbit.</p>
            </li>
            
            <li>
            <span id="neptune">Neptune</span>
            <p>Nearly 4.5 billion kilometers (2.8 billion miles) from the Sun, Neptune orbits the Sun once every 165 years. It is invisible to the naked eye because of its extreme distance from Earth. Interestingly, the unusual elliptical orbit of the dwarf planet Pluto brings Pluto inside Neptune's orbit for a 20-year period out of every 248 Earth years</p>

            </li>
            
            <li>
            <span id="pluto">Pluto</span>
            <p>Tiny, cold and incredibly distant, Pluto was discovered in 1930 and long considered to be the ninth planet. But after the discoveries of similar intriguing worlds even farther out, Pluto was reclassified as a dwarf planet. This new class of worlds may offer some of the best evidence of the origins of our solar system.</p>
            </li>
        </ul>	
    
<?}

?>

 

What I need to know is if this is possible and if so how would I got about doing this?

<?php 
$row['0']['name']; // Main Issue.
?>

McBryver

Link to comment
Share on other sites

i think your missing the point of using a loop!

all you need to do is:

            <li>
            <span id="sun">Solar System Star</span>
            <p>The Sun is a star, a hot ball of glowing gases at the heart of our solar system. Its influence extends far beyond the orbits of distant Neptune and Pluto. Without the Sun's intense energy and heat, there would be no life on Earth. And though it is special to us, there are billions of stars like our Sun scattered across the Milky Way galaxy.</p>
            </li>
<?php
$res = mysql_query("SELECT * FROM `planetsTable` WHERE `section` = '1' LIMIT 9 ASC");
while($row = mysql_fetch_array($res)){ ?> 
        <li>
            <span id="<?php echo $row['name'] ?>"><?php echo $row['name']; ?></span>
            <p><?php echo $row['name_of_column_holding_the_description_about_this_planet'] ?></p>
        </li>
<?php } // end of loop through all the planets ?>

Link to comment
Share on other sites

As your code is, you will print out 90 rows (10 items in a loop which executes 9 times). I don't believe you want that. Hopefully your planetsTable has a description filed, otherwise there's not much point in using the DB to print out this list.

 

?>
<ul>
           <li>
            <span id="sun">Solar System Star</span>
            <p>The Sun is a star, a hot ball of glowing gases at the heart of our solar system. Its influence extends far beyond the orbits of distant Neptune and Pluto. Without the Sun's intense energy and heat, there would be no life on Earth. And though it is special to us, there are billions of stars like our Sun scattered across the Milky Way galaxy.</p>
            </li>
<?php

$res = mysql_query("SELECT * FROM `planetsTable` WHERE `section` = '1' LIMIT 9 ASC");
while($row = mysql_fetch_array($res)){ ?>
   $name = $row['name'];
   $key = strtolower($name); 
   $description = $row['description']; 

?>
        <li>
            <span id="<?php echo $key; ?>"><?php echo $name; ?></span>
            <p><?php echo $rdescription; ?></p>

        </li>
   
<?}

?>
</ul>

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.