archonis Posted December 23, 2009 Share Posted December 23, 2009 There has to be a way to do this. Here is my code. Trying to pull the last nine dates then display that infomation in the row without having to write my html as echo. any help or tips? // Connect to server and select databse. mysql_connect("$host", "$dbusername", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $date = date("Y-m-d"); // Make a MySQL Connection $result = mysql_query("SELECT * FROM MEMBERS ORDER BY DATE DESC limit 9") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $showmyphoto = "<center><a href=\"http://www.mytowndate.com/profile.php?id=" . $row['username'] . "\"><img src=\"http://www.mytowndate.com/".$row['photo'] ."\" width=\"90\" height=\"94\"><a>"; ?> <table width="70%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="30%"><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row(1)['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row(1)['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row(1)['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row(1)['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row(1)['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> <td width="33%"><table width="217" border="0"> <tr> <td width="211"><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row(2)['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row(2)['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row(2)['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row(2)['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row(2)['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> <td width="37%"><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row(3)['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row(3)['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row(3)['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row(3)['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row(3)['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> </tr> <tr> <td><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row(4)['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row(4)['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row(4)['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row(4)['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row(4)['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> <td><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row(5)['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row(5)['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row(5)['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row(5)['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row(5)['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> <td><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row(6)['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row(6)['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row(6)['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row(6)['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row(6)['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> </tr> <tr> <td><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row(7)['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row(7)['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row(7)['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row(7)['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row(7)['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> <td><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row(['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row(['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row(['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row(['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row(['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> <td><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style16"><?php echo $row['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table> <?php } ?></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/ Share on other sites More sharing options...
taquitosensei Posted December 23, 2009 Share Posted December 23, 2009 what do you need this to look like. Because you have too many brackets. You really only need the while($row= loop each time through is the next row so you don't need the numbers after the arrays $row(1) should be just $row You're table structure is a bit confusing I think you're making it too complicated. Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-982806 Share on other sites More sharing options...
archonis Posted December 23, 2009 Author Share Posted December 23, 2009 This is a include file. Its one table and in that table its 3 rows with 3 blocks. here is a url http://www.mytowndate.com/modrecent.php Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-982807 Share on other sites More sharing options...
trq Posted December 23, 2009 Share Posted December 23, 2009 You need to understand that whatever is within a loop is repeated while that loop iterates. eg; if ($result = mysql_query("SELECT * FROM MEMBERS ORDER BY DATE DESC limit 9")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { echo "this content will repeat until \$result is empty<br />"; } } } What that means is you only need to code the repeating html table elements once within your loop and they will be created however many times the loop iterates over. Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-982810 Share on other sites More sharing options...
archonis Posted December 23, 2009 Author Share Posted December 23, 2009 take a look at http://www.mytowndate.com/modrecent.php I had a feeling this was going to happen. // Connect to server and select databse. mysql_connect("$host", "$dbusername", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $date = date("Y-m-d"); $result = mysql_query("SELECT * FROM members ORDER BY online DESC limit 9") or die(mysql_error()); while($row = mysql_fetch_array($result)) { ?> <table width="70%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="30%"><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style1"><?php echo $row['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table></td> <td width="33%"><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style1"><?php echo $row['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table></td> <td width="37%"><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?> </td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style1"><?php echo $row['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table></td> </tr> </table> <?php } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-982823 Share on other sites More sharing options...
trq Posted December 23, 2009 Share Posted December 23, 2009 What part of "whatever is within a loop is repeated while that loop iterates" don't you understand? Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-982863 Share on other sites More sharing options...
archonis Posted December 23, 2009 Author Share Posted December 23, 2009 REALY NO!, Yes i understand that! Did you look at the link i provided? If you did you will see i have no problem putting them on top of each other. But there is rows of three. I dont know how to do part so it looks like this. 111 222 333 and not 123 456 789 Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-983033 Share on other sites More sharing options...
mrMarcus Posted December 23, 2009 Share Posted December 23, 2009 how it is now is repeating the same "profile" 3 times in the same row. as per your last comment, that is the desired result? and a little off-topic. you should really resize the profile pictures. i clicked on one and it is over 1MB. instead, you are just changing the size of the image within the image tag, but that doesn't take away from the images attributes. think about 1,000 hits on one profile with that image being displayed 1,000 times at 1MB per visit. 1 gig worth of bandwidth gone over a picture. Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-983089 Share on other sites More sharing options...
archonis Posted December 23, 2009 Author Share Posted December 23, 2009 the end result is to sort the database by login dates and display the last 9 that has logged in. Each block is a user. 123 456 789 and not 111 222 333 444 555 666 777 888 999 Yea, Thanks about the photo thing. Im working on that. Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-983123 Share on other sites More sharing options...
mrMarcus Posted December 23, 2009 Share Posted December 23, 2009 k, well your previous comment stated otherwise: 111 222 333 and not 123 456 789 Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-983125 Share on other sites More sharing options...
archonis Posted December 24, 2009 Author Share Posted December 24, 2009 Anyhow I can't find out how to make it look like this 123 457 789 I been searching for days and what I do find and alter it does not work right Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-983419 Share on other sites More sharing options...
archonis Posted December 27, 2009 Author Share Posted December 27, 2009 this is where i am at. its still a no go // Connect to server and select databse. mysql_connect("$host", "$dbusername", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $date = date("Y-m-d"); $result = mysql_query("SELECT * FROM members ORDER BY online DESC limit 9") or die(mysql_error()); echo '<table width=/"70%/" border=/"0/" cellspacing=/"0/" cellpadding=/"0/"><tr><td width=/"30%/"><tr>'; while($row = mysql_fetch_array($result)) { if($x == 3){ echo '</tr></table>'; echo '<table width=/"70%/" border=/"0/" cellspacing=/"0/" cellpadding=/"0/"><tr><td width=/"30%/"><tr>'; $x=0; } else{ $x++; ?> <td><table width="220" border="0"> <tr> <td><table width="100%" border="0"> <tr> <td width="47%" rowspan="4" align="left" valign="top" bordercolor="#FF0000" bgcolor="#FFFFFF"><table width="90" height="94" border="1" bordercolor="#FF0000" bgcolor="#FFFFFF"> <tr> <td height="102" bordercolor="#FF0000"><?php echo $showmyphoto; ?></td> </tr> </table></td> <td height="21" align="left" valign="top"><div align="center"><strong><span class="style1"><?php echo $row['username'] ?></span></div></td> </tr> <tr> <td height="21" align="left" valign="top">Age:<?php echo $row['age'] ?></td> </tr> <tr> <td height="21" align="left" valign="top">City:<?php echo $row['city']; ?></td> </tr> <tr> <td height="26" align="left" valign="top">State:<?php echo $row['state']; ?></td> </tr> <tr> <td colspan="2" align="center" valign="top"><?php echo "<a href=\"http://www.mytowndate.com/profile.php?id=" . $row['username'] . "\">"; ?>VIEW PROFILE</td> </tr> </table></td> </tr> </table></td> <?php } }echo '</tr></table>'; ?></body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-984614 Share on other sites More sharing options...
archonis Posted December 27, 2009 Author Share Posted December 27, 2009 its almost there but i have a border and the last two gets droped off http://www.mytowndate.com/modrecent.php Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-984615 Share on other sites More sharing options...
archonis Posted December 29, 2009 Author Share Posted December 29, 2009 no more help? Quote Link to comment https://forums.phpfreaks.com/topic/186100-need-some-help-here-guys-confused/#findComment-985558 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.