Jump to content

Query database gone wrong


apw

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/175514-query-database-gone-wrong/
Share on other sites

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.

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.

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

  • 2 weeks later...

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.