Jump to content

Query and php


Xtremer360

Recommended Posts

Not sure whether this belongs in php or javascript seeing as how it deals with both but we'll see what kind of responses I get.

 

I have a dropdown that lists countries and their id from my database and then when the user selects one it sends a post parameter through jquery to a php process page where it matches up the countryid to all the arenas in a table and then here's wehre I'm stuck I already have a dropdown in form like so:

 

<div class="field required">
    			<label for="arena">Arenas</label>
                <select class="dropdown" name="arenas" id="arenas" title="Arenas">
                </select>
    			<span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
    		</div>

 

I'm not sure how I should send over the values if I should just pass over the entire dropdown box with the values or just send back the values.

 

Any opinions?

Link to comment
Share on other sites

I hope I'm not leading you completely astray, and if I am I hope someone comes by and tells me how wrong I am and why.

 

I'm not sure if this code would work, I haven't been working with PHP for very long, but this is what I thought about when you told me your problem:

 

page.php?countryid=10

 

<?

$countryid = $_GET['countryid'];

$query = "select arena, arenaid from database where countryid = '".$countryid."'";
$result = mysql_query($query);

$numrows = mysql_num_rows($result);

$i = 0;

while ($i < $numrows) {

$arenano = $i+1;
$arena = mysql_result($result, $i, "arena");
$arenaid = mysql_result($result, $i, "arenaid");

$slct = "arena".$arenano;

$$slct = "<option value = '".$arenaid."'>".$arena."</option>
         ";

$slcts .= ".arena".$arenano;

$select = $$slcts.".";

i++;

}

echo "
<div class='field required'>
<label for='arena'>Arenas</label>
	<select class='dropdown' name='arenas' id='arenas' title='Arenas'>"
		.$$select.
	"</select>
<span class='required-icon tooltip' title='Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. '>Required</span>
</div>";

?>

 

The code *should* get the arenas and generate a variable containing a select tag with each arena in it.  It then creates another variable that contains all the option tags.  Afterwords the variable is inserted between the select statement.

 

Hopefully this works the way I think it does, and if not hopefully it at least gives you an idea of what you want to do.

 

edited: modified code

Link to comment
Share on other sites

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.