shorty3 Posted September 2, 2009 Share Posted September 2, 2009 ive got this so far <select name="choose" id="choose" onChange="MM_jumpMenu('this',this,0)"> <option selected>Choose car</option> <?php $get=mysql_query("SELECT * FROM garage WHERE owner='$username' and damage='0' and car='$stuff'"); while($it=mysql_fetch_object($get)){ echo "<option value=?car=$it->id>$it->car, $it->damage%</option>"; } ?> </select> i want it to show only cars i want it to show that are in my database eg: if i have a ford mustang and ferrari enzo and bmw m3 i want it so i can only use certain cars for certain things if you need more information just ask thanks Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/ Share on other sites More sharing options...
shorty3 Posted September 2, 2009 Author Share Posted September 2, 2009 ? Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911256 Share on other sites More sharing options...
bundyxc Posted September 2, 2009 Share Posted September 2, 2009 if you need more information just ask Yeah. What do you want? Your post was confusing, and we don't know what you want (which is why you didn't get any replies). Slow down, use proper grammar, punctuation, and capitalization.. and explain to us exactly what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911264 Share on other sites More sharing options...
shorty3 Posted September 2, 2009 Author Share Posted September 2, 2009 Right I want the drop down to only show certain cars. So i might have 5 cars in the garage but only 3 of them can be used for racing how would i do this i thought i could do it this way <?php $get=mysql_query("SELECT * FROM garage WHERE owner='$username' and damage='0' and car='carname','carname2"); but it dont work Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911268 Share on other sites More sharing options...
jamesxg1 Posted September 3, 2009 Share Posted September 3, 2009 Right I want the drop down to only show certain cars. So i might have 5 cars in the garage but only 3 of them can be used for racing how would i do this i thought i could do it this way <?php $get=mysql_query("SELECT * FROM garage WHERE owner='$username' and damage='0' and car='carname','carname2"); but it dont work Dude please use the captions , What errors are you getting ?. And here try this, I am assuming you have a mysql connection code. <select name="choose" id="choose" onChange="MM_jumpMenu('this',this,0)"> <option selected>Choose car</option> <?php $get = mysql_query("SELECT * FROM `garage` WHERE owner = '$username' AND damage='0' AND car = '$stuff'"); while($it = mysql_fetch_array($get)) { echo "<option value=?car=" . $it['id'] . ">" .$it['car'] . "," . $['damage'] . "%</option>"; } ?> </select> James. Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911317 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 Thats not my problem it works but i want to add something else to make it only drop down what can be dropped down example i ave a ferrari enzo, a ford f40 and a ford mustand fastback in my garage and only the ford f40 could only be used in a race so i want the drop down to only show cars that can be used in a race Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911852 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911877 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 What criteria makes a car able to race? PHP doesn't just a function that can tell if you can race a car.. you have to come up with the rules yourself. Is there a column in your database that tells if the car can race? a column that tells which types of races it can participate in. You are going to have to provide more information than "I want to show cars that can race"... That means absolutely nothing to me.. Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911878 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 Right this is the code. I`ll tell you what ive done so you can understand 1. as you can see damage='0' so it will only show up cars with 0 damage and car='ferrari enzo',ford mustang' which doesnt work thats one way ive tried. <select name="choose" id="choose" onChange="MM_jumpMenu('this',this,0)"> <option selected>Choose car</option> <?php $get=mysql_query("SELECT * FROM garage WHERE owner='$username' and damage='0' and car='ferrari enzo','ford mustang'"); while($it=mysql_fetch_object($get)){ echo "<option value=?car=$it->id>$it->car, $it->damage%</option>"; } ?> [/select] 2. This time i tried a code that referes to the cars that can be used. <?php $cars=('ferrari enzo') $cars=('ford msutang') <select name="choose" id="choose" onChange="MM_jumpMenu('this',this,0)"> <option selected>Choose car</option> <?php $get=mysql_query("SELECT * FROM garage WHERE owner='$username' and damage='0' and car='$cars'"); while($it=mysql_fetch_object($get)){ echo "<option value=?car=$it->id>$it->car, $it->damage%</option>"; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911887 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 that is all wrong... well not all wrong, but judging by what you wrote, this does not do nearly what you think it will. First from the first code "SELECT * FROM garage WHERE owner='$username' and damage='0' and car='ferrari enzo','ford mustang" this query is completely invalid. idk what you are trying to do with "car='ferrari enzo','ford mustang", but if you want to make it so it will pull out everything where the car is either an enzo or a stang, you have to do something like "SELECT * FROM garage WHERE owner='$username' and damage='0' and (car='ferrari enzo', OR car='ford mustang')" this script is just atrocious... <?php $cars=('ferrari enzo') $cars=('ford msutang') <select name="choose" id="choose" onChange="MM_jumpMenu('this',this,0)"> <option selected>Choose car</option> <?php $get=mysql_query("SELECT * FROM garage WHERE owner='$username' and damage='0' and car='$cars'"); while($it=mysql_fetch_object($get)){ echo "<option value=?car=$it->id>$it->car, $it->damage%</option>"; } ?> you can;t really do anything like you just did. You can't just type HTML inside of PHP tags without echoing them. You need semi colons at the end of stuff. and the following lines $cars=('ferrari enzo')//need semi colons $cars=('ford msutang')//semi colons are useless because it only stores one of the values (in this case, it stores ford mustang) it seems like you want to store them as an array. you do that by doing the following $cars = array('enzo', 'stang'); But you can't use an array inside a query like you seem to want to do. you would have to do something like mysql_query("SELECT * FROM garage WHERE owner='$username' and damage='0' and (car='".$cars[0]."', OR car='".$cars[1]."')"); but thats pretty much the same as the example I gave you above. and this still doesn't answer my question as to what constitutes a car as race able... Can only Enzo's and Mustang's race? Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911891 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 lol say if ive got 20 cars in the garage ive got cars from ferraris enzos to mini coopers but i want it so only certain can race so if i use the drop down it will only show cars that can race and not all the cars i have in my garage Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911899 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 ..... i understand the fact that you have multiple cars in your garage. I also understand you only want certain ones to be able to race. why can only certain cars race... Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911901 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 lol its for a game Right if i use this mysql_query("SELECT * FROM garage WHERE owner='$username' and damage='0' and (car='".$cars[0]."', OR car='".$cars[1]."')"); would i need to do this $cars=ferrari enzo[1]; $cars=mini cooper[2]; Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911907 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 ........ I'm sorry but you are completely incapable of explaining what you want. and no, you wouldn't need to do that Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911919 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 Well i dont get how that would work then Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911928 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 this: $cars=ferrari enzo[1]; $cars=mini cooper[2]; is wrong, arrays don't work that way. look up a tutorial on PHP arrays. Honestly I would suggest you look up tutorials on a lot of things before you try to tackle this project, because based on the code you posted you don't even understand basic syntax rules Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911930 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 $cars = array('Alfa Romeo Brera[0]','Rolls Royce Phantom[1]' ); ? And thats only part of the script im trying to sort this i dont expect criticism from you i apparicate all your help and respect your knowledge i admit im not the best coder and need abit of guildence. Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911941 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 http://www.w3schools.com/PHP/php_arrays.asp Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911942 Share on other sites More sharing options...
Yesideez Posted September 3, 2009 Share Posted September 3, 2009 Let's say in your garage table you have an extra field, let's call it "canrace" and make it boolean (0 or 1) You can then have a query like this: SELECT * FROM garage WHERE owner='$username' AND damage='0' AND canrace=1 Those cars that can race set to 1 and those that can't, set to 0. Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911950 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 this is probally a good idea just what i needed thank you Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-911971 Share on other sites More sharing options...
shorty3 Posted September 3, 2009 Author Share Posted September 3, 2009 solved thanks Quote Link to comment https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/#findComment-912050 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.