realjumper Posted October 20, 2008 Share Posted October 20, 2008 Hi, I currently have a static page for book reviews. The reviews consist of a title showing Book and Author.....next line is a left aligned image of the book, plus the text. The next review is the same as the above, except that the image is right aligned......the next review the image is left aligned and the next review the image is right aligned and so on. I am going to make an admin panel so that the administrator can add/delete reviews without me having to physically type the html. I have the DB setup ok as well as the image upload/resize etc and all that is good....BUT.....when they (1) add a new review, how can I code the loop to keep the first review image left aligned, the second review image right aligned etc etc.......and (2) how can I achieve the smae if the administrator deletes a review in the middle of the page? I can write a loop to make the images always left, or right aligned (see code) but how do I make the images alternate between left and right alinement? // Retrieve all the data from the table $result = mysql_query("SELECT * FROM library_images WHERE review_type = 'Book'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<img src=\"images/books/$row[image]\" align=\"left\">"; echo "<h3>$row[name] <em>by</em> $row[author]</h3>"; echo "<p align=\"justify\">$row[review_text]</p>"; echo "<p> </p>"; } Link to comment https://forums.phpfreaks.com/topic/129164-solved-while-loop-layout-question/ Share on other sites More sharing options...
realjumper Posted October 20, 2008 Author Share Posted October 20, 2008 I suppose I could do a num_rows count and alternate between odd and even numbers? Link to comment https://forums.phpfreaks.com/topic/129164-solved-while-loop-layout-question/#findComment-669675 Share on other sites More sharing options...
unrelenting Posted October 20, 2008 Share Posted October 20, 2008 I'd do it like this: // Retrieve all the data from the table $result = mysql_query("SELECT * FROM library_images WHERE review_type = 'Book'") or die(mysql_error()); $i=0; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table if ($i % 2) { echo "<img src=\"images/books/$row[image]\" align=\"left\">"; } else { echo "<img src=\"images/books/$row[image]\" align=\"right\">"; } echo "<h3>$row[name] <em>by</em> $row[author]</h3>"; echo "<p align=\"justify\">$row[review_text]</p>"; echo "<p> </p>"; $i++; } Link to comment https://forums.phpfreaks.com/topic/129164-solved-while-loop-layout-question/#findComment-669676 Share on other sites More sharing options...
realjumper Posted October 20, 2008 Author Share Posted October 20, 2008 I'd do it like this: <snip> Yep, that's the sort of thing I was thinking but couldn't get the syntax working...thanks Link to comment https://forums.phpfreaks.com/topic/129164-solved-while-loop-layout-question/#findComment-669678 Share on other sites More sharing options...
unrelenting Posted October 20, 2008 Share Posted October 20, 2008 I'd do it like this: <snip> Yep, that's the sort of thing I was thinking but couldn't get the syntax working...thanks Not a problem. Link to comment https://forums.phpfreaks.com/topic/129164-solved-while-loop-layout-question/#findComment-669680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.