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
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.