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

Twisted Mind

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

10+ Year Member



no the error i posted $query = $query was my bad

dmmh

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

10+ Year Member



also change the other query to : $result = mysql_query($query) or die ("Error in query: $query " . mysql_error());

should do the trick :)

Twisted Mind

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

10+ Year Member



there is something from your script i commented cuz when i uncomment all i see 1 field again :P

Twisted Mind

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

10+ Year Member



the mysql error only displays errrors :p and u get unexplained errors without the mysql_error

dmmh

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

10+ Year Member



yes there are some minor errors hehe. like the closing </form> tag, move it to after <? }?> :)

but the rest should be ok, I really dont see anything terribly wrong.....

Twisted Mind

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

10+ Year Member



k i got your script only working now but it still does the same ... only shows first record of db
and says:

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

dmmh

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

10+ Year Member



the mysql error only displays errrors :p and u get unexplained errors without the mysql_error

ofcourse, thats why it is there....
if the script reports an error why dont you fix it?
leaving it out will not fix the error.....

Twisted Mind

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

10+ Year Member



sorry still one field...

Twisted Mind

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

10+ Year Member



i sayed it dind gave an error :)

dmmh

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

10+ Year Member



ah. dont understand why there is only one field
and dont understand the reason of the error 'undefined variable'.... :(

Twisted Mind

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

10+ Year Member



Anyway i did put it in my script but i still get this error Notice: Undefined variable: order_status_selector in D:\Fluke_Mambo\components\com_confirmation\order_status_finance.php on line 77
so there must be something wrong in the function or is it supposed to do this?

Twisted Mind

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

10+ Year Member



i suppose u want me to get this out of the function?

$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);}

then it displays nothing again

dmmh

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

10+ Year Member



no, there must be an error in the function, but I just cant find it....

dmmh

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

10+ Year Member



try it like 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;
}

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";

$query = "SELECT name, username, country FROM $usertable WHERE username = '$my->username'";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
while(list($name,$username,$country) = mysql_fetch_row($result)){
echo "Welcome $name<br><br>"
$mycountry = $country;
;}?>
<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_query($query) or die ("Error in query: $query " . mysql_error());?>

<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></td>
<td><? echo $row['order_id'];?></td>
</tr>
<tr>
<td><strong>current status:</strong></td>
<td><? echo $row['order_status_finance'];?></td>
</tr>
<tr>
<td><? echo func_order_status_selector($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>
<form action="components/com_confirmation/billing_shipping_info.php" target="_new" name="info_order_id" >
<tr>
<td>
<input name="id" type="hidden" value="<? echo $row['order_id'];?>">
<input type="submit" value="order <? echo $order_id info;?>" action="submit" class="button">
</td>
<td>&nbsp;</td>
</tr>
<? }?>
</form>
</table>

Twisted Mind

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

10+ Year Member



--

dmmh

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

10+ Year Member



:(

Twisted Mind

12:04 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



the -- was becouse i made an error in my post i get this error now :S but it is in the form so i dont know what is wrong here ...

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\Fluke_Mambo\components\com_confirmation\order_status_finance.php on line 86

Twisted Mind

12:10 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



is wich i get now

Fatal error: Cannot redeclare func_order_status_selector() (previously declared in D:\Fluke_Mambo\components\com_confirmation\order_status_finance.php:2) in D:\Fluke_Mambo\includes\functions.php on line 26

dmmh

12:20 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



ah, remove the entire function out of the script I posted before, didnt realise you had actually made a include file to hold the function :)

you can only declare a function once and since it now is in a include AND inside the script, there error will show

Twisted Mind

12:23 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



nou kan ie de database niet vinden

wups well it cant find the database now but there is nothing asking for it in the script

Twisted Mind

12:26 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



Error in query: SELECT name, username, country FROM mos_users WHERE username = 'fconf' No database selected

is the error

dmmh

12:29 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



I hope inside the connect.php file there is something like:

<? @ $db = mysql_connect('localhost', 'mysql_user_name', 'mysql_user_password');?>

Twisted Mind

12:31 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



ehh i thought i had

Twisted Mind

12:32 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



it does but the database never gets defined in the whole script

dmmh

12:33 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



no need to, it should connect to the database when you include the file with require() and will keep continuing to use this database until you specify otherwise

Twisted Mind

12:35 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



Well my database name is fluke variable is $Database... but doesnt it need to be in the script becouse the connection is host user and pw...

dmmh

12:36 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



you are right, I forgot it hahaha

do a
@mysql_select_db('fluke');

somewhere at the beginning hehehe

dmmh

12:37 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



was mixing up selecting table and selecting database hehe

Twisted Mind

12:37 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



whoohoo i got something right :P

Twisted Mind

12:38 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



Dude it works!
This 94 message thread spans 4 pages: 94