Reply to Re: foreach woes

Your name:

Reply:


Posted by strawberry on 06/07/06 17:56

Perfect. Thank you very much.

ZeldorBlat wrote:
> strawberry wrote:
> > I'm trying to extend the script(s) provided at
> > www.phpriot.com/d/articles/client-side/sortable-lists-with-php-and-ajax/.
> > I'm struggling with the foreach syntax - I guess I'm just a dummy. I
> > still don't get it despite reading through http://uk.php.net/foreach.
> >
> > Basically, there's a movie table (`movie_id`, `title`, `description`,
> > `ranking`).
> >
> > and a function that gets the movies:
> >
> > function getMovies()
> > {
> > $query = 'select movie_id, title, description from movies order
> > by ranking, lower(title)';
> > $result = mysql_query($query);
> >
> > $movies = array();
> > while ($row = mysql_fetch_object($result)) {
> > $movies[$row->movie_id] = $row->title;
> > }
> >
> > return $movies;
> > }
> >
> >
> > and here's where the titles are displayed on the page:
> >
> > <ul id="movies_list" class="sortable-list">
> > <?php foreach ($movies as $movie_id => $title) { ?>
> > <li id="movie_<?= $movie_id ?>"><?= $title ?></li>
> > <?php } ?>
> > </ul>
> >
> > For each movie what do I need to do to echo the movie description -
> > within the <li> statement for instance.
> >
> > Hope that makes sense. Any help appreciated.
>
> In the getMovies() function, change the while loop to something like
> this:
>
> while ($row = mysql_fetch_object($result)) {
> $movies[] = $row;
> }
>
> And when you display them:
>
> foreach($movies as $movie) {
> //$movie->movie_id is the movie_id
> //$movie->title is the title
> //$movie->description is the description
> }

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация