newb Posted June 11, 2006 Share Posted June 11, 2006 [code]<?phpinclude "../inc/connect.php";$result = mysql_query("SELECT id, title, artist, thumb FROM pictures WHERE id='1'");$result2 = mysql_query("SELECT id, title, artist, thumb FROM pictures WHERE id='2'")or die(mysql_error()); while($row = mysql_fetch_array( $result )) {$thumb = $row['thumb'];$title = $row['title'];$artist = $row['artist'];while($row = mysql_fetch_array( $result2 )) {$thumb2 = $row['thumb'];$title2 = $row['title'];$artist2 = $row['artist'];}echo "<p align='left'><font face='Arial'><b>My Thumbnails</b></font><br><br></p><table border='0' width='100%' id='table1'> <tr> <td width='33%' valign='top' height='65'> $thumb<br> Title: $title<br> Artist(s): $artist </td> <td width='33%' valign='top' height='65'> $thumb2<br> Title: $title2<br> Artist(s): $artist2[/code] This code works fine. The problem is, I dont wan't to keep copying and pasting, adding repetitive code to the file. I was hoping there was a way to avoid doing this. It would save me alot of time and work. I just want to grab the data from the database. Anyone think they can help me with this? If so let me know, thanks. Link to comment https://forums.phpfreaks.com/topic/11690-is-there-anyway-to-shorten-this/ Share on other sites More sharing options...
Masna Posted June 11, 2006 Share Posted June 11, 2006 Use the while loops you're already using.Wait a minute... Do you know what the while loop is for? Link to comment https://forums.phpfreaks.com/topic/11690-is-there-anyway-to-shorten-this/#findComment-44186 Share on other sites More sharing options...
newb Posted June 11, 2006 Author Share Posted June 11, 2006 Nope, I'm basically trying to figure out how to print the data on the page without having to copy and paste all that code over and over and modifying it (thumb3, thumb4, thumb5, etc...). It's enough that I have to insert it all in the SQL db. Link to comment https://forums.phpfreaks.com/topic/11690-is-there-anyway-to-shorten-this/#findComment-44190 Share on other sites More sharing options...
.josh Posted June 11, 2006 Share Posted June 11, 2006 [code]<?phpinclude "../inc/connect.php";$result = mysql_query("SELECT id, title, artist, thumb FROM pictures") or die(mysql_error()); echo "<p align='left'><font face='Arial'><b>My Thumbnails</b></font><br><br></p>";echo "<table border='0' width='100%' id='table1'>";while($row = mysql_fetch_array( $result )) { $thumb = $row['thumb']; $title = $row['title']; $artist = $row['artist']; echo "<tr>"; echo "<td width='33%' valign='top' height='65'>"; echo "$thumb<br>"; echo "Title: $title<br>"; echo "Artist(s): $artist"; echo "</td>"; echo "</tr>";}echo "</table>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/11690-is-there-anyway-to-shorten-this/#findComment-44193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.