magi Posted June 25, 2007 Share Posted June 25, 2007 Hey Everyone, sorry to bother you but im having some problems. I am making a calculator for an online game to calculate attacks and things. However i cannot seem to get his part here to work. echo'<td align"left" width="155"> <select class="inputBox" id="iRacePK0" name="D1"> <option value="1">Dwarven </option><option value="2">Imperials </option><option value="3">Shinobi </option><option value="4">Templars </option><option value="5">Treefolk </option><option value="6">Avian </option><option value="7">Abominations </option><option value="8">Orcs </option><option value="9">Snowkin </option></select> </td></tr><tr>'; if(D1=='Dwarven'){ echo'<td align"left" width="155"> Gnome Sapper </td>'; }else if(D1==2){ echo'<td align"left" width="155"> Your Mom </td>'; } echo'<td align"left" width="155"><input type="hidden" name="unitpk1"><input type="hidden" name="totalunits1">'; echo'<input type="text" name="totalunitssent1" class="inputbox" value="0" maxlength="9" size="6"></td></tr><tr>'; What i am trying to do is if the select drop down box is a certain race, to put the unit name and then there is an input box. I also want it to change when a new race is selected but currently it only changes when my button is pressed. Any help ? Quote Link to comment Share on other sites More sharing options...
magi Posted June 25, 2007 Author Share Posted June 25, 2007 Anyone ? Quote Link to comment Share on other sites More sharing options...
magi Posted June 25, 2007 Author Share Posted June 25, 2007 Anyone Help me ? Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 if you want the prompt result like on change use ajax do you know about that i think that can help you or tell us what you like to know about that Quote Link to comment Share on other sites More sharing options...
magi Posted June 25, 2007 Author Share Posted June 25, 2007 Well the thing i want is make it so that when the race Dwarven is picked, a certain unit name appears. And that if i change the race then the unit name changes to somehting else. Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 it like when you chose a certain option from a select you want that to appear some where else? http://www.w3schools.com/php/php_ajax_database.asp Quote Link to comment Share on other sites More sharing options...
magi Posted June 25, 2007 Author Share Posted June 25, 2007 NO, what i want to do is this I have a select list with different items. If i change the item to Dwarven it comes out like this Race: Dwarven Unit 1: Gnome Sapper then when i cange the race this appears Race: Templar Unit 1: Imperial Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 i dont think that this will solve you prob coz the way i see it theres still more error any way try this and tell me the following error echo'<td align"left" width="155"> <select class="inputBox" id="iRacePK0" name="D1"> <option value="1">Dwarven </option> <option value="2">Imperials</option> <option value="3">Shinobi</option> <option value="4">Templars </option><option value="5">Treefolk</option> <option value="6">Avian </option> <option value="7">Abominations </option> <option value="8">Orcs</option> <option value="9">Snowkin </option></select> </td></tr><tr>'; if($_POST['D1']=='Dwarven') { echo'<td align"left" width="155"> Gnome Sapper </td>'; }else { echo'<td align"left" width="155"> Your Mom </td>'; } echo'<td align"left" width="155"><input type="hidden" name="unitpk1"><input type="hidden" name="totalunits1">'; echo'<input type="text" name="totalunitssent1" class="inputbox" value="0" maxlength="9" size="6"></td></tr><tr>'; first $_POST['D1'] you initialize in your code the ID it good if that was defined then tell me the other thing obaut your code Quote Link to comment Share on other sites More sharing options...
magi Posted June 25, 2007 Author Share Posted June 25, 2007 Well i feel stupid now that that was all it was Now for the second part what i would like to do is when you change the selection in the box, it resets the page with the new data For example When you go to the page Racw: Dwarven Unit: Imps When you change the race to Imperials, it refreshes the page and puts Race: Imperials Unit: G's Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 you can use the this if you dont want the submit button i hitnk thats wat you mean <select class="inputBox" id="iRacePK0" name="D1" onchange="javascript:document.getElementById("myForm").submit()"> Quote Link to comment Share on other sites More sharing options...
magi Posted June 25, 2007 Author Share Posted June 25, 2007 That didnt seem to work, however i do have another question. I decided to try a different way to do this and it doesnt seem to be working. This way is much more efficient for me as i dont want to be doing 50 if statements. This was used on another page of mine and works fine but will not work on this page. <select class="inputBox" id="iRacePK0" name="D1" onchange="javascript:document.getElementById("myForm").submit()"><option value="1">Dwarven </option><option value="2">Imperials </option><option value="3">Shinobi </option><option value="4">Templars </option><option value="5">Treefolk </option><option value="6">Avian </option><option value="7">Abominations </option><option value="8">Orcs </option><option value="9">Snowkin </option></select> </td></tr><tr>'; $get_min_id=mysql_query("SELECT MIN(id) FROM mnamedb WHERE race= '$_POST[D1]'",$link ) or die(mysql_error()); $min_id=mysql_fetch_array($get_min_id); $m_details=mysql_query("SELECT * FROM mnamedb WHERE race = '$_POST[D1]' AND atk!=0 ORDER BY id ASC",$link ) or die(mysql_error()); while ($details=mysql_fetch_array($m_details)){ $m=$details[id]-$min_id[0]+1; if ($m==1) $m_num=m1; if ($m==2) $m_num=m2; if ($m==3) $m_num=m3; if ($m==4) $m_num=m4; if ($m==5) $m_num=m5; if ($m==6) $m_num=m6; // only show if current have troops of that type if ($newarray[$m_num]!=0){ echo'<tr class="admincell"><td><span onMouseover="ddrivetip(\'Offense:'.$details[3].'<br>Defense:'.$details[4].'<br>Mage:'.$details[6].'<br>Spy:'.$details[5].' \')" onMouseout="hideddrivetip()">'.$details[mname].'</span> </td>'; echo"<td>".number_format($newarray[$m_num])." </td>"; // display current troops strength echo'<td><input class="inputp" name="'.$m_num.'" type="text" size="5" maxlength="5" value="'.$_POST[$m_num].'"></td></tr>'; // display textbox } } $get_min_id=mysql_query("SELECT MIN(id) FROM mnamedb WHERE race= '$_POST[D1]'",$link ) or die(mysql_error()); $min_id=mysql_fetch_array($get_min_id); $m_details=mysql_query("SELECT * FROM mnamedb WHERE race = '$_POST[D1]' AND atk!=0 ORDER BY id ASC",$link ) or die(mysql_error()); while ($details=mysql_fetch_array($m_details)){ $m=$details[id]-$min_id[0]+1; if ($m==1) $m_num=m1; if ($m==2) $m_num=m2; if ($m==3) $m_num=m3; if ($m==4) $m_num=m4; if ($m==5) $m_num=m5; if ($m==6) $m_num=m6; // only show if current have troops of that type if ($newarray[$m_num]!=0){ echo'<tr class="admincell"><td><span onMouseover="ddrivetip(\'Offense:'.$details[3].'<br>Defense:'.$details[4].'<br>Mage:'.$details[6].'<br>Spy:'.$details[5].' \')" onMouseout="hideddrivetip()">'.$details[mname].'</span> </td>'; echo"<td>".number_format($newarray[$m_num])." </td>"; // display current troops strength echo'<td><input class="inputp" name="'.$m_num.'" type="text" size="5" maxlength="5" value="'.$_POST[$m_num].'"></td></tr>'; // display textbox This above code is the part that seems not to be working. Im not sure why it doesnt work though. It will display the text box in the wrong part of the code but the text box displays nonetheless, HOwever i cannot get any of the info from my query to appear with the text box, any help ? Quote Link to comment Share on other sites More sharing options...
magi Posted June 25, 2007 Author Share Posted June 25, 2007 BUMP Quote Link to comment Share on other sites More sharing options...
trq Posted June 25, 2007 Share Posted June 25, 2007 One of the reasons your getting little response is your lack of a decent subject title, and also a pretty distinct lack of being able to build a decent question. You might benifit from a read of the How to.... link in my signiture. As for your issue. Could be a number of things but this stands out for me. if ($m==1) $m_num=m1; m1 meens nothing to PHP. Have you defined it as a constant somewhere? Otherwise, it needs to be dfined as a string... if ($m==1) $m_num="m1"; I suggest you turn on error reporting and let us know what errors your getting. Quote Link to comment Share on other sites More sharing options...
magi Posted June 25, 2007 Author Share Posted June 25, 2007 OK Sorry, i will try to be a bit more clear. When you go to the page, a form appears with a selection box. In the selection box is different races. It first appears like this Race : (dropdown box with different races) Dwarven is the first one Unit: (this is the dwarvens first unit) Gnome Sapper What i want to happen is that when i change the dropdown box option the unit name will change according to what the race is. Quote Link to comment Share on other sites More sharing options...
trq Posted June 25, 2007 Share Posted June 25, 2007 Your problem is best solved using Javascript, not PHP. 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.