Forum Moderators: coopster

Message Too Old, No Replies

Select tag pre defined

I want the select tag to select the current status

         

Twisted Mind

10:43 am on Oct 28, 2005 (gmt 0)

10+ Year Member



Hi i want to know how it is possible to make a <select></select> tag to get the current status from a mysql database and display that one...
like the database says 3 and the list has 1-10 that it displays 3 on opening of te page

panos

12:30 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



Use the selected attribute:

<select>
<option selected>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>....</option>
</select>

Twisted Mind

1:26 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



well i meant in mysql but with this info i think its enough to fix it make a variable with selected..

Twisted Mind

2:06 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



Okay i have this loop of records in my database and i want this select tag to be automaticly defined from db like i explained in my first post... can some1 tell me how to do it this is what i tried so far:

while(list($order_id,$order_status_it,$order_status_manager,$order_status_finance)=mysql_fetch_row($result)){
if ($order_status_finance == Pending)
{
$ppp = Selected;
}
if ($order_status_finance == Accepted)
{
$aaa = Selected;
}
if ($order_status_finance == Cancelled)
{
$ccc = Selected;
}

echo "

<form name=\"change_$order_id\" method=\"post\" action=\"components/com_confirmation/confirm_order_status_update.php\"\>
<input name=\"order_id\"type=\"hidden\" value=\"$order_id\">
<input name=\"order_status_manager\"type=\"hidden\" value=\"$order_status_manager\">
<input name=\"order_status_it\"type=\"hidden\" value=\"$order_status_it\">
<tr><td><strong>order id:</Strong> $order_id </td><td><strong></Strong></td></tr>
<tr><td><strong>current status :</td><td></strong> $order_status_finance</td></tr>
<tr><td><select name=\"order_status_finance\">
<option value=\"\">Choose status</option>
<option $ppp value=\"Pending\">Pending</option>
<option $aaa value=\"Accepted\">Accepted</option>
<option $ccc value=\"Cancelled\">Cancelled</option>
</select>
</td><td><input type=\"submit\" name=\"submit\" value=\"Update status\" class=\"button\"></td></tr>
</form><tr><td><form action=\"components/com_confirmation/billing_shipping_info.php\" action=\"submit\" target=\"_new\" name=\"info_$order_id\" >
<input name=\"order_id\"type=\"hidden\" value=\"$order_id\">
<input type=\"submit\" value=\"order $order_id info\" action=\"submit\" class=\"button\">
</form></td></tr>

dmmh

5:02 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



im gonna post one of my more advanced functions for this. I have come to the point, especially when for currency selectors that I could re-use the selector but needed to pass it arguments and sometimes conditions

a short explanation: this is my timezone selector so I can have the system adjust echoed times to the user's local time.
first the code:

function func_timezone_selector($pass){
$timezone_selector.= "<select name=\"timezone\" size=\"1\" class=\"menu\">\n";
{
$timezone_values = array(
'-11','-10','-9','-8','-7','-6','-5','-4','-3','-2','-1','GMT','+1','+2','+3','+4','+5','+6','+7','+8','+9','+10','+11','+12'); // initialise an array holding the timezone VALUES
$timezone_disp_name = array(
'-11: American Samoa, Midway Atoll, Samoa',
'-10: Cook Islands, Hawaii (HAST)',
'-9: [Alaska Standard] Alaska, Gambier Islands (AKST)',
'-8: [Pacific Standard] Los Angeles (PST)',
'-7: [Mountain Standard] Denver, Colorado Springs (MST)',
'-6: [Central Standard] Mexico City, Saskatchewan (CST)',
'-5: [Eastern Standard] Bogota, New York City (EST)',
'-4: [Atlantic Standard] Caracas, La Paz (AST)',
'-3: Brasilia, Buenos Aires, Georgetown',
'-2: Ocean Islands Brazil, South Georgia',
'-1: Azores, Cape Verde Islands',
'GMT: Greenwich, Londen, Edinburgh, Casablanca (UTC)',
'+1: [Central European] Amsterdam, Berlin, Vienna (CET)',
'+2: [Eastern European] Athens, Helsinki, Istanbul (EET)',
'+3: Kuwait, Moscow, Nairobi',
'+4: Abu Dhabi, Kabul, Volgograd',
'+5: Ashgabat, Dushanbe, Karachi, Malé',
'+6: Bishkek, Dhaka, Thimphu',
'+7: Bangkok, Hanoi, Phnom Penh',
'+8: Beijing, Hong Kong, Kuala Lumpur, Quezon City',
'+9: Dili, Tokyo, P\'yongyang, Seoul',
'+10: Hagåtña, Port Moresby, Saipan',
'+11: New Caledonia, Solomon Islands, Vanuatu',
'+12: Eniwetok, Bikini, Fiji, Marshall Islands, Wellington'
);//initialise an array holding the timezone display names

//this is here so we can pre-select it if there was a POST to the form the select is in, else it is ignored, very handy
if (isset($_POST['timezone'])){
$timezone_selected = $_POST['timezone'];
}
//if a value was passed to the function, $timezone_selected will hold it
if (!empty($pass)){
$timezone_selected = $pass;
}
//now count the number of values in the timezones values array
$nr_zones = count($timezone_values);
for ($i=0; $i<$nr_zones; $i++)
{
// and for the values....build the options...
$timezone_selector.= "<option value=\"$timezone_values[$i]\"";
//now the most important thing....if $timezone_selected holds a value which is the same as the current select option, pre-select it
if ($timezone_values[$i] == $timezone_selected)
{$timezone_selector.= " selected ";}
$timezone_selector.= ">$timezone_disp_name[$i]</option>\n";
}
// close the select tags
$timezone_selector.= "</select>"; }
return $timezone_selector;
}

it is easy to use the function, also to modify it. You can pass it a value, if you dont, just pass it an empty variable, else there will be an error.

Im not gonna re-write it to exactly what you need, this would defeat the purpose of this website ;)
you can use the function like: echo func_timezone_selector($empty_var);

adjusting it is easy, just pass it the value you need, rename the function and variables to suit your needs and youre done. Hint: change $timezone_values to hold the stuff you need (accepted, cancelled, pending)

Twisted Mind

7:19 am on Oct 31, 2005 (gmt 0)

10+ Year Member



i will see if i can get it to work...

Twisted Mind

7:30 am on Oct 31, 2005 (gmt 0)

10+ Year Member



This really isnt helpfull for me at all this script is looking for a post or whatsoever at my script it has to be read from a database (orders from shop) so it HAS to be looped wich this script does not...

dmmh

7:57 am on Oct 31, 2005 (gmt 0)

10+ Year Member



no, not really, but you just dont get it :p

use this function:

function func_order_status_selector($order_status){

$order_status_selector.= "<select name=\"order_status\" size=\"1\">\n";

if (empty($_POST['order_status'])){
$order_status_selected = $order_status;
}
if (isset($_POST['order_status'])){
$order_status_selected = $_POST['order_status'];
}

$poss_order_statusses = array('accepted', 'pending', 'cancelled');

foreach ($poss_order_statusses as $poss_order_status){
// build the options...
$order_status_selector.= "<option value=\"$poss_order_status\"";
if ($poss_order_status == $order_status_selected)
{$order_status_selector.= " selected ";}
$order_status_selector.= ">$poss_order_status</option>\n";
}
// close the select tags
$order_status_selector.= "</select>";
return $order_status_selector;
}

query like you normally do and pass the current order status to the function and it will preselect the appropriate option

list($order_id,$order_status_it,$order_status_manager,$order_status_finance)=mysql_fetch_row($result));
echo func_order_status_selector($order_status_finance);

/*this is the status for the current row, so we pass it to the function and inside the function there is a check to see which of the possible order statusses it matches with...*/

Twisted Mind

8:04 am on Oct 31, 2005 (gmt 0)

10+ Year Member



ill try if it works i will probaly understand it (i hope)

Twisted Mind

8:10 am on Oct 31, 2005 (gmt 0)

10+ Year Member



i really dont know what to do with this error:

Notice: Undefined variable: order_status_selector in D:\Fluke_Mambo\components\com_confirmation\order_status_finance.php on line 78

the script displays only one order it should be 6

thanks for the help though...

Twisted Mind

8:12 am on Oct 31, 2005 (gmt 0)

10+ Year Member



line 78 was $order_status_selector.= blah blah
i deleted the dot after selector is this allowed? takes care of the error though

dmmh

8:51 am on Oct 31, 2005 (gmt 0)

10+ Year Member



well thats just odd, the dot is needed or the selector will not work
lemme look into it a bit

maybe you could paste some more of your code?

dmmh

8:53 am on Oct 31, 2005 (gmt 0)

10+ Year Member



try this:

function func_order_status_selector($order_status){

$order_status_selector.= "<select name=\"order_status\" size=\"1\">\n";
{
if (empty($_POST['order_status'])){
$order_status_selected = $order_status;
}
if (isset($_POST['order_status'])){
$order_status_selected = $_POST['order_status'];
}

$poss_order_statusses = array('accepted', 'pending', 'cancelled');

foreach ($poss_order_statusses as $poss_order_status){
// build the options...
$order_status_selector.= "<option value=\"$poss_order_status\"";
if ($poss_order_status == $order_status_selected)
{$order_status_selector.= " selected ";}
$order_status_selector.= ">$poss_order_status</option>\n";
}
// close the select tags
$order_status_selector.= "</select>";
}
return $order_status_selector;
}

Twisted Mind

8:59 am on Oct 31, 2005 (gmt 0)

10+ Year Member



i put the . back ill submit all my code exept database and password info :P

<?
/************************************
**Order Confirmation form
**Created by MathijsSegers@gmail.com
**Copyright by FlukeCorp
************************************/

//Get Host
$Host ="localhost";

//Select Database
$Database ="fluke";

//Get database table
$table ="mos_pshop_orders";

//get 2cond table
$sessiontable="mos_session";

//get usertable
$usertable = "mos_users";

//Get database User
$User ="#*$!xxxx";

//Get database Password
$Password ="xxxxxxx";

// Connect to host
$connection = mysql_connect ($Host,$User,$Password);
//getting home country of confirmer
$query = "select
name, username, country FROM $usertable
WHERE username = '$my->username'";
$result = mysql_db_query("$Database",$query);
while(list($name,$username,$country)=mysql_fetch_row($result)){
echo"Welcome $name<br><br>";
$mycountry = $country;

;}
echo"<table>";
/*/get order statusses
$query =
"SELECT order_id,
order_status_it,
order_status_manager,
order_status_finance
FROM $table
WHERE order_id NOT IN (select order_id FROM mos_pshop_order_user_info WHERE country ='$mycountry')";
$result = mysql_db_query("$Database",$query);

while(list($order_id,$order_status_it,$order_status_manager,$order_status_finance)=mysql_fetch_row($result)){

echo "

<form name=\"change_$order_id\" method=\"post\" action=\"components/com_confirmation/confirm_order_status_update.php\"\>
<input name=\"order_id\"type=\"hidden\" value=\"$order_id\">
<input name=\"order_status_manager\"type=\"hidden\" value=\"$order_status_manager\">
<input name=\"order_status_it\"type=\"hidden\" value=\"$order_status_it\">
<tr><td><strong>order id:</Strong> $order_id </td><td><strong></Strong></td></tr>
<tr><td><strong>current status :</td><td></strong> $order_status_finance</td></tr>
<tr><td><select name=\"order_status_finance\">
<option value=\"\">Choose status</option>
<option value=\"Pending\">Pending</option>
<option value=\"Accepted\">Accepted</option>
<option value=\"Cancelled\">Cancelled</option>
</select>
</td><td><input type=\"submit\" name=\"submit\" value=\"Update status\" class=\"button\"></td></tr>
</form><tr><td><form action=\"components/com_confirmation/billing_shipping_info.php\" action=\"submit\" target=\"_new\" name=\"info_$order_id\" >
<input name=\"id\"type=\"hidden\" value=\"$order_id\">
<input type=\"submit\" value=\"order $order_id info\" action=\"submit\" class=\"button\">
</form></td></tr>
";
}*/
function func_order_status_selector($order_status){

$order_status_selector.= "<select name=\"order_status\" size=\"1\">\n";

if (empty($_POST['order_status'])){
$order_status_selected = $order_status;
}
if (isset($_POST['order_status'])){
$order_status_selected = $_POST['order_status'];
}

$poss_order_statusses = array('Accepted', 'Pending', 'Cancelled');

foreach ($poss_order_statusses as $poss_order_status){
// build the options...
$order_status_selector.= "<option value=\"$poss_order_status\"";
if ($poss_order_status == $order_status_selected)
{$order_status_selector.= " selected ";}
$order_status_selector.= ">$poss_order_status</option>\n";
}
// close the select tags
$order_status_selector.= "</select>";
return $order_status_selector;
}

$query =
"SELECT order_id,
order_status_it,
order_status_manager,
order_status_finance
FROM $table
WHERE order_id NOT IN (select order_id FROM mos_pshop_order_user_info WHERE country ='$mycountry')";
$result = mysql_db_query("$Database",$query);

list($order_id,$order_status_it,$order_status_manager,$order_status_finance)=mysql_fetch_row($result); {
echo func_order_status_selector($order_status_finance);}

/*this is the status for the current row, so we pass it to the function and inside the function there is a check to see which of the possible order statusses it matches with...*/

echo "</table>";
?>

Twisted Mind

9:00 am on Oct 31, 2005 (gmt 0)

10+ Year Member



as you see my previous code is with it, it makes 2 forms 1 for changing status other for displaying all info about order but it has been commented :)

Twisted Mind

9:03 am on Oct 31, 2005 (gmt 0)

10+ Year Member



This script does exactly the same...

Twisted Mind

9:17 am on Oct 31, 2005 (gmt 0)

10+ Year Member



Hey just saw u were dutch too :) are u still there?

dmmh

10:06 am on Oct 31, 2005 (gmt 0)

10+ Year Member



you forgot a while loop and lots of other stuff doesnt make any sense at all

I think this is what you need. Try to understand it, not just use it if it works for what you need. You are making some fundamental thinking/ coding errors :)
Hope you can take the criticism, trying to help you with understanding that this is for your own good :)

<?
require($_SERVER['DOCUMENT_ROOT'].'/includes/connect.php'); //DB connect info
require($_SERVER['DOCUMENT_ROOT'].'/includes/functions.php');//all your functions, put func_order_status_selector() function code into the file

$table ="mos_pshop_orders";
$sessiontable="mos_session";
$usertable ="mos_users";

/*putting a function here isnt one of the wisest things to do,
you are far better of making a new file and saving it to a folder which holds all your files with functions and code that is used more then once.
like a connect.php file, which holds your mysql username and password, so you dont have to typ it in all new PHP files you create for the site.
You are better of changing this now then later, it can be a #*$! to update hundreds of files
like:
/site_root/includes/connect.php
then simply do:
require($_SERVER['DOCUMENT_ROOT'].'/includes/connect.php');
require($_SERVER['DOCUMENT_ROOT'].'/includes/functions.php');
on top of the page/ php script.
So I have removed the DB connect info on top and the code of the function asuming you are gonna adopt this way of working. It's for your own good ;)
Because, what happens if your password changes......you will have to update multiple files ;)
*/

// Connect to host
$connection = mysql_connect ($Host,$User,$Password);
//getting home country of confirmer
$query = "SELECT name, username, country FROM $usertable WHERE username = '$my->username'";
$result = mysql_db_query("$Database",$query);
while(list($name,$username,$country)=mysql_fetch_row($result)){
echo "Welcome $name<br><br>"
$mycountry = $country;
;}

echo '<table>';
//get order statusses
$query ="SELECT order_id,order_status_it,order_status_manager,order_status_finance FROM $table
WHERE order_id NOT IN (select order_id FROM mos_pshop_order_user_info WHERE country ='$mycountry')";
$result = mysql_db_query("$Database",$query);?>

<form name="change_order_id" method="post" action="components/com_confirmation/confirm_order_status_update.php">
<? //do not put the form opening tag inside a loop, as you will only need one form for this......
while($row = mysql_fetch_array($result)){?>
<tr>
<td><strong>order id:</strong><? echo $row['order_id'];?></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong>current status:</strong></td>
<td><? echo $row['order_status_finance'];?></td>
</tr>
<tr>
<td><? echo func_order_status($row['order_status_finance']);//this is where we use the function!?></td>
<td>
<input type="submit" name="submit" value="Update status" class="button">
<input name="order_id" type="hidden" value="<? echo $row['order_id'];?>">
<input name="order_status_manager" type="hidden" value="<? echo $row['order_status_manager'];?>">
<input name="order_status_it" type="hidden" value="<? echo $row['order_status_it'];?>">
</td>
</tr>
</form>
<tr>
<td><form action="components/com_confirmation/billing_shipping_info.php" action="submit" target="_new" name="info_order_id" >
<input name="id" type="hidden" value="<? echo $row['order_id'];?>">
<input type="submit" value="order <? echo $order_id info;?>" action="submit" class="button">
</form>
</td>
<td>&nbsp;</td>
</tr>
<? }?>
</table>

Twisted Mind

10:36 am on Oct 31, 2005 (gmt 0)

10+ Year Member



dude thats wierd i am sure i have a while tag in my script...

ur right i did forget it il check it out

there is no need for the connect becouse im editing a mambo site the connect isnt really necacarry i think :)

as displayed this is just part of a page wich already connects

Twisted Mind

10:49 am on Oct 31, 2005 (gmt 0)

10+ Year Member



your script really has loads of errors now im trying to find a open tag :P

dmmh

11:03 am on Oct 31, 2005 (gmt 0)

10+ Year Member



hey, I havent tested it in a live environment :p

dmmh

11:08 am on Oct 31, 2005 (gmt 0)

10+ Year Member



looks fine to me anyway.....whats the error?

dmmh

11:12 am on Oct 31, 2005 (gmt 0)

10+ Year Member



try changing $result = mysql_db_query("$Database",$query);

to

$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());

dunno if it helps tho, as I dont know the error :p

dmmh

11:16 am on Oct 31, 2005 (gmt 0)

10+ Year Member



and change: func_order_status($row['order_status_finance']);

to:

func_order_status_selector($row['order_status_finance']);

sorry :D

Twisted Mind

11:29 am on Oct 31, 2005 (gmt 0)

10+ Year Member



Why be sorry ur helping me :P

Twisted Mind

11:31 am on Oct 31, 2005 (gmt 0)

10+ Year Member



ATM i get no errors but it displays nothing either

dmmh

11:32 am on Oct 31, 2005 (gmt 0)

10+ Year Member



NOTHING at all?

Twisted Mind

11:33 am on Oct 31, 2005 (gmt 0)

10+ Year Member



oops my bad

dmmh

11:35 am on Oct 31, 2005 (gmt 0)

10+ Year Member



its working? :)

Twisted Mind

11:35 am on Oct 31, 2005 (gmt 0)

10+ Year Member



only welcome it confirmer :P
This 94 message thread spans 4 pages: 94