grlayouts Posted February 16, 2010 Share Posted February 16, 2010 can anyone help me i have a mysql database for the code <?php function gloss($word, $team) { $sql = "SELECT `team{$team}` FROM glossary WHERE word='{$word}'"; return ret11($sql); } echo gloss("title", $teamid) .', Welcome to your <B>' .gloss("barracks",$teamid) . '</B>!'; ?> but they way i've made the table in the database it's not working. I think this is more sql help but i can provide the table i have made if it helps? can someone help me out with the layout or point me in the right direction? [/code] EDIT DATaBASE CODE -- -- Table structure for table `glossary` -- CREATE TABLE IF NOT EXISTS `glossary` ( `title` text NOT NULL, `barracks` text NOT NULL, `word` text NOT NULL, `team` int(11) NOT NULL, ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/ Share on other sites More sharing options...
PHP Monkeh Posted February 16, 2010 Share Posted February 16, 2010 That's some pretty awful design, but the error probably lies in the ret11() function. Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/#findComment-1013190 Share on other sites More sharing options...
Psycho Posted February 16, 2010 Share Posted February 16, 2010 You are using some custom functions to do your database activities: ret11() and gloss(). So, there is no way for us to know what the problem really is. I doubt this has anything to do with your database structure. The only thing I can *guess* from the code you have provided is that it looks like you are only querying for the "team" field, but you are trying to use results for "title" and "barracks". In fact, the variable $team in the query makes no sense. It is being concatenated to the field name "team" and you have no fields in the database with team and additional characters. Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/#findComment-1013192 Share on other sites More sharing options...
grlayouts Posted February 16, 2010 Author Share Posted February 16, 2010 what parts of the code would i need to provide for it to make sense? Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/#findComment-1013239 Share on other sites More sharing options...
Maq Posted February 16, 2010 Share Posted February 16, 2010 what parts of the code would i need to provide for it to make sense? We need to see the ret11() method. Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/#findComment-1013244 Share on other sites More sharing options...
grlayouts Posted February 16, 2010 Author Share Posted February 16, 2010 function ret11($sql) { $r = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows($r) == 0) { return 0; } $row = mysql_fetch_row($r); return $row[0]; } Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/#findComment-1013322 Share on other sites More sharing options...
premiso Posted February 16, 2010 Share Posted February 16, 2010 You do not have the column team{$team} in your database design. Not sure what you want, perhaps an AND statement? $sql = "SELECT `team` FROM glossary WHERE word='{$word}' AND team = '{$team}'"; Given that you have the or die mysql_error, you should have been given an error that the column team$team does not exist (whatever $team is). Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/#findComment-1013329 Share on other sites More sharing options...
mattal999 Posted February 16, 2010 Share Posted February 16, 2010 No, this is what your function needs to look like: function gloss($word, $team) { $sql = "SELECT `{$word}` FROM glossary WHERE team='{$team}'"; return ret11($sql); } Although I must say everytime you call that function you are basically running a query. You could just run one at the top of the page and use the results to show all the columns. Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/#findComment-1013331 Share on other sites More sharing options...
grlayouts Posted February 16, 2010 Author Share Posted February 16, 2010 yeah i have have but i added a column for team1 and team2.. the glossery should find the word realting to the team and display it but i dont think the databse layout is right. Quote Link to comment https://forums.phpfreaks.com/topic/192264-database-structure/#findComment-1013337 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.