Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/172901-solved-need-help-with-dropdown/
Share on other sites

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.

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

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.

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

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..

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>

         

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?

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

 

$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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.