Jump to content

[SOLVED] 2 database entries per table row


EvilVamp

Recommended Posts

Hi there!

 

I'm doing a redesign to my website but I'm having trouble designing a table.  Basically, I want this kind of structure:

 

________________

|            |          |

| Entry 1 | Entry 2 |

|_______|________|

|          |            |

| Entry 3 | Entry 4 |

|_______|________|

|            |          |

| Entry 5 | Entry 6 |

|_______|________|

 

Its a databse with game info in it, So I'd be putting an image, a paragraph and a link in each 'entry cell', thats the easy bit, but its getting two entries on a row that I'm stuck on.  This is a link to the design so far: http://gamer.awardspace.co.uk/index3.php its the 'capsules' under 'recently added games' that I want to put the info into.  Each capsule being a different game.

 

I hope this makes sense! Any help is appreciated! Thanks!

Link to comment
https://forums.phpfreaks.com/topic/73999-solved-2-database-entries-per-table-row/
Share on other sites

This code worked great for me. You can set the # of columns as well. I used it to display 2 columns of subcategories in table cells pulling from the MySQL database.

 

// run query
$sql = "SELECT * FROM subcategories WHERE cat_id='2'";
$results = mysql_query($sql) or die(mysql_error());
// display results
$totalColumns = 2;
$i = 1;
echo "<table border='0' cellpadding='2'>";
while ($row = mysql_fetch_array($results)){
if ($i == 1) echo "<tr>";
echo "<td>";
echo "<a href='getcat.php?subcat_id=". $row['subcat_id'] . "'>" . $row['subcat_name'] . "</a>";
echo "</td>";
if ($i == $totalColumns)
	{
	echo "</tr>";
	$i = 0;
	}
$i++;
}
echo "</table>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.