Setting values in an option function and the option
Moderator: General Moderators
Setting values in an option function and the option
HELLO ALL,
I am new to PHP
I'm trying to set up an option that sets the value and the option data for my web site..
I am have have successfully taken the data from mySQL but I can't seem to set the proper function to
echo '<option value="$data1[]">$data2[]</option>'
Each set of data comes from seperate tables and are both arrays..
Thanks in advance.
I am new to PHP
I'm trying to set up an option that sets the value and the option data for my web site..
I am have have successfully taken the data from mySQL but I can't seem to set the proper function to
echo '<option value="$data1[]">$data2[]</option>'
Each set of data comes from seperate tables and are both arrays..
Thanks in advance.
Re: Setting values in an option function and the option
might want to brush up on your html first. an option is defined like thisDeaglex wrote:HELLO ALL,
I am new to PHP
I'm trying to set up an option that sets the value and the option data for my web site..
I am have have successfully taken the data from mySQL but I can't seem to set the proper function to
echo '<option value="$data1[]">$data2[]</option>'
Each set of data comes from seperate tables and are both arrays..
Thanks in advance.
Code: Select all
<input type="radio" name="input_name" value="X" />Code: Select all
echo '<label for="this_radio">'.$dataї2].'<input type="radio" value="'.$dataї1].'" id="this_radio" /></label>';I need it to pull from two differnt tables
I'm using a this so far and I don't know how to get seperate values posted in the HTML
query = "SELECT CONCAT(driver_first_name, ' ' ,driver_last_name) AS name, driver_id FROM drivers ORDER BY driver_id ASC";
$result = @mysql_query ($query); //Run this query.
$nub= mysql_num_rows ($result);
if ($nub > 0) //If if ran OK display the records
{
echo "<select>";
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<option value=\"$row[0]\">$row[0]</option>";
}
I want the option value="" to be the driver_id
I don't want to have to redefine the driver's name as driver_id later in the script. Cuz that would be reduntant and a waste of time.
I should have clarified better,
THANKS
query = "SELECT CONCAT(driver_first_name, ' ' ,driver_last_name) AS name, driver_id FROM drivers ORDER BY driver_id ASC";
$result = @mysql_query ($query); //Run this query.
$nub= mysql_num_rows ($result);
if ($nub > 0) //If if ran OK display the records
{
echo "<select>";
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<option value=\"$row[0]\">$row[0]</option>";
}
I want the option value="" to be the driver_id
I don't want to have to redefine the driver's name as driver_id later in the script. Cuz that would be reduntant and a waste of time.
I should have clarified better,
THANKS
Re: I need it to pull from two differnt tables
Ahh, I should have realized what you were doing with the option tag. Anyway the driver id is stored in the $row array at index 1, $row[1]. The name is at index 0, $row[0].Deaglex wrote:I'm using a this so far and I don't know how to get seperate values posted in the HTML
query = "SELECT CONCAT(driver_first_name, ' ' ,driver_last_name) AS name, driver_id FROM drivers ORDER BY driver_id ASC";
$result = @mysql_query ($query); //Run this query.
$nub= mysql_num_rows ($result);
if ($nub > 0) //If if ran OK display the records
{
echo "<select>";
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<option value="$row[0]">$row[0]</option>";
}
I want the option value="" to be the driver_id
I don't want to have to redefine the driver's name as driver_id later in the script. Cuz that would be reduntant and a waste of time.
I should have clarified better,
THANKS
Re: WOOT!
not a problem. If you want to make your code more readable and managable, you should use the mysql_fetch_assoc instead of mysql_fetch_array. You wont need the second parameter (MYSQL_NUM), and then your array indexes will be associative, meaning instead of numerical they will coincide with the database field name. Like this:Deaglex wrote:THANKS!!
Code: Select all
query = "SELECT CONCAT(driver_first_name, ' ' ,driver_last_name) AS name, driver_id FROM drivers ORDER BY driver_id ASC";
$result = @mysql_query ($query); //Run this query.
$nub= mysql_num_rows ($result);
if ($nub > 0) //If if ran OK display the records
{
echo "<select>";
while ($row = mysql_fetch_assoc($result))
{
echo '<option value="'.$rowї'driver_id'].'">'.$rowї'name'].'</option>';
}feyd |
THAT ROCKS TY.....ONE other thing
Code: Select all
<select name="diї]">.........
while ($row = mysql_fetch_assoc($result, MYSQL_NUM))
{
echo "<option name="$rowї1]" >$rowї0]</option>";
}
}I know it's any easy fix I just can't seem to put the right search in. Thanks again.
THAT ROCKS TY.....ONE other thing
Code: Select all
<select name="diї]">.........
while ($row = mysql_fetch_assoc($result,))
{
echo "<option name="$rowїdriver_id]" >$rowїname]</option>";
}
}I know it's any easy fix I just can't seem to put the right search in. Thanks again.
UPDATED CODE...
try using $row['name']...
edit: didn't read carefully enough
are you just trying to get the output if di[] on the form action page?
if so you're going to need to convert it from an array to a string
try
edit: didn't read carefully enough
are you just trying to get the output if di[] on the form action page?
if so you're going to need to convert it from an array to a string
try
Code: Select all
$bob = implode(",",$_POSTї'di']);
echo $bob;That didn't work for some reason. I tried it.. It doesn't have value on the action page...
I'm lost what I want is to select the drivers name and have it output the driver_id when submitted... when i implode the a ray it kicks out the driver's name how can I get it to output the driver_id after selecting the drivers name?
I know it's easy I just can't find where to get the info...
Thanks
Code: Select all
select name="di" >
<?
#####################################
# Data Base Access For Driver #
# Names #
#####################################
require_once ('connection.file'); //connect to DB
$dbc;
//set message to null
$message= NULL;
// Checking driver data
$query = "SELECT CONCAT(driver_first_name, ' ' ,driver_last_name) AS name, driver_id FROM drivers ORDER BY driver_id ASC";
$result = @mysql_query ($query); //Run this query.
$nub= mysql_num_rows ($result); //Check if list is populated
if ($nub > 0) //If if ran OK display the records
{
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<option name="$rowї1]" value"">$rowї0]</option>";I know it's easy I just can't find where to get the info...
Thanks