fireice87 Posted August 15, 2007 Share Posted August 15, 2007 Intro Right iv got this website, with this webpage http://thewu.site23.co.uk/browseallprofiles3.php as you can see the data (pictures and usernames) are shown in a vertical line right down the page. what i want is to show them in a grid say 6x6 for example. My issue is well i cant figure out how to do it ill show you the code then explain why im stumped. Code <?php $conn = @mysql_connect( "blaaah", "nlaaah", "andblaaah") or die ("could not connect to mysql"); #Connect to mysql $rs = @mysql_select_db( "site23_thewu", $conn ) or die ("Could not select database"); #select database $sql = "Select `user` FROM profile_quickfacts"; //pull the users from the table $result= @mysql_query($sql, $conn ) or die(" Could not add style facts"); echo "<table>"; // display the users in table while($row = mysql_fetch_array($result)) { $user2 = $row['user']; echo "<tr>"; echo "<td>" ?><a href=" <?php echo "ViewProfile.php?view=$user2"?>"> <?php echo $user2 ?> </a><?php "</td>"; echo "</tr>"; echo "<td>" ?> <img src="DisplayPic_Tiny/<?php echo $row['user']?>.jpg"/> <?php "</td>"; // use the varaible row to display image DisplayPic_Tiny/user } ?> code explained Right so for each while loop the user is put into the variable $user2 this variable is then used to create the link to the users profile and to diaply there image, and its all displayed in a table. Problem i need about a 5x6 table not just a vertical line but i cant simply make the table in the while loop be 6x6 as it will keep displaying the same user. possible solution? I thought about maybe adding a (while $count < 6)style condition, so the loop would go around 6 times creating a vertical row of 6 then stop. and then do this again to the right of this table whitch would create a seconded vertical row of 6 so itd be 6x2, and repeating this till i had 6x5. The problem with this is i dont know how to start the seconed loop 6 rows down as too not display the same users. I hop this makes sense and im not over complicating the matter iv be at this for a while and my brains is a bit frazzeld so hopefully im making sense! thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/65080-solved-whilerow-mysql_fetch_array-displaying-with-table-issue/ Share on other sites More sharing options...
php_tom Posted August 15, 2007 Share Posted August 15, 2007 <?php $conn = @mysql_connect( "blaaah", "nlaaah", "andblaaah") or die ("could not connect to mysql"); #Connect to mysql $rs = @mysql_select_db( "site23_thewu", $conn ) or die ("Could not select database"); #select database $sql = "Select `user` FROM profile_quickfacts"; //pull the users from the table $result= @mysql_query($sql, $conn ) or die(" Could not add style facts"); echo "<table>"; // display the users in table $c = 0; while($row = mysql_fetch_array($result)) { $user2 = $row['user']; if($c%6 == 0) echo "<tr>"; // If the counter has ticked 6 times, start a new row. echo "<td><a href='ViewProfile.php?view=$user2'>$user2</a></td>"; echo "<br /><img src='DisplayPic_Tiny/".$row['user'].".jpg'/>"; // use the varaible row to display image DisplayPic_Tiny/user if($c%6 == 5) echo "</tr>"; // If we're drawing the 6th pic, end this row. $c++; } if($c%6 != 5) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row echo "</table>"; // end the table ?> Maybe this will help you. Quote Link to comment https://forums.phpfreaks.com/topic/65080-solved-whilerow-mysql_fetch_array-displaying-with-table-issue/#findComment-324819 Share on other sites More sharing options...
fireice87 Posted August 15, 2007 Author Share Posted August 15, 2007 Thank you that did help and put me very close to what i want but that script displays like this http://thewu.site23.co.uk/browseallprofiles4.php i have alterd the code slightly id got it too display how i want to in firefox but annoyling in Internet explorer 6 it looks completly diffrent http://thewu.site23.co.uk/browseallprofiles3.php firefox explorer heres the code as it is now <?php echo "<table>"; // display the users in table $c = 0; while($row = mysql_fetch_array($result)) { $user2 = $row['user']; if($c%5 == 0) echo "<tr height=\"150px\">"; // If the counter has ticked 6 times, start a new row. echo "<td><a href='ViewProfile.php?view=$user2'>$user2</a>"; echo "<img src='DisplayPic_Tiny/".$row['user'].".jpg'/></td>"; // use the varaible row to display image DisplayPic_Tiny/user if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row. $c++; } if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row echo "</table>"; // end the table ?> Iv tried alot of diffrent ways to get this to display right but cant get it right i thought the issue between the browsers may be due to the row height but that didnt work as both the link and the pic are in the same cell is it that internet explorer just orders things horizontally in this situation firefox orders things vertically once again any help one be great thanks ??? Quote Link to comment https://forums.phpfreaks.com/topic/65080-solved-whilerow-mysql_fetch_array-displaying-with-table-issue/#findComment-324998 Share on other sites More sharing options...
php_tom Posted August 15, 2007 Share Posted August 15, 2007 I think you want a <br /> tag in between the link and the pic. like so: <?php echo "<table>"; // display the users in table $c = 0; while($row = mysql_fetch_array($result)) { $user2 = $row['user']; if($c%5 == 0) echo "<tr height=\"150px\">"; // If the counter has ticked 6 times, start a new row. echo "<td><a href='ViewProfile.php?view=$user2'>$user2</a><br />"; echo "<img src='DisplayPic_Tiny/".$row['user'].".jpg'/></td>"; // use the varaible row to display image DisplayPic_Tiny/user if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row. $c++; } if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row echo "</table>"; // end the table ?> Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/65080-solved-whilerow-mysql_fetch_array-displaying-with-table-issue/#findComment-325067 Share on other sites More sharing options...
fireice87 Posted August 15, 2007 Author Share Posted August 15, 2007 ;D ;D Thank you again, youv helped me out alot with this and its greatly appreciated thank you! Quote Link to comment https://forums.phpfreaks.com/topic/65080-solved-whilerow-mysql_fetch_array-displaying-with-table-issue/#findComment-325071 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.