Jump to content

Emiiya

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Emiiya's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. THIS. This is what I was looking for. I didn't know you could have a variable as the row, where it's '$column'='$item'. Thank you, I appreciate all the help!
  2. In the database table, basically, there's rows such as username (your/the user's username), and then rows called Name1, Item1, Name2, Item2, Name3, Item3, etc. So a user's username is in the username column, and then they have something in each row. This is in inventory script, so in Name1 there might be a name like "Black Shoes" and in Item1 is the code for the item, such as blackshoes.png, which is for the image of the item. All of this works. With this, I'm also seeing if I can build a human avatar system, with layering images of clothes/etc on the base image of a person. I've gotten this script to work completely. All I need is for the user to be able to insert things from the inventory to the table (above) with the items they are "wearing." I don't want to have columns in the table like "Shirt", "Pants", etc because that would mean only one shirt can be worn at a time, and only pair of pants, etc. So I've made 9 slots for items so that 9 items can be worn at one time. In the human avatar script, I've already got layering and stuff to work, and the z-index of each image is in another row called index1, index2, etc. But that's besides the point. Basically, it would look like this: Username---Name1----Item1----Index1---Name2---Item2---Index2---etc Em-------------Blah-----blah.png----1-------etc The drop down list has 9 different slots to choose from, and then clicking "Wear" would delete that item from the inventory table and update the Character table where username=$whatever the username is, which I have done now in that jumble of code in my first post (thanks to you fixing my error before). You asked why I had all the if/else statements. This is because I have no idea how to compare what you selected in the drop-down list to the row names. What I would prefer having, instead of the handful of if/elses, is inserting the item into the row corresponding to $wdnumber (the number you chose). So, for instance, if you chose 5, the row where username=$username would be updated and insert the code of the image in the row Item5 and the name of it in Name5. I just have NO idea how to do this, and to get around it, I used a million if/else statements. In short, is there a much easier way to do this?
  3. Thank you so much for that! I'm not really an "advanced" programmer at all. I do it in my spare time and I've been teaching myself because I like getting things to work. The problem is, I'm doing something a little different for each of the numbers, that's why I have all the if statements. Maybe you can answer another question I had before this, which would be really helpful - the reason I have all these if statements is because depending on the number chosen from the drop-down, the "item" would be inserted into a certain corresponding row in the table ("row1"; "row2", etc. as examples). But - I had no idea how to do that...this is generally what each if statement looks like: elseif ($wdnumber = "2") { if ($name2 != "none") { echo "<font color=\"red\">There is already something in that row.</font>"; } else { mysql_query("DELETE FROM inventory WHERE id='$idofitem2'") or die(mysql_error()); mysql_query("UPDATE characters SET name2='$nameofitem2', item2='$codeofitem2' WHERE owner='$username'") or die(mysql_error()); } }
  4. I'm not going to explain the whole back story, so you might be totally clueless when it comes to what the heck I'm trying to accomplish here. It's a long story. BUT, I have this simple(ish) HTML form with a "discard" button (that deletes the entry from the table, yada yada, that stuff works fine) and a "wear" button, which should do some stuff with the database when you click it, ie. update some rows and delete stuff, etc, depending on which number you choose from the drop-down list I have coded. What exactly it does doesn't matter, I've got that all coded. So, I have an if statement for each of the possible 9 outcomes depending on which number you select; however, only #1 is working and I have no idea why. There are no MySQL or PHP errors, just some stubborn code. Whatever number you choose from the drop-down list, it will ALWAYS echo "You chose 1." However, I'd like it to say "You chose __(number)." Of course, the code in the end isn't going to echo that at all. The MySQL stuff that happens when you click "Wear" is gonna go in each of the places where it says "echo "You chose 2";". I noticed that my code there wasn't working, so I took it out and substituted it with this simple output to see why the form wasn't working. I can't seem to figure it out. Any help? (some header stuff is here, before the code) <? $sql=mysql_query("SELECT * FROM inventory WHERE username='$username'"); if(mysql_num_rows($sql)==0){ echo "<center><font class=header>Your inventory is empty.</font></center>"; } if(mysql_num_rows($sql) > 0){ echo "<table border=\"0\" cellspacing=\"10\">"; echo "<tr>"; for($i=0;$i<=mysql_num_rows($sql);$i=$i+1){ while($row = mysql_fetch_array($sql)){ $itemcode = $row['itemcode']; $category = $row['category']; $itemname = $row['itemname']; $idofitem = $row['id']; $i++; if($i%6==0){ // use the operator to find the remainder of $i / 6 (%) // if the remainder is 0; it is a multiple of 6, so make a new row. echo "<td align=\"center\"><img src=\"http://*******.com/images/items/$category/$itemcode.png\" /><br />$itemname<br />"; ?> <form action="<? echo $PHP_SELF; ?>" method="post" name="discarditem"> <input type="hidden" name="idofitem" value="<? echo $idofitem; ?>" /> <input type="submit" name="discarditem" value="Discard" /></form> <? if ($category == "clothes") { ?> <form action="<? echo $PHP_SELF; ?>" method="post" name="wearitem"> <input type="hidden" name="idofitem" value="<? echo $idofitem; ?>" /> <input type="hidden" name="codeofitem" value="<? echo $itemcode; ?>" /> <input type="hidden" name="nameofitem" value="<? echo $itemname; ?>" /> <select name="wdno"><option value="99">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option> <option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option> </select> <input type="submit" name="wearitem" value="Wear" /></form> <? } ?> <? echo "</td></tr><tr>"; } else { echo "<td align=\"center\"><img src=\"http://*******.com/images/items/$category/$itemcode.png\" /><br />$itemname<br />"; ?> <form action="<? echo $PHP_SELF; ?>" method="post" name="discarditem"> <input type="hidden" name="idofitem" value="<? echo $idofitem; ?>" /> <input type="submit" name="discarditem" value="Discard" /></form> <? if ($category == "clothes") { ?> <form action="<? echo $PHP_SELF; ?>" method="post" name="wearitem"> <input type="hidden" name="idofitem" value="<? echo $idofitem; ?>" /> <input type="hidden" name="codeofitem" value="<? echo $itemcode; ?>" /> <input type="hidden" name="nameofitem" value="<? echo $itemname; ?>" /> <select name="wdno"><option value="99">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option> <option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option> </select> <input type="submit" name="wearitem" value="Wear" /></form> <? } ?> <? echo "<td>"; } } } echo "</tr></table>"; } $yep = mysql_query("SELECT * FROM characters WHERE owner='$username'") or die(mysql_error()); while($row = mysql_fetch_array( $yep )) { $name1 = $row['name1']; $name2 = $row['name2']; $name3 = $row['name3']; $name4 = $row['name4']; $name5 = $row['name5']; $name6 = $row['name6']; $name7 = $row['name7']; $name8 = $row['name8']; $name9 = $row['name9']; } if (isset($_POST['discarditem'])) { $idofitem2 = $_POST['idofitem']; mysql_query("DELETE FROM inventory WHERE id='$idofitem2'") or die(mysql_error()); echo "<font color=\"red\">This item has been permanently discarded.</font>"; } if (isset($_POST['wearitem'])) { $idofitem2 = $_POST['idofitem']; $nameofitem2 = $_POST['nameofitem']; $codeofitem2 = $_POST['codeofitem']; $wdnumber = $_POST['wdno']; if ($wdnumber = "1") { echo "You chose 1"; } elseif ($wdnumber = "2") { echo "You chose 2"; } elseif ($wdnumber = "3") { echo "You chose 3"; } elseif ($wdnumber = "4") { echo "You chose 4"; } elseif ($wdnumber = "5") { echo "You chose 5"; } elseif ($wdnumber = "6") { echo "You chose 6"; } elseif ($wdnumber = "7") { echo "You chose 7"; } elseif ($wdnumber = "8") { echo "You chose 8"; } elseif ($wdnumber = "9") { echo "You chose 9"; } } ?>
  5. The first two Discard buttons are the same button - they are there twice because one of them is for all items in the first 5 columns of each row (there are 6 items per row in this table) and the second one is for the item which is the 6th in each row. Those aren't the buttons I'm talking about. <form action="<? echo $PHP_SELF; ?>" method="post" name="yesorno"> <input type="submit" name="yesdiscard" value="Discard"> <input type="submit" name="cancel" value="Cancel"></form> Those two buttons, which show up after you click [Discard] for any item, are the problem. I'll try closing the input buttons, thanks!
  6. I'm creating an inventory page on a virtual pet site where your items are held, and right now I'm working on a Discard button so you can delete items. When you click [Discard], verification should show up at the bottom asking "Are you sure you want to permanently discard of this item?" and two more submit buttons are shown: Discard and Cancel. Each item has a certain ID number so that when you click Discard, it only discards that item and not every item, and I'm using php to grab the ID of the item you clicked Discard for so that the entry can be deleted from a table of items. I was able to successfully work discarding items before I added my own little verification system, but now that I added a second form, I can't get the buttons to work. <? $title2="Inventory"; include("mainlayout.php"); if ($notlogged==yes) { echo "<center><h2><font class=\"header\">Sorry, this area is accessible only by members.</font></h2></center>"; } else { ?> <center> <h1><font class="header">Inventory</font></h1> <? $sql=mysql_query("SELECT * FROM inventory WHERE username='$username'"); if(mysql_num_rows($sql)==0){ echo "<center><font class=header>Your inventory is empty.</font></center>"; } if(mysql_num_rows($sql) > 0){ echo "<table border=\"0\">"; echo "<tr>"; for($i=0;$i<=mysql_num_rows($sql);$i=$i+1){ while($row = mysql_fetch_array($sql)){ $itemcode = $row['itemcode']; // These are just random variables used for making the $category = $row['category']; // images of the items show up. $itemname = $row['itemname']; $idofitem = $row['id']; // Here's where the item id is given a variable. $i++; if($i%6==0){ // use the operator to find the remainder of $i / 6 (%) // if the remainder is 0; it is a multiple of 6, so make a new row. echo "<td align=\"center\"><img src=\"http://midaevon.pcriot.com/images/items/$category/$itemcode.png\" /><br />$itemname<br />"; ?> <form action="<? echo $PHP_SELF; ?>" method="post" name="discarditem"> <input type="hidden" name="idofitem" value="<? echo $idofitem; ?>"> <input type="submit" name="discarditem" value="[Discard]"></form> //first discard button <? echo "</td></tr><tr>"; } else { echo "<td align=\"center\"><img src=\"http://midaevon.pcriot.com/images/items/$category/$itemcode.png\" /><br />$itemname<br />"; ?> <form action="<? echo $PHP_SELF; ?>" method="post" name="discarditem"> <input type="hidden" name="idofitem" value="<? echo $idofitem; ?>"> <input type="submit" name="discarditem" value="[Discard]"></form> //first discard button <? echo "<td>"; } } } echo "</tr></table>"; } if (isset($_POST['discarditem'])) { // if you click discard for any item, $idofitem2 = $_POST['idofitem']; ?> // new variable for the specific item discarded <font color="red">Are you sure you want to permanently discard of this item?</font><br /> <form action="<? echo $PHP_SELF; ?>" method="post" name="yesorno"> <input type="submit" name="yesdiscard" value="Discard"> <input type="submit" name="cancel" value="Cancel"></form> <? if (isset($_POST['yesdiscard'])) { // if you click Discard, mysql_query("DELETE FROM inventory WHERE id='$idofitem2'") // the item should be deleted or die(mysql_error()); echo "This item has been permanently discarded."; } else if (isset($_POST['cancel'])) { // if you click cancel, header( 'Location: redirect page goes right here' ); // you will be redirected back } } ?> </center> </center> <? } ?> </div> </body> Neither the second Discard button nor the Cancel button work. When clicking the Cancel button, of course it redirects only because the form action is <? echo $PHP_SELF; ?>. If I delete the redirect part and just make it so that it echoes something when canceled, it doesn't work. Therefor, neither button works. Any ideas? I've tried to search for how to make a javascript confirm box when Discard is clicked, that sounds a lot easier, but I don't know much javascript. Any help with this option would be appreciated as well.
×
×
  • 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.