berry05 Posted December 18, 2008 Share Posted December 18, 2008 how do i sell items in php? like text based game items..when a user has a item it goes to users_items table but i dont know how to make it so it can be sellable and add gold to the table users when a item is sold.. so far all i have is this which shows all the items the user has...i looked at the tutorial in the admins signature but it didnt help me when it comes to something like this though... <?php session_start(); if(isset($_SESSION['otherusername'])){ $db=mysql_connect('localhost', 'root', ''); $res=mysql_select_db('textgame',$db) or die(mysql_error()); $otherusername = $_SESSION['otherusername']; //"SELECT item FROM users_items WHERE username='".$Username."'"; $res=mysql_query($otherusername)or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo $row['item'] . "<BR />"; } }else{ echo "Sorry your not a member please join us!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/ Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 i looked at the tutorial in the admins signature What tutorial are you referring to? Could you provide a link so we could get the info that you're basing your game off of? Are you keeping this info in a database? Is there an item table with a value for each item? What are the major issues here. All you said is that you don't know how to do something. This looks more like a design issue... You need to have a table for items with a value for each, and another table like "user_to_items" to keep track of what items each user has. Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719150 Share on other sites More sharing options...
phpian Posted December 18, 2008 Share Posted December 18, 2008 i would love to help you but i don't have a clue about what you're asking! Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719152 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 thorpes tutorial at Hudzilla...he told me to check it out.. yes i'm keeping this information in a database also.. there's a item table with just a field called name and anotehr table called users_items with a field called username and a field called item Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719162 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 You need to figure out a proper design for the application, database, and logic so that you don't run into these kinds of problems. Currently you need to add a field called "gold_value" in the item table for each item so when users perform a transaction you know how much to add/subtract from each gold_count of each user. Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719172 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 ok i did that....is there like a certain tutorial that can teach me something like that though? Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719176 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 someone told me to add a sell link to each item but how do i do that if its echoing out of the database? Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719261 Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 <?php session_start(); if(isset($_SESSION['otherusername'])){ $db=mysql_connect('localhost', 'root', ''); $res=mysql_select_db('textgame',$db) or die(mysql_error()); $otherusername = $_SESSION['otherusername']; //"SELECT item FROM users_items WHERE username='".$Username."'"; $res=mysql_query($otherusername)or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo '<a href="sell.php?item=" . $row['item'] . '">' . $row['item'] . "<BR />"; } }else{ echo "Sorry your not a member please join us!"; } ?> You will have to create a "sell.php" to see the item, probably have a confirmation for them, ask them if they really want to sell it. Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719264 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 i get his error Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\wamp\www\test\login\sell.php on line 18 and yes i heard about query strings but dont know much about them but i can learn from tuts Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719285 Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 echo '<a href="sell.php?item="' . $row['item'] . '">' . $row['item'] . "<BR />"; Forgot a ' before the . $row Basically you would access that variable in sell.php by $_GET['item'] Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719287 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 i can have this all in one PHP file right? and how do i work $_GET['item'] ? Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719291 Share on other sites More sharing options...
berry05 Posted December 19, 2008 Author Share Posted December 19, 2008 when i hover over the items link it has the URL and at the end it has sell.php?item= and that's it..isn't it suppose to show the item name from the field? echo '<a href="sell.php?item="' . $row['item'] . '">' . $row['item'] . "<BR />"; i think it has something to do with that code right there.. Quote Link to comment https://forums.phpfreaks.com/topic/137590-how-to-sell-items-in-php/#findComment-719362 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.