Forum Moderators: coopster
I have a script to submit some values into my DB...
the variable type is dynamic as shown below....
how can I get all types in an array in order to store them in one field afterwards?
/////////////////////////////////////////////////
$location = htmlspecialchars($HTTP_POST_VARS['location']);
$town = htmlspecialchars($HTTP_POST_VARS['town']);
$name = htmlspecialchars($HTTP_POST_VARS['name']);
$category = htmlspecialchars($HTTP_POST_VARS['category']);
//////////////////////////////
$Querytype = "select * from Type";
$resulttype = mysql_query($Querytype);
$timestype = mysql_num_rows($resulttype);
$i = 1;
while ($i <= $timestype)
{
$type {"$i"}= $HTTP_POST_VARS['type{"$i"}'];
$i++;
};
////////////////////////////////////////////////////////
echo $location;
echo '<br>';
echo $town;
echo '<br>';
echo $name;
echo '<br>';
echo $category;
echo '<br>';
////////////////////////////////////
$y = 1;
while ($y <= $timestype)
{
echo ${"type$y"};
$y++;
};
thx in advance guys...hope u can help me
Nothing is going wrong....I think I wasnt so clear..I am sorry...
////this part get the dynamic variables from the form//////
$Querytype = "select * from Type";
$resulttype = mysql_query($Querytype);
$timestype = mysql_num_rows($resulttype);
$i = 1;
while ($i <= $timestype)
{
$type {"$i"}= $HTTP_POST_VARS['type{"$i"}'];
$i++;
};
////////////////////////////////////////////
and this one is just for testing to display (by echoing) if types are passed to the page///
$y = 1;
while ($y <= $timestype)
{
echo ${"type$y"};
$y++;
};
////
all types are passed and displayed...everything ok...HOWEVER..... how can I store them in a database? .....getting all these dynamic and unpredictable types in one field?might be only one type ($type1) or even 10 ($type1, $type2, ....., $type10)
I need to put them in an array (meybe?) or in a variable $types_all in order to store them in my database field TYPE.......
I need to store them like that ($type1, $type2, ....., $type10)
If I am not clear again plz tell me....
Types are dynamically created by my admin menu...so everytime I want to add an accommodation to my system I have to declare what the type is...soo I have checkboxes for that reason in my form...like:
[] Hotel
[] Apartments
[] Studio etc....all these are not standard but dynamic...so when form is submitted i have to request them by $HTTP_POST_VARS.......as these are not standard I use this type of code to get them:
///////////////////
$Querytype = "select * from Type";
$resulttype = mysql_query($Querytype);
$timestype = mysql_num_rows($resulttype);
$i = 1;
while ($i <= $timestype)
{
$type {"$i"}= $HTTP_POST_VARS['type{"$i"}'];
$i++;
};
//////////////////
it works fine....when I echo them ////
$y = 1;
while ($y <= $timestype)
{
echo ${"type$y"};
$y++;
};
///////////
I get:
HotelApartmentStudio etc....
but in order to store them in one field within the DB (Field called 'type') I need to put all these in an array or something else in ordert to store them like:
Hotel, Apartment, Studio ....and so on and so forth
is there a way to map them all ${"type$y"} in one array?while looping?this is my problemmm
you create an array here
$type {"$i"}= $HTTP_POST_VARS['type{"$i"}'];
before you insert you could implode [php.net] them using a delimiter. Yourt delimiter could be as simple as a comma or as complicated as a combination of three strange chars, whatever, I can't decide a delimiter for someone else.
Then when the data is selected you can explode [php.net] on that same delimiter.