how to put data from database directly to array?
how to put data from database directly to array? for example i will get a data from my database like this "a,b,c,d" is there a way of putting the data in the array without looping? because what i did is i use substr() function and one by one i put it to array and the " , " is my sign that the data should be put to array.
just like this
for ($ctr=0; $ctr<=strlen($string); ++$ctr)
if ( $tmpStorage!=",")
$ExplodedString=$ExplodedString . $tmpStorage;
=>a for $array
=>b for $array
=>c for $array
=>d for $array
if there any other way to do this that will make the program more faster, because my program is more on parsings. pls share your knowledge. thanks in advance...
Umm if you use a MySQL database you can utilize functions like mysql_fetch_row...
So all you would do is have:
print_r will show you your array...
$query = "SELECT * FROM table";
$result = mysql_query($query);
$array = mysql_fetch_row($result);
thanks for reply.. yes im using mysql and that how i also query my data from database.. what i mean is.. for example the data in my data base is like this " a,b,c,d " and that data is only in one field or line of database and when i get that data from database it should directly put or store in array.. print_r is just like print right? and when i get have it in array that data can be use many times inside the program...
oh okay I see what you mean.... your data is stored as "a,b,c,d" in the database field.
you can just use explode I think?
Then you can see the content of the array using print_r again - it just allows you to look at the content of the array (for debugging really) and then you can access it like $array, $array etc.
$dataField = "a,b,c,d";
$array = explode(",", $dataField);
Is this making sense to you?
Last edited by smickus; 12-30-2007 at 12:32 PM.
Reason: error in code!
yeah.. thats what i want.. thank you very much smickus.. this is just a simply function but its really help me a lot and work my system fast... thanks again...
yeah explode is very handy! good luck with it...
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)