beamerrox Posted March 9, 2006 Share Posted March 9, 2006 [code]CREATE TABLE `map` ( `id` int(255) NOT NULL, `name` varchar(50) NOT NULL default '', `size` int(25) NOT NULL default '0', `creator` varchar(100) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM AUTO_INCREMENT=2;INSERT INTO `map` (`id`, `name`, `size`, `creator`) VALUES (1, 'Test Galaxy', 25, 'Beamerrox (Site Owner)');[/code][code]CREATE TABLE `systems` ( `id` int(255) NOT NULL, `map_id` int(255) NOT NULL default '0', `local` varchar(255) NOT NULL default '', `family` int(100) NOT NULL default '0', `name` varchar(10) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM AUTO_INCREMENT=5;INSERT INTO `systems` (`id`, `map_id`, `local`, `family`, `name`) VALUES (1, 1, '1, 1', 1, 'Family 1');INSERT INTO `systems` (`id`, `map_id`, `local`, `family`, `name`) VALUES (2, 1, '25, 1', 2, 'Family 2');INSERT INTO `systems` (`id`, `map_id`, `local`, `family`, `name`) VALUES (3, 1, '1, 25', 3, 'Family 3');INSERT INTO `systems` (`id`, `map_id`, `local`, `family`, `name`) VALUES (4, 1, '25, 25', 4, 'Family 4');[/code][code]<?$db = mysql_connect("", "", "");mysql_select_db("", $db);?><table border="1" cellpadding="2" cellspacing="0"><?$map = mysql_fetch_assoc(mysql_query("SELECT * FROM map WHERE id={$_GET['id']}"));$i = 1;for($i; $i <= $map['size']; $i++){?><tr><?$j = 1;for($j; $j <= $map['size']; $j++){$local = "$i, $j"$res = mysql_query("SELECT * FROM systems WHERE local='$local'");?><td><? if($res){ echo "1"; } else { echo "0"; } ?></td><?}?></tr><?}?></table>[/code]i want this page so that it doesn't post all the cells with a 1 in each, the way it is set up is so it only posts the 4 systems to the map that is 25x25, so there should be 4 ones and 421 zeros, i don't know how to make this work[EDIT]fixed part of the coding, still have the same problem though Link to comment https://forums.phpfreaks.com/topic/4502-solved-dynamic-table-help/ Share on other sites More sharing options...
Barand Posted March 9, 2006 Share Posted March 9, 2006 $res will be false only if the query fails due to an error. Finding 0 results is not an error.Change[code]if($res){ echo "1"; } else { echo "0"; } [/code]to[code]if (mysql_num_rows($res) > 0){ echo "1"; } else { echo "0"; } [/code] Link to comment https://forums.phpfreaks.com/topic/4502-solved-dynamic-table-help/#findComment-15702 Share on other sites More sharing options...
beamerrox Posted March 9, 2006 Author Share Posted March 9, 2006 whoa, maybe it wasn't so advanced, thank you, it fixed it right away Link to comment https://forums.phpfreaks.com/topic/4502-solved-dynamic-table-help/#findComment-15935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.