Jump to content

[SOLVED] 'while($row = mysql_fetch_array' displaying with table issue


fireice87

Recommended Posts

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 ;)

 

 

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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

fire.jpg

explorer

explorer.jpg

 

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 ???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.