Re: [PHP] PHP control structure

2011-07-14 Thread Richard Quadling
On 14 July 2011 05:15, Negin Nickparsa nickpa...@gmail.com wrote:
 if the problem is only the assigning it's an example:
 in mysql you can have this one:
 create table store_list(id_markets int auto_increment,store_type int,primary
 key(id_markets));

 and for page this one:

 html

 head
 titleStore/title
 /head
 form method=post
 ?php
 $connection=Mysql_connect('localhost','admin','123');
 Mysql_select_db('net',$connection);
 if(array_key_exists('sub',$_POST))
 if(isset($_POST['store_type']) )
 {
 $Type =$_POST['store_type'];
 $ID=$_POST['id'];
  $sql =update store_list set store_type=$Type where id_markets=$ID;
 $res = mysql_query($sql,$connection);
 }
 ?
 select name='store_type'
 option value=0store typeoption
 option value=1corporateoption
 option value=2standardoption
 /select
 ID:input type='text' name='id'
 input type='submit' name='sub' value='update the type'
 /form
 /html

 also I didn't understand your code that you have 'id_store' and 'id_markets'
 it's confusing for me

 if it wasn't your problem please clarify your question maybe I can help.


I'd do this in the SQL...


SELECT DISTINCT
store_type,
CASE store_type
WHEN 1 THEN 'Corporate'
WHEN 2 THEN 'Standard'
ELSE 'Unknown store_type ' + CAST(store_type AS VARCHAR())
END AS store_type_desc
FROM
store_list
WHERE
id_markets=$_POST[id];

Though for the text, I'd probably have a store_types table so I can
label them there and hold additional data about the store types if
needed.

SELECT DISTINCT
store_type,
COALESCE(store_type_desc, 'Unknown store_type ' + CAST(store_type AS
VARCHAR())) AS store_type_desc
FROM
store_list
LEFT OUTER JOIN
store_types ON store_list.store_type = store_types.store_type
WHERE
id_markets=$_POST[id];


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP control structure

2011-07-13 Thread Tamara Temple


On Jul 12, 2011, at 10:11 PM, Chris Stinemetz wrote:


Hey all,

I would like to add an if statement to the following function so that
the value 1 is assigned corporate and the value is 2 assign
standard to it.  Would you show me an example on adding it to the
below function? If there is a better way to reassign the value please
share.

Thank you,

Chris

public function ShowType()
{
$sql = SELECT DISTINCT store_type FROM store_list WHERE
id_markets=$_POST[id];
$res = mysql_query($sql,$this-conn);
$Type = 'option value=0store type.../option';
while($row = mysql_fetch_array($res))
{
$Type .= 'option value=' . $row['id_store'] . 
'' .
$row['store_type'] . '/option';
}
return $Type;
}

--  
PHP General Mailing List (http://www.php.net/)

To unsubscribe, visit: http://www.php.net/unsub.php



I'm really not at all clear what you want to do here. Where and how  
are the values going to be used? Where is it determined something is  
corporate or standard? What do these things mean in the context of  
your application?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP control structure

2011-07-13 Thread Negin Nickparsa
if the problem is only the assigning it's an example:
in mysql you can have this one:
create table store_list(id_markets int auto_increment,store_type int,primary
key(id_markets));

and for page this one:

html

head
titleStore/title
/head
form method=post
?php
$connection=Mysql_connect('localhost','admin','123');
Mysql_select_db('net',$connection);
if(array_key_exists('sub',$_POST))
if(isset($_POST['store_type']) )
{
$Type =$_POST['store_type'];
$ID=$_POST['id'];
  $sql =update store_list set store_type=$Type where id_markets=$ID;
$res = mysql_query($sql,$connection);
}
?
select name='store_type'
option value=0store typeoption
option value=1corporateoption
option value=2standardoption
/select
ID:input type='text' name='id'
input type='submit' name='sub' value='update the type'
/form
/html

also I didn't understand your code that you have 'id_store' and 'id_markets'
it's confusing for me

if it wasn't your problem please clarify your question maybe I can help.