apw Posted September 25, 2009 Share Posted September 25, 2009 Hello im trying to preform a simple query im trying to pull all the fields in the column yet only those by the players name. The table is my uk_user_buildings and contain the fields id, charname, level and building_name the table cnntains every player buildings but i only want say playerA buildings and not players B and C. How would i query the database to do this? Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/ Share on other sites More sharing options...
Maq Posted September 25, 2009 Share Posted September 25, 2009 A simple WHERE clause should do the trick. In your example what column would playerA be in? charname? Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-924829 Share on other sites More sharing options...
apw Posted September 25, 2009 Author Share Posted September 25, 2009 Yes, playerA is charname .. Ive tried doing where by id and by charname but get no results Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-924832 Share on other sites More sharing options...
Maq Posted September 25, 2009 Share Posted September 25, 2009 Should just be a simple select query with a where clause: SELECT building_name FROM uk_user_buildings WHERE charname = 'playerA' Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-924834 Share on other sites More sharing options...
apw Posted September 25, 2009 Author Share Posted September 25, 2009 Would your example pull all the fields id, charname, level, building_name for that specific player so playerB doesnt see what playerA has Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-924840 Share on other sites More sharing options...
Maq Posted September 25, 2009 Share Posted September 25, 2009 No, only building_name. Read the documentation on MySQL SELECT. If you want more fields then either specify them in the select or, if you need all of them, use *. so playerB doesnt see what playerA has Not sure what you mean by this. Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-924847 Share on other sites More sharing options...
apw Posted September 25, 2009 Author Share Posted September 25, 2009 Each player shares the uk_user_building which holds what every building each player has built if i use * it shows every player what i want to do is limit so playerA sees only their buildingsB and so on Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-924980 Share on other sites More sharing options...
Maq Posted September 25, 2009 Share Posted September 25, 2009 Each player shares the uk_user_building which holds what every building each player has built if i use * it shows every player what i want to do is limit so playerA sees only their buildingsB and so on That's the whole point of the WHERE clause, to only select a specific player. The * just selects all of the fields for that specific player. Maybe post your table structure, sample data, and what you want to output to be based off of a scenario. Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-924984 Share on other sites More sharing options...
apw Posted September 25, 2009 Author Share Posted September 25, 2009 Database dump: -- phpMyAdmin SQL Dump -- version 3.2.0.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Sep 25, 2009 at 04:21 PM -- Server version: 5.1.37 -- PHP Version: 5.3.0 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `dk` -- -- -------------------------------------------------------- -- -- Table structure for table `dk_user_buildings` -- CREATE TABLE IF NOT EXISTS `dk_user_buildings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(10) NOT NULL, `level` int(10) NOT NULL, `building_name` varchar(10) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ; -- -- Dumping data for table `dk_user_buildings` -- INSERT INTO `dk_user_buildings` (`id`, `username`, `level`, `building_name`) VALUES (2, 'playerB', 1, 'cottage'), (1, 'hugoland', 1, 'cottage'); The actual php code (that isn't working) function manage() { // Manages built buildings. global $userrow; $boo = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["username"]."' LIMIT 1", "user_buildings"); $boo2 = mysql_fetch_array($boo); // trying to pull the users "charname" from the user database with $userrow["username"] $page = "The following are your available buildings:<br /><br />\n"; $page .= "<table width=\"80%\">\n"; $page .= "<td width=\"20%\"><b><a href=\"index.php?do=manage2:".$boo2["id"]."\">".$boo2["building_name"]."</a>$specialdot</b></td> <td width=\"50%\">Level:".$boo2["level"]."</b></td> <td width=\"50%\">Name".$boo2["building_name"]."</b></td></tr>\n"; $page .= "</table><br />\n"; $page .= "If you've changed your mind, you may also return back to <a href=\"index.php\">town</a>.\n"; $title = "Buy Items"; display($page, $title); } Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-925037 Share on other sites More sharing options...
fenway Posted October 5, 2009 Share Posted October 5, 2009 Echo the query. Quote Link to comment https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/#findComment-930739 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.