Forum Moderators: coopster
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>
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)
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...*/
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;
}
<?
/************************************
**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>";
?>
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> </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> </td>
</tr>
<? }?>
</table>