Page 1 of 2
Drop List mysql Array
Posted: Mon May 31, 2004 8:44 pm
by recsx
I have been trying to do something for the past 4 days with no luck.
Need help badly.
Here is my situation.
I have a drop list populated by a mysql_query
it will query a table called PACKAGES from it!, it will retrieve 2 columns of data one called [pname] the other called [radius_attributes_high].
for whatever selection is made in the drop list form i need the [pname] and the [radius_attributes_high] sent to another table called CLIENTS and in the clients table the will go under....
[pname] -> [package] and [radius_attributes_high] -> [radius_attributes]
I cant seem to figure out what to do with it, here is my code;
<?PHP
$package_result = mysql_query("SELECT pname, radius_attributes_high FROM packages",$mysql_ID);
echo '<select name="radius_attributes" TABINDEX="18">';
while ($row_item = mysql_fetch_assoc($package_result)){
$attributes = $row_item["radius_attributes_high"];
$pname = $row_item["pname"];
echo "<OPTION value=\"$attributes\">$pname</OPTION>";
}
echo '</SELECT><BR>';
mysql_free_result ($package_result);
?>
$pname is the Name of the PACKAGE and $attributes is the Radius Attributes
What this is meant to do is this;
i have a table PACKAGES to manage and maintain ISP packages and a table CLIENTS to maintain clients the above script is just a portion of a full form the is the part when ADDING a new client you will choose from available packages i need the package name to be placed in the clients account so i know what package he/she has and i also need the attributes that package uses and it be placed into the clients account under the radius_attributes field.
So i you all get what im doing does anyone have suggestions on what i can do to send these two values from a SELECT field?
Posted: Mon May 31, 2004 8:46 pm
by tim
try mysql_fetch_array() in replace of fetch_assoc
Posted: Mon May 31, 2004 9:02 pm
by Joe
Try something along the lines of:
<?PHP
echo "<select name='radius_attributes' TABINDEX='18'>";
$query = "SELECT pname, radius_attributes_high FROM packages",$mysql_ID;
$result = mysql_query($query) or die("Error!");
while (true)
{
$row_item = mysql_fetch_assoc($result);
if ($row_item == false) break;
$attributes = $row_item["radius_attributes_high"];
$pname = $row_item["pname"];
echo "<OPTION value='$attributes'>$pname</OPTION>";
}
echo "</SELECT><BR>";
mysql_close($query);
?>
Regards
Joe

Posted: Mon May 31, 2004 9:16 pm
by tim
never or die("Error"); with SQL query's
or die(mysql_error());

Posted: Mon May 31, 2004 9:19 pm
by Joe
Whoops silly me :~) If it is only a small code and the word error popped up you would most obviously know its an error with the query, lol. But i guess your right as one always likes a full explination of an error, hehe

Posted: Tue Jun 01, 2004 6:02 am
by recsx
Thanks alot for the replies.
BUT! ........
You aint gettin what im asking.
Let me ask again in a different way.
A DROP LIST! ....
TWO VARIABLES ....
FOR A SELECTION SEND TWO VARIABLES FROM THAT DROP LIST IN TWO DIFFERENT PLACES.
P.S.
if ya put $variable1 and $variable2 between the VALUE tag of an OPTION the dam things are going to go to the same place E.G. (((( THE NAME AS SET BY THE SELECT TAG ))))
ARRRRRRRRG!!!!!!!!
Don't mind me guy's and gals it's just that i've been on so many forums in the past week and i keep getting the same every where nobody understands what my question is.
Thanks
Posted: Tue Jun 01, 2004 9:15 am
by evanz
how about concatenate two values using a special separator to a single value then separate and retrieve them in the client table page:
some thing:
echo "<OPTION value=\"$attributes . "XXX" . $pname . \">$pname</OPTION>";
in the client page:
arr = explode("XXX", $HTTP_POST_VAR['attribute_value']);
list ($attr, $pname) = each arr;
etc. ...
Posted: Tue Jun 01, 2004 9:47 am
by pickle
Ya, put the two variables in a single drop list. Then when you are processing the form, split the variable and deal with each value separately. Pretty much just what ~evanz said.
Posted: Tue Jun 01, 2004 2:29 pm
by recsx
evanz wrote:how about concatenate two values using a special separator to a single value then separate and retrieve them in the client table page:
some thing:
echo "<OPTION value="$attributes . "XXX" . $pname . ">$pname</OPTION>";
in the client page:
arr = explode("XXX", $HTTP_POST_VAR['attribute_value']);
list ($attr, $pname) = each arr;
etc. ...
OK...
Hmm...
I'll try this, im still trying to see the logic in your example.
Never the less i'll see if i can make it work if i do i'll get back you and post my results; ok?
Thanks a mill guys and gals
Posted: Tue Jun 01, 2004 3:42 pm
by recsx
Ok i tried this but it dont work it gives an error right away
Parse error: parse error in /home/xxxxxxxxxxx.xxx/temp/index.php on line 300
this
<OPTION value=\"$attributes . "XXX" . $pname . \">$pname</OPTION>
the . dot cause an error in my scripts
have any ideas?
Maybe i should post my entire page?
Yes? No?
what do ya think?
Posted: Tue Jun 01, 2004 3:46 pm
by feyd
echo "<OPTION value=\"{$attributes}XXX{$pname}\">$pname</OPTION>";
Posted: Tue Jun 01, 2004 4:24 pm
by pickle
recsx wrote:
<OPTION value="$attributes . "XXX" . $pname . ">$pname</OPTION>
I always try to use the "." as little as possible, hence my version would look.
Code: Select all
$string_to_echo = "<option value = '$attributesXXX$pname'>$pname</option>";
Inside double-quotes, variables are parsed (although I'm not sure how it'll work with the XXX right beside $attributes). Anyway, try that and see what happens.
Posted: Tue Jun 01, 2004 4:28 pm
by Weirdan
pickle wrote:
(although I'm not sure how it'll work with the XXX right beside $attributes).
XXX would be interpreted as a part of a variable name. feyd has posted solution.
Posted: Tue Jun 01, 2004 7:44 pm
by recsx
HOORAY!!!!!!!!!!!!!!!
it worked!!!!!!!
this is what i did
Here is my drop list
<?PHP
// Populate a Drop List for available packages
$package_result = mysql_query("SELECT pname, radius_attributes_high FROM packages",$mysql_ID);
echo '<select name="package_select" TABINDEX="18"><OPTION>';
echo $myrow["package"];
echo "</OPTION>";
while ($row_item = mysql_fetch_assoc($package_result)){
$attributes = $row_item["radius_attributes_high"];
$pname = $row_item["pname"];
echo "<OPTION value=\"$attributes" . "DIVIDE" . "$pname\">$pname</OPTION>";
}
if(mysql_num_rows($package_result) == "0"){
$no_packages = "<OPTION value=\"#No Attributes" . "DIVIDE" . "No Package\">No Packages Made</OPTION>";
}
echo "$no_packages";
echo '</SELECT><BR>';
mysql_free_result ($package_result);
// End Populate Drop List
?>
once submited my form is sent via $PHP_SELF
and
if (submit)
start doing my update client
but before the mysql query i entered the explode like this
// Package Drop List Explode and Seperate the Attributes from the Package Name
$selected_package = $_POST['package_select'];
$xx = explode("DIVIDE", $selected_package);
$radius_attributes = $xx[0];
$package = $xx[1];
// End Explode
and voila it works as it should
Man you guys and gals are life savers
i had to go to php.net for the right syntax of the explode statement and a few minutes of reading i had it down pat.
Oh! what i can do with this command is behond my brain.
Thanks a bunch.
Posted: Tue Jun 01, 2004 7:52 pm
by feyd
>> if(submit)
If that's the name of your submit button, I wouldn't bank on it being there. Someone that hit's enter to submit the form will not pass the button. Instead, I'd either look at $_SERVER['REQUEST_METHOD'], and/or look for a field that is always unique to that specic post/get..