Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

displaying just the data from an array

Featured Replies

I have an array stored in my_sql using serialize, makes a messy string in my database.

I use unserialize to turn back into an array.

 

how do i display JUST the data stored inside the array??

 

This is all i can work out to display;

 

a:2:{i:0;s:5:"white";i:1;s:5:"black";}

 

Or

 

Array

(

[0] => white

[1] => black

[2] => red

[3] => blue

)

 

all i want to display is just the colours like this:

 

white, black, red, blue

 

could some one point me in the correct direction as i cant find it anyware?

 

Thank you in advance!

 

Leah

Hi Leah,

 

What programming language are you using?

 

Rob

Serialzing data for MYSQL is great. We use this method for forms. Here's how you can get your data out... I'll comment it so you know what is going on...

 

$query="SELECT * FROM colours";  // change the 'colours' to the table you have your array in
$result=mysql_query($query); // perform the query
$numrows=mysql_num_rows($result); // count how many results returned...
if($numrows>0) // and if there's anything in the table, process it
{
while($colours_list=mysql_fetch_array($result)) // This loop checks for multiple sets of colours
 {
 $colours_set=unserialize($colours_list['colours']); // Unserailize the 'set' of colours

 foreach($colours_set as $single_colour) // This loop sorts one at a time each colour from the unserialized array
  {
  print $single_colour.', '; // prints the colour name, followed by a comma. 
  } // end of 'for each' loop
 } // end of 'while' loop
} // end of 'if numrows>0' loop if it's true
else
{
print 'That table's empty!'; // Display a message that the table is empty
} // end of 'if numrows>0' loop if it was false

 

Hope that makes sense!

  • Author

I get an error here;

 

foreach($colors_set as $single_colour)

 

Warning: Invalid argument supplied for foreach() in /home/lingerie/public_html/new/admin/list.php on line 48

 

I haven't been able to use the "foreach($ as $ )" command as it gives me errors every time i try to use it?

I get an error here;

 

foreach($colors_set as $single_colour)

 

Warning: Invalid argument supplied for foreach() in /home/lingerie/public_html/new/admin/list.php on line 48

 

I haven't been able to use the "foreach($ as $ )" command as it gives me errors every time i try to use it?

 

 

What PHP version are you using?

 

Foreach has been around since version 4. You may be able to subsitute a "while/each" loop for the foreach.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.