Jump to content


Photo

**solved** Dynamic Table Help


  • Please log in to reply
2 replies to this topic

#1 beamerrox

beamerrox
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationGrimshaw, Alberta, Canada

Posted 09 March 2006 - 04:09 AM

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

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


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

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 March 2006 - 07:26 AM

$res will be false only if the query fails due to an error. Finding 0 results is not an error.

Change

if($res){ echo "1"; } else { echo "0"; }

to

if (mysql_num_rows($res) > 0){ echo "1"; } else { echo "0"; }

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 beamerrox

beamerrox
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationGrimshaw, Alberta, Canada

Posted 09 March 2006 - 10:18 PM

whoa, maybe it wasn't so advanced, thank you, it fixed it right away




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users