473,511 Members | 11,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to output data from array?

26 New Member
Hi,

I am new for php. I don't know.... what to do? but i try to get data using "foreach($data as $key => $value), but i got error message "Warning: Invalid argument supplied for foreach()"

my code is below
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT meta_aps FROM sgc where nric = 'S9214548D'";
  2.  
  3.     $result = mysql_query($query) or die (mysql_error());
  4.  
  5.     $num = mysql_numrows($result);
  6.  
  7.  
  8.  
  9.         for ($i = 0; $i < $num; $i++) {
  10.  
  11.         $extra = mysql_result($result,$i);
  12.  
  13.     $serializedData = $extra;
  14.  
  15.     $data = @unserialize($serializedData);
  16.  
  17.     foreach($data as $key => $value){
  18.         print_r($value);
  19.  
  20.     }
  21. //print_r ($data);
  22. echo '<br>';
  23.  
  24.   }
  25.  
i got the output
Expand|Select|Wrap|Line Numbers
  1. Array ( [carer] => Soh Man was a student of (APS) from Jan 2007- Nov 2010 During her time in school, Soh Man managed to demonstrate care for her fellow classmates. She often took the initiative to help new students; she is a member of Boys Scout and was the class monitor. [story] => She has demonstrated her commitment and particicationable by carrying out tasks assigned to her diligently and responsibly. [other] => She adapts very well to unfamiliar environment easily. She is an honest and reliable person. ) 
  2.  
But i want to display the output like below. pls help
Carer:
Soh Man was a student of (APS) from Jan 2007- Nov 2010 During her time in school, Soh Man managed to demonstrate care for her fellow classmates. She often took the initiative to help new students; she is a member of Boys Scout and was the class monitor.
Story:
She has demonstrated her commitment and particicationable by carrying out tasks assigned to her diligently and responsibly.
Others:
She adapts very well to unfamiliar environment easily. She is an honest and reliable person.
Mar 2 '11 #1
1 1217
Niheel
2,456 Recognized Expert Moderator Top Contributor
So you've managed to get your data into an array.

To output it in the format you requested all you need to do is output different array variables.

In your case simple code like this:
Expand|Select|Wrap|Line Numbers
  1. ?>
  2. Career:
  3. <?=data["carer"]?>
  4.  
  5. Story:
  6. <?=$data["story"]?>
  7.  
  8. Others:
  9. <?=data["others"]?>
  10.  
  11. <?php
  12.  
Mar 2 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
12220
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after...
1
7830
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
0
6454
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
3
6593
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
8
6512
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and...
2
5016
by: Salad | last post by:
I have a log file with a list of records. The log file can be unfiltered or filtered. I have a command button to call a data entry form from the log. At first I was only going to present the...
2
2476
by: Mike Sweetman | last post by:
I have a form Form1 which when the Advanced Filter/Sort is used creates a form(maybe) with a title 'Form1Filter1 : Filter'. When I apply the filter to Form1 it is applied, but the value of...
8
6060
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
15
2565
by: Briansmi1116 | last post by:
I created two buttons, that filter my form, They filter in different Fields, and if one is filtered, and the other is not there is a certain amount of record, if they are both pushed, then there is...
4
8575
by: kcropper | last post by:
Hi, I’ve been trolling these forums for a while now, and while I’ve found other related threads (e.g., http://bytes.com/topic/access/answers/702416-search-code-how-filter-using-code-sql), nothing has...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.