Jump to content

Game Trading Application


flashbangpro

Recommended Posts

Hello

 

I am making a game trading web application for class.

 

Here are the requirements:

You must be able to register and log in, you must be able to list games you have to trade and games you want, you must be able to search users that want games you have and users that have games you want, you must be able to accept and make trades, on trade finalization screen you must be able to rate user 1-5, view the users shipping address, and leave a comment on the users page.

 

You do not have to be able to view other users pages, but on your home page you must be able to view your average rating.

 

I am the most advanced programmer in my group so this has been a little tough.

 

I have a login page and a registration page, I have a user home page, a add games page, a view feedback/ratings page, and a my games page where you can delete games.

 

What I'm stuck on is the page that allows you to search users by games they want and games you want, and the trade finalization page.

On the search page I would like to combine the functionality of searching for users with games you want and games they want with the ability to make a trade offer. The way we have it drawn up is using radio buttons to select either show people with games I want and show people wanting my games. When one is selected it will populate a list of usersnames in a drop down menu that fit whichever choice was made. We drew up four list boxes that populate lists when we select a user name, one box populates the games they have, one populates the games they want, one populates the games I have and one populates games I want. We want to be able to select game titles and move them to a list box of games I want and another to a list box of games willing to trade, lastly a submit offer button.

We are debating on if this is the best set up given the requirements needing to be met. I think there is more here than what we need, we have 1 week to do this and I am doing all the programming so I am looking for the easiest way to search users that want games I have/have games I want and display the results giving me the option to select games to trade and make an offer.

We are also arguing on if we have to use JavaScript to do this or if it can all be done within php.

 

The trade finalization page would have a drop down menu where you select the user name of completed trades and upon selection lists will be populated of games they gave, games I gave and the address to send the game. It will also have a form where we can rate the user and leave a comment.

 

This page I need help with cause again we disagree on having to use JavaScript or not.

 

We are using phpMyAdmin and the db tables we have are:

tblgame - list of games I have added

tblgamestatuscode - gives game a code that determines if it is wanted, to trade, or traded

tblmember - member registration

tblplatform - platform the game is on (Xbox, Xbox 360, Playstation2, Playstation3, PC, and Wii)

tbltransaction - date traded and a status change code

tbltransactiondetail - gameID and trans ID

tbltransactionparty - memberID, transID, rating, comments, status change accepted

 

We are also using adodb.

 

Please help if you can. I will gladly give more information if needed.   

 

Link to comment
Share on other sites

My advice (and I'm being brutally honest): don't go on and on about your project. Most people don't care about all the details of your project and your team chemistry. Maybe if this is an English class and or a place to demo to everyone what your project is. But sadly, it's not.

 

Just be explicit in what you want and keep it very simple. Do not digress. This is the place where you should just "get to the point!"

 

With that said, let's first try to tackle the searching problem. Everything else should be clear after that is solved.

 

1. How is data being entered in? Is the user entering the name of a game into a text input field?

2. What is the relationship between tblgame, tblmember, tblgamestatuscode, and tblplatform? Are they related to one another? If not, you may need some helper tables or some reorganization.

3. JavaScript is not terribly out of the question. You can use it for AJAX or DataTables. But it certainly can be done with just PHP.

 

Link to comment
Share on other sites

  • 3 weeks later...

Here is the coding I have so far on the potential trades page. First set of coding is a file that contains all my php functions and is included in all my php pages, second file is my php page that is not working correctly.

Functions Coding

<?php
session_start();
$memberID = (isset($_SESSION['memberID']) ? $_SESSION['memberID'] : '');
$fName = (isset($_SESSION['fName']) ? $_SESSION['fName'] : '');

function logout(){
    global $memberID;
    global $fName;

    $memberID = '';
    $fName = '';
    
    session_destroy();
    session_start();
}

function ensureLoggedIn(){
    global $memberID;
    if($memberID == ''){
        header("Location: logout.php"); 
    }
}

function loginCheck($email, $password){
    //Returns true if successful login, otherwise returns false.
    //Sets global variables about user if successful login.

    global $memberID;
    global $fName;

    //Clear all session vars; start new session.
    session_start();
    $memberID = '';
    $fName = '';
    $encryptedPassword = '';

    $encryptedPassword = crypt($password);
    
    $sql = "select ID, fName from tblmember where email = '$email' and (password = '$password' or password = '$encryptedPassword')";
    $rs = getRecordset($sql, false); //2nd arg false to cause false to be returned if rs empty.
    
    if($rs === false){
        return false;
    }

    $memberID = $rs->fields[0];
    $fName = $rs->fields[1];
    
    $_SESSION['memberID'] = $memberID;
    $_SESSION['fName'] = $fName;
    return true;
}

function registerNewMember($fN, $lN, $email, $pw, $street1, $street2, $city, $state, $country, $zip, $screenName){
    //Returns true/false based on success.
    
    //Encrypt the password.
    $pw = crypt($pw);

    $sql = <<<STRSQL
        INSERT INTO tblmember(fName, lName, email, password,
        street1, street2, city, state, country, zip, screenName)
        VALUES('$fN', '$lN', '$email', '$pw',
        '$street1', '$street2', '$city', '$state', '$country', '$zip', '$screenName')
STRSQL;

    return runActionQuery($sql);    
}

function updateRegistrationData($fN, $lN, $email, $pw, $street1, $street2, $city, $state, $country, $zip, $screenName){
    //Returns true/false based on success.

    global $memberID;

    //Encrypt the password.
    $pw = crypt($pw);

    $sql = <<<STRSQL
        UPDATE tblmember SET
        fName='$fN',
        lName='$lN',
        email='$email',
        password='$pw',
        street1='$street1',
        street2='$street2',
        city='$city',
        state='$state',
        country='$country',
        zip='$zip',
        screenName='$screenName'
        WHERE ID = $memberID        
STRSQL;

    return runActionQuery($sql);    
}

function getMyGamesList($htmlID, $visibleListItemsCount = 15, $displayDelimiter = '-'){
    //Returns a string containing an html select tag (listbox) of the games listing for the current user.
    //Pass in $htmlID so that tag is built with html id for css etc.
    global $memberID;

    //Recall, we must not show traded games in the games list.
    
    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle 'Game Title',
            p.platformName 'Platform',
            s.statusCode 'Status'            
        from
            tblgame g
            inner join tblPlatform p on(p.ID = g.platformID)
            inner join tblGameStatusCode s on(s.ID = g.gameStatusCode)
        where
            g.memberID = $memberID
            and
            s.ID <> 3
STRSQL;

    $rs = getRecordset($sql);    
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleListItemsCount, $displayDelimiter);
}

function addGame_InsertGameRecord($gameTitle, $platformID, $gameStatusCode){
    global $memberID;

    $platformID = getIDValIfNotNumeric($platformID);
    $gameStatusCode = getIDValIfNotNumeric($gameStatusCode);
    
    $sql = <<<STRSQL
        INSERT INTO tblgame(gameTitle, platformID, memberID, gameStatusCode)
        VALUES('$gameTitle', $platformID, $memberID, $gameStatusCode)
STRSQL;

    $boolSuccess = runActionQuery($sql);    
    if($boolSuccess){
        return("'$gameTitle' successfully added.");
    }else{
        return("Failed to add '$gameTitle'.");
    }
}

function addGame_GetPlatformDropDown($htmlID){
    $sql = <<<STRSQL
        select ID, platformName from tblPlatform order by platformName
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, 1);    
}

function addGame_GetGameStatusCodeDropDown($htmlID){
    $sql = <<<STRSQL
        select ID, statusCode from tblGameStatusCode where ID <> 3 order by statusCode
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, 1);    
}

function deleteGame($gameID){
    global $memberID;

    $gameID = getIDValIfNotNumeric($gameID);

    $sql = <<<STRSQL
        delete from tblGame where ID = $gameID and memberID = $memberID
STRSQL;

    return runActionQuery($sql);    
}

function myCompletedTrades_TransactionsDropDown($transID, $htmlID, $displayDelimiter = '-'){
    //Returns a string containing an html select tag (drop down) (ID | TradeDate | TradedWith) for the current user.
    //Pass in $htmlID so that tag is built with html id for css etc.
    global $memberID;

    $transID = getIDValIfNotNumeric($transID);

    $sql = <<<STRSQL
        select
            t.ID,
            DATE_FORMAT(t.dateFinalized,'%c/%e/%Y') "Trade Date",
            m.screenName "Traded With"
        from
            tblTransaction t
            inner join tblTransactionParty tp1 on(t.ID = tp1.transID)
            inner join tblTransactionParty tp2 on(t.ID = tp2.transID)
            inner join tblMember m on(m.ID = tp2.memberID)
        where
            tp1.memberID = $memberID
            and
            tp2.memberID <> $memberID
            and
            t.dateFinalized is not null
        order by
            t.dateFinalized
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, 1, $displayDelimiter, $transID);    
}

function myCompletedTrades_GamesIGaveListBox($transID, $htmlID, $visibleItemsCount = 8, $displayDelimiter = '-'){
    global $memberID;

    $transID = getIDValIfNotNumeric($transID);

    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle,
            p.platformName            
        from
            tblTransactionDetail td
            inner join tblGame g on(g.ID = td.gameID)
            inner join tblPlatform p on(p.ID = g.platformID)
        where
            td.transID = $transID
            and
            g.memberID = $memberID
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleItemsCount, $displayDelimiter);    
}

function myCompletedTrades_GamesIGotListBox($transID, $htmlID, $visibleItemsCount = 8, $displayDelimiter = '-'){
    global $memberID;

    $transID = getIDValIfNotNumeric($transID);

    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle,
            p.platformName            
        from
            tblTransactionDetail td
            inner join tblGame g on(g.ID = td.gameID)
            inner join tblPlatform p on(p.ID = g.platformID)
        where
            td.transID = $transID
            and
            g.memberID <> $memberID
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleItemsCount, $displayDelimiter);    
}

function myCompletedTrades_sendGamesToAddressText($transID){
    global $memberID;

    $transID = getIDValIfNotNumeric($transID);

    $sql = <<<STRSQL
        select
            concat(m.fName, " ", m.LName, "\n",
                    m.street1, "\n",
                    ifnull(m.street2, ""), "\n",
                    m.city, ", ", m.state, " ", m.zip, "\n",
                    m.country) "sendToAddress"
        from
            tblTransactionParty tp
            inner join tblMember m on(m.ID = tp.memberID)
        where
            tp.transID = $transID
            and
            tp.memberID <> $memberID
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return $rs->fields[0];
}

function myCompletedTrades_ratingOfMemberDropDown($transID){
    global $memberID;
    $transID = getIDValIfNotNumeric($transID);
    $rating = '';

    $sql = <<<STRSQL
        select
            tp.rating
        from
            tblTransactionParty tp
        where
            tp.transID = $transID
            and
            tp.memberID <> $memberID
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs !== false && $rs->EOF == false){
        $rating = $rs->fields[0];
    }
    
    switch($rating){
        case 'low':
            $selLow = 'selected';
            $selAvg = '';
            $selHigh = '';
            break;
        case 'average':
            $selLow = '';
            $selAvg = 'selected';
            $selHigh = '';
            break;
        case 'high':
            $selLow = '';
            $selAvg = '';
            $selHigh = 'selected';
            break;
        default:
            $selLow = '';
            $selAvg = '';
            $selHigh = '';
            break;        
    }
    
    $strDropDown = <<<STRDROP
    <select>
        <option value="low" selected="$selLow">low</option>
        <option value="average" selected="$selAvg">average</option>
        <option value="high" selected="$selHigh">high</option>
    </select>
STRDROP;

    return $strDropDown;
}

function myCompletedTrades_commentOnMemberTradedWith($transID){
    global $memberID;

    $transID = getIDValIfNotNumeric($transID);

    $sql = <<<STRSQL
        select
            tp.comment
        from
            tblTransactionParty tp
        where
            tp.transID = $transID
            and
            tp.memberID <> $memberID
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    if(is_null($rs->fields[0]) == false){
        return $rs->fields[0];
    }else{
        return '';
    }
}

function myCompletedTrades_saveRatingAndComment($transID, $rating, $comment){
    global $memberID;
    $transID = getIDValIfNotNumeric($transID);

    $sql = <<<STRSQL
        update
            tblTransactionParty
        set
            rating = '$rating',
            comment = '$comment'
        where
            transID = $transID
            and
            memberID <> $memberID
STRSQL;

    return runActionQuery($sql);
}

function viewMyFeedbackRatingsComments($htmlID, $visibleItemsCount = 20, $displayDelimiter = '-'){
    global $memberID;

    $sql = <<<STRSQL
        select
            DATE_FORMAT(t.dateFinalized,'%c/%e/%Y') "Transaction Date",
            tp.rating "Rating",
            tp.comment "Comment"
        from
            tblTransaction t
            inner join tblTransactionParty tp on(tp.transID = t.ID)
        where
            t.dateFinalized is not null
            and
            tp.memberID = $memberID
        order by
            t.dateFinalized
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleItemsCount, $displayDelimiter);    
}


function potentialTrades_ScreenNamesDropDown_ShowAll($htmlID, $selectedMemberID = -1){
    global $memberID;

    $sql = <<<STRSQL
        select
            b.screenName
        from
            tblMember b
        where
            b.ID <> $memberID
        order by
            b.screenName
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, 1, '', $selectedMemberID);    
}

function potentialTrades_ScreenNamesDropDown_ShowPeopleWithGamesIWant($htmlID, $selectedMemberID = -1){
    global $memberID;

    $sql = <<<STRSQL
        select
            m.screenName
        from
            tblGame avail
            inner join tblGame want on(want.platformID = avail.platformID
                                        and
                                        upper(want.gameTitle) = upper(avail.gameTitle))
            inner join tblMember m on(m.ID = avail.memberID)
        where
            avail.gameStatusCode = 1
            and
            want.gameStatusCode = 2
            and            
            avail.memberID <> $memberID
            and
            want.memberID = $memberID
        order by
            m.screenName
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, 1, '', $selectedMemberID);    
}

function potentialTrades_ScreenNamesDropDown_ShowPeopleWantingMyGames($htmlID, $selectedMemberID = -1){
    global $memberID;

    $sql = <<<STRSQL
        select
            m.screenName
        from
            tblGame avail
            inner join tblGame want on(want.platformID = avail.platformID
                                        and
                                        upper(want.gameTitle) = upper(avail.gameTitle))
            inner join tblMember m on(m.ID = want.memberID)
        where
            avail.gameStatusCode = 1
            and
            want.gameStatusCode = 2
            and            
            avail.memberID = $memberID
            and
            want.memberID <> $memberID
        order by
            m.screenName
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, 1, '', $selectedMemberID);    
}

function potentialTrades_ScreenNamesDropDown_ShowPeopleIAmNegotiatingWith($htmlID, $selectedMemberID = -1){
    global $memberID;

    $sql = <<<STRSQL
        select
            m.screenName
        from
            tblTransaction t
            inner join tblTransactionParty tp1 on(tp1.transID = t.ID)
            inner join tblTransactionParty tp2 on(tp2.transID = t.ID)
            inner join tblMember m on(m.ID = tp1.memberID)
        where
            t.dateFinalized is null
            and
            tp1.memberID <> $memberID
            and
            tp2.memberID = $memberID
        order by
            m.screenName
STRSQL;

    $rs = getRecordset($sql);
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, 1, '', $selectedMemberID);    
}

function potentialTrades_GamesTheyWantListBox($selectedMemberID, $htmlID, $visibleListItemsCount = 10, $displayDelimiter = '-'){    
    
    $selectedMemberID = getIDValIfNotNumeric($selectedMemberID);

    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle 'Game Title',
            p.platformName 'Platform'
        from
            tblgame g
            inner join tblPlatform p on(p.ID = g.platformID)
        where
            g.memberID = $selectedMemberID
            and
            g.gameStatusCode = 2
STRSQL;

    $rs = getRecordset($sql);    
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleListItemsCount, $displayDelimiter);
}

function potentialTrades_GamesIWantListBox($htmlID, $visibleListItemsCount = 10, $displayDelimiter = '-'){    
    global $memberID;
    
    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle 'Game Title',
            p.platformName 'Platform'
        from
            tblgame g
            inner join tblPlatform p on(p.ID = g.platformID)
        where
            g.memberID = $memberID
            and
            g.gameStatusCode = 2
STRSQL;

    $rs = getRecordset($sql);    
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleListItemsCount, $displayDelimiter);
}

function potentialTrades_GamesIHaveListBox($htmlID, $visibleListItemsCount = 10, $displayDelimiter = '-'){    
    global $memberID;
    
    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle 'Game Title',
            p.platformName 'Platform'
        from
            tblgame g
            inner join tblPlatform p on(p.ID = g.platformID)
        where
            g.memberID = $memberID
            and
            g.gameStatusCode = 1
STRSQL;

    $rs = getRecordset($sql);    
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleListItemsCount, $displayDelimiter);
}

function potentialTrades_GamesTheyHaveListBox($selectedMemberID, $htmlID, $visibleListItemsCount = 10, $displayDelimiter = '-'){        
    $selectedMemberID = getIDValIfNotNumeric($selectedMemberID);

    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle 'Game Title',
            p.platformName 'Platform'
        from
            tblgame g
            inner join tblPlatform p on(p.ID = g.platformID)
        where
            g.memberID = $selectedMemberID
            and
            g.gameStatusCode = 1
STRSQL;

    $rs = getRecordset($sql);    
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleListItemsCount, $displayDelimiter);
}

function potentialTrades_GamesIWillGiveListBox($selectedMemberID, $htmlID, $visibleListItemsCount = 10, $displayDelimiter = '-'){
    global $memberID;
    $selectedMemberID = getIDValIfNotNumeric($selectedMemberID);
    
    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle 'Game Title',
            p.platformName 'Platform'
        from
            tblTransactionParty tp1
            inner join tblTransactionParty tp2 on(tp2.transID = tp1.transID and tp2.memberID <> tp1.memberID)
            innter join tblTransactionDetail td on(td.transID = tp1.transID)
            inner join tblgame g(on g.ID = td.gameID)
            inner join tblPlatform p on(p.ID = g.platformID)
            inner join tblTransaction t on(t.ID = tp1.transID)
        where
            tp1.memberID = $memberID
            and
            tp2.memberID = $selectedMemberID
            and
            g.gameStatusCode = 1
            and
            t.dateFinalized is null
STRSQL;

    $rs = getRecordset($sql);    
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleListItemsCount, $displayDelimiter);
}

function potentialTrades_GamesIWillGetListBox($selectedMemberID, $htmlID, $visibleListItemsCount = 10, $displayDelimiter = '-'){
    global $memberID;
    $selectedMemberID = getIDValIfNotNumeric($selectedMemberID);
    
    $sql = <<<STRSQL
        select
            g.ID,
            g.gameTitle 'Game Title',
            p.platformName 'Platform'
        from
            tblTransactionParty tp1
            inner join tblTransactionParty tp2 on(tp2.transID = tp1.transID and tp2.memberID <> tp1.memberID)
            innter join tblTransactionDetail td on(td.transID = tp1.transID)
            inner join tblgame g(on g.ID = td.gameID)
            inner join tblPlatform p on(p.ID = g.platformID)
            inner join tblTransaction t on(t.ID = tp1.transID)
        where
            tp1.memberID = $selectedMemberID
            and
            tp2.memberID = $memberID
            and
            g.gameStatusCode = 1
            and
            t.dateFinalized is null
STRSQL;

    $rs = getRecordset($sql);    
    
    if($rs === false){
        return '';
    }
    
    return htmlSelectTagFromRecordset($rs, $htmlID, $visibleListItemsCount, $displayDelimiter);
}

function unfinalizedTransIDFromMemberID($selectedMemberID){
    global $memberID;
    
    $selectedMemberID = getIDValIfNotNumeric($selectedMemberID);
    
    if($selectedMemberID == -1){
        return -1;
    }
    
    $sql = <<<STRSQL
        select
            t.ID
        from
            tblTransactionParty tp1
            inner join tblTransactionParty tp2 on(tp2.transID = tp1.transID and tp2.memberID <> tp1.memberID)
            inner join tblTransaction t on(t.ID = tp1.transID)
        where
            tp1.memberID = $selectedMemberID
            and
            tp2.memberID = $memberID
            and
            t.dateFinalized is null
STRSQL;

    $rs = getRecordset($sql);    
    
    if($rs === false || $rs->EOF == true){
        return -1;
    }
    
    //We have a record.
    return $rs->fields[0];
} 
function potentialTrades_MakeOffer($selectedMemberID,
								$pipeDelimGameIDsToBeTraded){
global $memberID;

$transID = -1;
$sql = '';
$boolSuccess = true;
$boolIsNewTrans = false;


$selectedMemberID = getIDValIfNotNumeric($selectedMemberID);

if($selectedMemberID == -1){
	return 'Member not selected for making an offer.';
}

//Trim away any leading or trailing pipe character(s).
$pipeDelimGameIDsToBeTraded = trim($pipeDelimGameIDsToBeTraded,'|');
if($pipeDelimGameIDsToBeTraded == ''){
	return 'No games have been specified to be made a part of the trade.';
}

$transID = unfinalizedTransIDFromMemberID($selectedMemberID);

if($transID == -1){
	$boolIsNewTrans = true;
}else{
	$boolIsNewTrans = false;
}	

beginTransaction();

//-------
//Work with tblTransaction...
switch($boolIsNewTrans){
	case true:
		//No unfinalized transaction yet exists between logged in member and specified member.
		//Create new transaction record and get the ID of the newly created record.
		$sql = <<<STRSQL
			insert into tblTransaction(dateFinalized, changeCount) VALUES(null, 1)
STRSQL;
		$boolSuccess = $boolSuccess && runActionQuery($sql);
		//Get ID of newly inserted record.
		$transID = lastInsertedID();
		break;

	case false:
		//We have record of an unfinalized transaction in progress. Update the change count.
		$sql = <<<STRSQL
			update tblTransaction set changeCount = changeCount + 1 where ID = $transID
STRSQL;
		$boolSuccess = $boolSuccess && runActionQuery($sql);		
		break;
}
//-------


//-------
//Work with tblTransactionParty...
switch($boolIsNewTrans){
	case true:
		//Since new, add two records to tblTransactionParty; changeCountAccepted = 1 for logged in member, 0 for other member...

		//----For logged-in member:
		$sql = <<<STRSQL
			insert tblTransactionParty(transID, memberID, changeCountAccepted) values($transID, $memberID, 1)
STRSQL;
		$boolSuccess = $boolSuccess && runActionQuery($sql);		
		//----

		//----For selected member:
		$sql = <<<STRSQL
			insert tblTransactionParty(transID, memberID, changeCountAccepted) values($transID, $selectedMemberID, 0)
STRSQL;
		$boolSuccess = $boolSuccess && runActionQuery($sql);		
		//----

		break;

	case false:
		//Since existing, update tblTransactionParty just for the logged in member, setting changeCountAccepted to changeCount of trans.
		//----
		$sql = <<<STRSQL
			update tblTransactionParty tp
			inner join tblTransaction t(on t.ID = tp.transID)
			set tp.changeCountAccepted = t.changeCount
			where
			t.ID = $transID
			and
			tp.memberID = $memberID				
STRSQL;
		$boolSuccess = $boolSuccess && runActionQuery($sql);		
		//----
		break;
}
//-------


//-------
//Work with tblTransactionDetail...
switch($boolIsNewTrans){
	case true:
		//do nothing at this time; only need to do inserts which is done below.
		break;

	case false:
		//if existing, delete all records in tblTransactionDetail for current trans.
		//----
		$sql = <<<STRSQL
			delete from tblTransactionDetail where transID = $transID
STRSQL;
		$boolSuccess = $boolSuccess && runActionQuery($sql);		
		//----
		break;
}

//Now add records to tblTransactionDetail using var $pipeDelimGameIDsToBeTraded
$arrGameID = explode('|', $pipeDelimGameIDsToBeTraded);
foreach($arrGameID as $gameID){
		$sql = <<<STRSQL
			insert into tblTransactionDetail(transID, gameID) values($transID, $gameID)
STRSQL;
		$boolSuccess = $boolSuccess && runActionQuery($sql);		
}		
//-------

commitTransaction();

if($boolSuccess == true){
	return 'Offer successfully made.';
}else{
	return 'There was an error in the database work required for making the offer.';
}
}

function potentialTrades_RejectAndEndNegotiations($selectedMemberID){
global $memberID;

$transID = -1;
$sql = '';
$boolSuccess = true;


$selectedMemberID = getIDValIfNotNumeric($selectedMemberID);	
if($selectedMemberID == -1){
	return 'Member not selected.';
}

$transID = unfinalizedTransIDFromMemberID($selectedMemberID);
if($transID == -1){
	return 'There is no transaction being negotiated with the selected member.';
}

beginTransaction();	

//-------
//Work with tblTransactionDetail...
$sql = <<<STRSQL
	delete from tblTransactionDetail where transID = $transID
STRSQL;
$boolSuccess = $boolSuccess && runActionQuery($sql);
//-------


//-------
//Work with tblTransactionParty...
$sql = <<<STRSQL
	delete from tblTransactionParty where transID = $transID
STRSQL;
$boolSuccess = $boolSuccess && runActionQuery($sql);
//-------


//-------
//Work with tblTransaction...
$sql = <<<STRSQL
	delete from tblTransaction where ID = $transID
STRSQL;
$boolSuccess = $boolSuccess && runActionQuery($sql);
//-------

commitTransaction();

if($boolSuccess == true){
	return 'Negotiations successfully ended with the selected member.';
}else{
	return 'There was an error in the database work required for ending the negotiations.';
}
}

function potentialTrades_AcceptOffer($selectedMemberID){	
global $memberID;

$transID = -1;
$sql = '';
$boolSuccess = true;
$rowCount = 0;


$selectedMemberID = getIDValIfNotNumeric($selectedMemberID);	
if($selectedMemberID == -1){
	return 'Member not selected for accepting an offer.';
}

$transID = unfinalizedTransIDFromMemberID($selectedMemberID);
if($transID == -1){
	return 'There is no transaction being negotiated with the selected member.';
}	


//-------
//Check that changeCountAccepted of the other party is equal to changeCount of trans (which tells us
//   that the other party was the last to make an offer). If it's not, notify cannot accept and get out.
$sql = <<<STRSQL
	select count(tp.ID) from
	tblTransactionParty tp
	inner join tblTransaction t on(t.ID = tp.transID)
	where
	tp.transID = $transID
	and
	tp.memberID = $selectedMemberID
	and
	tp.changeCountAccepted = t.changeCount
STRSQL;
$rowCount = rowCountFromSelectCountSQL($sql);
if($rowCount == 0){
	//This means that the other party was not the last to make an offer; logged in user therefore
	//has no standing offer to accept.
	return 'The selected member was not the last one to make an offer; there is no standing offer for you to accept from this member; at this time, you can only make a revised offer.';
}
//-------


//-------
//Get the count of games in the detail of this trans that are no longer marked as being available for trade
//   because they may have since been traded in a finalized transaction with a different member.
$sql = <<<STRSQL
	delete from td
	using
	tblTransactionDetail td
	inner join tblGame g on(g.ID = td.gameID)
	where
	td.transID = $transID
	and
	g.gameStatusCode <> 1
STRSQL;

$rowCount = -1;
$boolSuccess = runActionQuery($sql, $rowCount);	
if($boolSuccess === false){
	return 'There was an error verifying that all games associated with the transaction are still available; cannot accept transaction at this time.';
}

if($rowCount > 0){
	//There were games in the transaction which were no longer available and were deleted from the detail.
	//Increment trans changeCount to reflect this change so that the current user will be forced to make an offer.
	$sql = <<<STRSQL
		update tblTransaction set changeCount = ChangeCount + 1 where ID = $transID
STRSQL;
	$boolSuccess = runActionQuery($sql);	
	return 'There were games in this transaction which are no longer available; please refresh your view of this transaction and make a new offer or end negotiations.';
}
//-------


//-------
//We could also check the pipe delim list of gameIDs that the logged in user is looking at and ensure
//the exactly match all the game ID in the trans detail. If differs, would notify and get out.
//But also, the interface should disable the Accept offer button if the user has modified the games in the trade.
//-------


//Prior to this point we have done validation to ensure the transaction can be accepted.
beginTransaction();
$boolSuccess = true;

//-------
//Work with tblTransactionParty...	
//Update tblTransactionParty for the logged in member, setting changeCountAccepted to changeCount of trans.
$sql = <<<STRSQL
	update tblTransactionParty tp
	inner join tblTransaction t(on t.ID = tp.transID)
	set tp.changeCountAccepted = t.changeCount
	where
	t.ID = $transID
	and
	tp.memberID = $memberID				
STRSQL;
$boolSuccess = $boolSuccess && runActionQuery($sql);		
//-------


//-------
//Work with tblGame...
//Mark all games involved in the transaction as traded.
$sql = <<<STRSQL
	update
	tblGame g
	inner join tblTransactionDetail td on(g.ID = td.gameID)
	set
	g.gameStatusCode = 3
	where
	td.transID = $transID
STRSQL;
$boolSuccess = $boolSuccess && runActionQuery($sql);		
//-------


//-------
//Work with tblTransaction...
//Value column dateFinalized with the current date.
$sql = <<<STRSQL
	update tblTransaction set dateFinalized = getdate() where ID = $transID
STRSQL;
$boolSuccess = $boolSuccess && runActionQuery($sql);		
//-------


commitTransaction();

if($boolSuccess == true){
	return 'Offer successfully accepted. After you receive your games from the other party, please leave a rating and comments on your trade experience with them.';
}else{
	return 'There was an error in the database work required for accepting the offer.';
}	
}

My Potential Trades Page:

<!DOCTYPE HTML>
<?php
     require_once('..\phpLib\dbConn.php');
     require_once('..\phpLib\gamesTraderSQL.php');
   
?>
<html>
<title>New To Me Games</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../_css/main.css" rel="stylesheet" type="text/css"><!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript">

{

document.getElementById('divOutput').innerHTML = window.location.search;

}

// Technique 1

function placeInHidden(delim, selStr, hidStr)

{

var selObj = document.getElementById(selStr);

var hideObj = document.getElementById(hidStr);

hideObj.value = '';

for (var i=0; i<selObj.options.length; i++) {

	hideObj.value = hideObj.value ==

		'' ? selObj.options[i].value : hideObj.value + delim + selObj.options[i].value;

}

}

// Technique 2

function selectAllOptions(selStr)

{

var selObj = document.getElementById(selStr);

for (var i=0; i<selObj.options.length; i++) {

	selObj.options[i].selected = true;

}

}

//-->

</script>
</head>

<body>

<div class="container">
  <header>
    <a href="#"><img src="../_images/logo.png" alt="Insert Logo Here" name="Insert_logo" width="960" height="150" id="Insert_logo" style="background: #C6D580; display:block;" /></a>
  </header>
  <div class="sidebar1">
    <nav>
      <ul>
        <li><a href="home.php" title="">HOME</a></li>
      </ul>
    </nav>
  <!-- end .sidebar1 --></div>
  <article class="content">
    <h1>Potential Trades</h1>
    <section>
<h2>Search For Games To Trade    </h2>
<div>
</div>
</p>
    <form name="form1" method="get" action="">
      <p>
        <label>
<input type="submit" name="Update" value="Update">
          Users With Games I Want </label>
        <br>
        <label>
<input type="submit" name="Update" value="Update">
          Users That Want My Games</label>
        <br>
      </p>
      <p>
      <select name="Screen Name" size="1"></select>
      </p>
    </form>
    <div>
    <form name="form2" method="post" action="">
      <label for="theyWant">Games They Want</label>
      <textarea name="theyWant" id="theyWant" cols="45" rows="5"></textarea>
      <label for="myGames">Games I Have</label>
      <textarea name="myGames" id="myGames" cols="45" rows="5"></textarea>
      <label for="wantedGames"><br>
        Games I Want</label>
      <textarea name="wantedGames" id="wantedGames" cols="45" rows="5"></textarea>
      <label for="thierGmaes">Games They Have</label>
      <textarea name="thierGmaes" id="thierGmaes" cols="45" rows="5"></textarea>
      <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>
    </form>
    </div>
    <p>
    <table width="598" border="0">

<tr>

	<td>

		Games I Will Give<br />

		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="placeInHidden('.', 'sel3', 'hide2');">

		<select id="sel3" multiple="multiple" size="5">

		<option value="optDVal1">optDText1</option>

		<option value="optDVal2">optDText2</option>

		<option value="optDVal3">optDText3</option>

		</select>

		<input type="hidden" name="hide2Name" id="hide2" />

		<br />

		<input type="submit" value="Submit" />

		</form>

	</td>

	<td align="center" valign="middle">

		<form>

		<input type="button" value="-->"

		 onclick="moveOptions(document.getElementById('sel3'), document.getElementById('sel4'));" /><br />

		<input type="button" value="<--"

		 onclick="moveOptions(document.getElementById('sel4'), document.getElementById('sel3'));" />

		</form>

	</td>

	<td>

		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="selectAllOptions('sel4');">

		Games I Will Get<br />

		<select name="selPHP[]" id="sel4" multiple="multiple" size="5">

		<option value="optCVal1">optCText1</option>

		<option value="optCVal2">optCText2</option>

		<option value="optCVal3">optCText3</option>

		</select>

		<br />

		<input type="submit" value="Submit" />

		</form>

	</td>

</tr>

</table>



    </p>
    </section>
<!-- end .content --></article>
  <footer>
    <p> </p>
  </footer>
  <!-- end .container --></div>
</body>
</html>

Link to comment
Share on other sites

My advice (and I'm being brutally honest): don't go on and on about your project. Most people don't care about all the details of your project and your team chemistry. Maybe if this is an English class and or a place to demo to everyone what your project is. But sadly, it's not.

 

Just be explicit in what you want and keep it very simple. Do not digress. This is the place where you should just "get to the point!"

 

With that said, let's first try to tackle the searching problem. Everything else should be clear after that is solved.

 

1. How is data being entered in? Is the user entering the name of a game into a text input field?

2. What is the relationship between tblgame, tblmember, tblgamestatuscode, and tblplatform? Are they related to one another? If not, you may need some helper tables or some reorganization.

3. JavaScript is not terribly out of the question. You can use it for AJAX or DataTables. But it certainly can be done with just PHP.

 

Kay - That's the best non-bashing post I've seen in a good while!

 

OP - what is not working in the 2nd code that you posted? Can you be more specific with the errors your receiving? The more you limit down to what is causing your issue the better you can be helped.

Link to comment
Share on other sites

The form has no action set and won't do anything...

 

    <form name="form2" method="post" action="">
      <label for="theyWant">Games They Want</label>
      <textarea name="theyWant" id="theyWant" cols="45" rows="5"></textarea>
      <label for="myGames">Games I Have</label>
      <textarea name="myGames" id="myGames" cols="45" rows="5"></textarea>
      <label for="wantedGames"><br>
        Games I Want</label>
      <textarea name="wantedGames" id="wantedGames" cols="45" rows="5"></textarea>
      <label for="thierGmaes">Games They Have</label>
      <textarea name="thierGmaes" id="thierGmaes" cols="45" rows="5"></textarea>
      <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>
    </form>

Link to comment
Share on other sites

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.