Dreamgirl Posted July 12, 2007 Share Posted July 12, 2007 Hello everyone, I am a php newbie and I would like some help. I am trying to display thumbnails on a page using the following code : <!--thumbnails of models--> <?php $sql = "SELECT * FROM MD_models ORDER BY name"; $recordset = mysql_query( $sql ) or die (mysql_error()); function pic_for_models($model_id) { $sql ="SELECT * FROM Pictures WHERE model_id='$model_id' LIMIT 1;"; $recordset = mysql_query ( $sql ) or die (mysql_error()); $row = mysql_fetch_assoc( $recordset ); return $row ['image']; } ?> <!--the list--> <?php while ( $row=mysql_fetch_assoc ($recordset) ) { $image = pic_for_models( $row["id"]); print '<tr><td><a href="model_detail.php?id='. $row['id']. '"><img src="'.$image.'" width="150" border="0"><br></td>'; print '<td><strong><a href="model_detail.php?id=' .$row["id"].'">' .$row ["name"].'</a></strong><br>'. $row ["phone"] ."<br><a href=\"mailto:\"". $row["email"] ."\" >". $row["email"]."</a>\n"; print "</td></tr>\n"; } ?> </table> The code works well my only problem is that each set of record is displaying as a row and vertical and I want it each set to be horizontal. This is a page I am doing with models pics and stats, so under each image I want the models info and stats but the next models picture and stats must be horizontal aligned to the last one. Link to comment https://forums.phpfreaks.com/topic/59575-help-needed-plz/ Share on other sites More sharing options...
EmperorJazzy Posted July 12, 2007 Share Posted July 12, 2007 Firstly, have a counter to count the numebr of columns you're displaying. I'd suggested setting the max at 3 columsn, but it's up to you and the screen resolution you're aiming for. Psuedo; Start New Table While Not (End of Models Returned in SQL) - Add 1 to Column Counter - Add New Row - Add New Cell - Display Photo - Display States - Close Cell - If Column Counter = 3 Then - Add Close Row Return To While Loop Essentially, writing code to this will ensure all stats are displayed across and down. If that's the desired result you're after. Hope this helps... Link to comment https://forums.phpfreaks.com/topic/59575-help-needed-plz/#findComment-296027 Share on other sites More sharing options...
Dreamgirl Posted July 12, 2007 Author Share Posted July 12, 2007 Thanks emperor jazzy, yeah its kind of what I am looking for the question I forgot to ask is I want to show 4 thumbnails +their info per row and as a new row is added the previous one gets pushed down. That means the latest info will always be on top. By the way I dont know php that well so if you dont mind editing or commenting my original code so i can follow along. Firstly, have a counter to count the numebr of columns you're displaying. I'd suggested setting the max at 3 columsn, but it's up to you and the screen resolution you're aiming for. Psuedo; Start New Table While Not (End of Models Returned in SQL) - Add 1 to Column Counter - Add New Row - Add New Cell - Display Photo - Display States - Close Cell - If Column Counter = 3 Then - Add Close Row Return To While Loop Essentially, writing code to this will ensure all stats are displayed across and down. If that's the desired result you're after. Hope this helps... Link to comment https://forums.phpfreaks.com/topic/59575-help-needed-plz/#findComment-296034 Share on other sites More sharing options...
EmperorJazzy Posted July 17, 2007 Share Posted July 17, 2007 Hey DreamGirl, Not sure if you've managed to solve your problem, so I'll attempt to contribute below. I'm also getting back into PHP after a few years of leave. You'll probably need to amend slightly when implementing. However; <table> <tr> <?php $col=0; while ( $row=mysql_fetch_assoc ($recordset) ) { $image = pic_for_models( $row["id"]); print '<td><a href="model_detail.php?id='. $row['id'].'"> <img src="'.$image.'" width="150" border="0"> <br>'; print '<strong><a href="model_detail.php?id='.$row["id"].'">'.$row ["name"].'[/url] </strong>'.$row ["phone"] ." <br><a href=\"mailto:\"". $row["email"] ."\" >". $row["email"]."[/url]\n"; print "</td>\n"; if ($col=4) then { $col=0 ?> </tr> <tr> <? } } ?> </tr> </table> Have a go at that..... It's rough, and untested. Link to comment https://forums.phpfreaks.com/topic/59575-help-needed-plz/#findComment-299949 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.