djfox Posted July 17, 2007 Share Posted July 17, 2007 Sorry to keep bothering but I`m still learning about php. <?php include("dbcon.php"); include("func.php"); require_once "auth.php"; require_once "includes/defines.php"; if (!isLoggedIn()) { Redirect("index.php"); } $log = $_SESSION['sess_name']; $res3 = mysql_query("Select id,echo_count FROM userdata WHERE id='$s''")or die( mysql_error() ); $sel = mysql_fetch_row($res3); mysql_free_result($res3); if ($_SESSION['echos'] >= $p) { $_SESSION['echos'] = $echos = $echos - $p; mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ") or die(mysql_error()); mysql_query("UPDATE coll_inven SET user='$log' WHERE id=$id"); mysql_query("INSERT INTO coll_inven (user,item,price) VALUES ( '$log', '$id', '$pr' )"); mysql_query("DELETE FROM coll_sell WHERE id=$id"); } header("Location: vendor_grovepark.php"); else { header("Location: vendor_grovepark.php?alert=noechos"); } ?> I know the code is incomplete. I`m stumped with something. I have in there to take currency (echos) from the echo_count of the logged in person buying the item. How do I add this number to the seller? I have in the query to call on the seller`s info, but how do I get $p added to the seller`s echos? I`m basically looking for $p added to $sel[1] a simple math thing to add $p to whatever number is already in $sel[1] Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 dude whats this $_SESSION['echos'] = $echos = $echos - $p;??? and explain more pls Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 dude whats this $_SESSION['echos'] = $echos = $echos - $p;??? and explain more pls That is subtracting the $p from the logged in person`s virtual currency (called echos). Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 $_SESSION['echos'] = $echos = $echos - $p; this is better any way do get correct result??? from that $echos = $echos - $p; $_SESSION['echos']=$echos ; try that Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 Oh yeah, the result comes out fine. Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 Just because I made a bit of changes to the original code and the system won`t let me edit the original post: <?php include("dbcon.php"); include("func.php"); require_once "auth.php"; require_once "includes/defines.php"; if (!isLoggedIn()) { Redirect("index.php"); } $log = $_SESSION['sess_name']; $res3 = mysql_query("Select id,echo_count FROM userdata WHERE id='$s''")or die( mysql_error() ); $sel = mysql_fetch_row($res3); mysql_free_result($res3); if ($_SESSION['echos'] >= $p) { $_SESSION['echos'] = $echos = $echos - $p; mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ") or die(mysql_error()); mysql_query("INSERT INTO coll_inven (user,item,price) VALUES ( '$log', '$it', '$pr' )"); mysql_query("DELETE FROM coll_sell WHERE id=$id"); } header("Location: vendor_grovepark.php"); else { header("Location: vendor_grovepark.php?alert=noechos"); } ?> But I still can`t figure out how to add $p tp $sel[1] Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 if you will want that outside the db then iguess $sel[1].=your value is that??? Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 $p is the value that will be added. It will be a different value depending on the value the page before it indicates: <a href="sell_coll.php?id=<? echo "$row[0]" ?>&p=<? echo "$row[3]" ?>&pr=<? echo "$row[4]" ?>&s=<? echo "$row[5]" ?>&it=<? echo "$item[0]" ?>">Buy</a> The codes I posted earlier are from the sell_coll.php file. Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 I know this is being posted several times but reading over my code again, I found a couple errors and got them sorted out, here is the final revised code: <?php include("dbcon.php"); include("func.php"); require_once "auth.php"; require_once "includes/defines.php"; if (!isLoggedIn()) { Redirect("index.php"); } $log = $_SESSION['sess_name']; $res3 = mysql_query("Select id,echo_count FROM userdata WHERE id='$s'")or die( mysql_error() ); $sel = mysql_fetch_row($res3); mysql_free_result($res3); if ($_SESSION['echos'] >= $p) { $_SESSION['echos'] = $echos = $echos - $p; mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ") or die(mysql_error()); mysql_query("INSERT INTO coll_inven (user,item,price) VALUES ( '$log', '$it', '$pr' )"); mysql_query("DELETE FROM coll_sell WHERE id=$id"); header("Location: vendor_grovepark.php"); } else { header("Location: vendor_grovepark.php?alert=noechos"); } ?> But still need to be able to add $p to $sel[1] I`m totally stumped. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 still i cant understand sorry but, $row[0]=$row[0]+$another; or explain what you really want its hard to answer poor explained question even if your q is easy i really find it hard Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 Ok, trying to explain it as best as I can. Person A puts Item A into the market to sell. Person A sets Item A`s sellprice to 75 echos. Person B comes along and decides they want to buy Item A. So they click the link that does the transaction. The transaction is that the 75 echos is taken from Person B`s echo_count and entered into Person A`s echo_count. Item A is taken from Person A`s inventory and put into Person B`s inventory. My code has all those parts working except putting the echos into Person A`s echo_count. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 try $echos = $echos - $p; $_SESSION['echos'] = $echos ; mysql_query("UPDATE userdata SET echo_count = '".$echos."' WHERE login = '".$log."' "); Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 That works fine for Person B but Person A (marked by $s ) is not getting their currency. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 then put another update query for that user just like what you did and reverse your logic if the first is to add then its now time subtact Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 That`s what I`m having trouble with. I`m not sure of how the code should be since some instances are different fro the code for Person B. I can easily modify this part of the code: mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ") But for this part: $_SESSION['echos'] = $echos = $echos - $p; How do I manipulate that to work for Person A (who is $s )? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 whats hard with that $_SESSION['echos'] = $echos = $echos - $p; mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ");//sample1 mysql_query("UPDATE userdata SET echo_count = (value here +$echos) WHERE login = '".$log."' ");//sample or maybe mysql_query("UPDATE userdata SET echo_count+$value WHERE login = '".$log."' ");//sample Quote Link to comment Share on other sites More sharing options...
djfox Posted July 17, 2007 Author Share Posted July 17, 2007 The current echo count code is for Person B (the buyer or $log): $_SESSION['echos'] = $echos = $echos - $p; mysql_query("UPDATE userdata SET echo_count = $echos WHERE login = '".$log."' ") The code would need to change to add the echo amount ($p) to the seller`s ($s) echo_count $_SESSION['echos'] = $echos = $echos + $p; mysql_query("UPDATE userdata SET echo_count = $echos WHERE id = '$s' ") But it`s that $_SESSION['echos'] = $echos = $echos part that needs to change. $_SESSION['echos'] = $echos = $echos takes the echos of the buyer and adds to what`s already there. I don`t know how to change it completely to add to $s echo_count. It can`t have $echos (I`m assuming) because then it would just copy what echos the buyer has. That would not be right because both persons would have different values in their echo_count. It can`t have the $_SESSION thing because that is for the buyer, not the seller. Only analogy I can think of is if you ever played Gaia Online and used their marketplace. It`s basic retail-consumer functions. Quote Link to comment 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.