PDA

View Full Version : Need help with this



iJoe
07-08-2009, 08:11 PM
Hi,

I'm trying to grab information from one table in the database based on info from another database. That works fine and it's giving out the right results, however. I want the information to be displayed in a table, I currently have this code and it's not working properly so is anyone able to fix it?

Thanks,

Joe


<?php
$result = mysql_query("SELECT * FROM site_game_favs WHERE uid='{$_GET['user']}'") or die(mysql_error());

while($row=mysql_fetch_array($result)) {
$result2 = mysql_query("SELECT * FROM site_games WHERE id='{$row['gid']}'") or die(mysql_error());
$row2=mysql_fetch_array($result2);

$tdcount = 1;
$numtd = 3; // number of cells per row
echo "<table>";

$tdcount = 1;
$numtd = 4; // number of cells per row
echo "<table>";

if ($tdcount == 1) echo "<tr>";
echo "<td><div class='right-top'></div><div class='right-mid'><center><img src='http://www.nexdana.com/thumbs/{$row2['img']}' height='50' width='50' style='float:left'> <a href='http://www.nexdana.com/new/?page=load_game&id={$row2['id']}' class='greenlink'> {$row2['name']}</a><br> Added to yout favourites on: {$row['date']}</center></div><div class='right-bot'></div></td>"; // display as you like
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}

// time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++;
}
echo "</tr>";
}
echo "</table>";

}
?>

(Database is connected to in a different code)

Fehm
07-08-2009, 08:29 PM
Wont the connection to the database have to be included in that code as well though?

iJoe
07-08-2009, 08:44 PM
It's on the same page, just above that which is why it's not shown ;) Don't worry, that parts working fine. The current output I'm getting is this...

http://img6.imageshack.us/img6/563/20922070.png

Trinity
07-08-2009, 11:05 PM
It's on the same page, just above that which is why it's not shown ;) Don't worry, that parts working fine. The current output I'm getting is this...

http://img6.imageshack.us/img6/563/20922070.png

What is it meant to look like?

iJoe
07-08-2009, 11:25 PM
I want it to be in a table, 3 across and however many down. Obviously it will vary by the amount of results

RichardKnox
08-08-2009, 01:00 AM
its because you're echoing the table code after the mysql_fetch_array which means for each row it'll make a <table>, put that BEFORE the query and it should work

Dentafrice
08-08-2009, 02:00 PM
its because you're echoing the table code after the mysql_fetch_array which means for each row it'll make a <table>, put that BEFORE the query and it should work
When he does <table>, there is nothing above it that echos. Also when he echo's <table>, it's not in the loop.. so that doesn't matter.

I think you're misinformed of how tables work.

Every loop iteration, you're creating a new row.

http://img.skitch.com/20090808-gwcg1ab4smfxajsww5mby3h4hy.png

So of course it's going to go on top of each other, instead of side by side if you'e creating a new ROW each time it goes through.

So why not style it via CSS, instead of tables.. and have it float: left; position: relative; display: block; I think.. and it should make it go...

[] [] [] []
[] [] [] []
[] [] [] []

all depending on what you're width is set at..

If someone a lot better at CSS could chime in, that would help ;)

Blob
08-08-2009, 02:13 PM
When he does <table>, there is nothing above it that echos. Also when he echo's <table>, it's not in the loop.. so that doesn't matter.

I think you're misinformed of how tables work.

Every loop iteration, you're creating a new row.

http://img.skitch.com/20090808-gwcg1ab4smfxajsww5mby3h4hy.png

So of course it's going to go on top of each other, instead of side by side if you'e creating a new ROW each time it goes through.

So why not style it via CSS, instead of tables.. and have it float: left; position: relative; display: block; I think.. and it should make it go...

[] [] [] []
[] [] [] []
[] [] [] []

all depending on what you're width is set at..

If someone a lot better at CSS could chime in, that would help ;)

Just have a div which width is e.g 930px width then have the things inside at 300px wide with 10px margin to the right, and all you need is float: left;

RichardKnox
08-08-2009, 04:49 PM
My mistake, mis-read the code at 2AM this morning :P

Dentafrice
08-08-2009, 05:08 PM
My mistake, mis-read the code at 2AM this morning :P
I just realized I quoted you when I said you was misinformed of how tables worked.. I didn't mean that aimed at you, meant it aimed at the original poster haha. I was just telling you the <table> wasn't in a loop :P

iJoe
08-08-2009, 06:41 PM
Got it all sorted now, thanks all :)

Dentafrice
08-08-2009, 10:45 PM
What was the problem?

Want to hide these adverts? Register an account for free!