PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 13th, 2005, 09:42 PM
Dulcinea Dulcinea is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 23 Dulcinea User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 49 sec
Reputation Power: 0
Send a message via Yahoo to Dulcinea
Exclamation Array in PHP and MySQL

I have a problem in retrieving array in php from MySQL database.


<?php

$host='localhost';
$database='npi';
$password='';
$username='root';

$connect=mysql_connect($host, $username, $password);

mysql_select_db($database);

$colors=serialize($_POST['colors']); //takes the data from a post operation...
$name=$_POST['name'];

//$query = "INSERT INTO colors VALUES('".$colors."','".$name."') ";
$size = sizeof($colors);
//$result=mysql_query($query, $connect) or die ("Cannot execute 1");



for($c = 0; $c < sizeof($colors); $c++) {

$query = "INSERT INTO colors VALUES('".$colors."','".$name."') ";
$result = mysql_query($query) or die(mysql_error());
}


$query2="SELECT Color FROM Colors WHERE Name = '$name' ";
$result2=mysql_query($query2, $connect) or die ("Cannot execute 2");

$numrows=mysql_num_rows($result2);

if($result2){
while($my_colors=mysql_fetch_array($result2))
{
$my_colors=unserialize($colors);
print "<table border=\"1\">";
foreach($my_colors as $shirt)
{
print "<tr><td>$shirt</td><tr>";
}
}
print " and $name";
}
else
{
print 'No colors in database.';
}



?>

I run the code successfully. But my problem is:

$my_colors=unserialize($colors); <<--- I can do this if $colors was in the same page where I can serialize and unserialize;

But if I want to retrieve from database where there is no $colors at the same page, how can I write the code?

More addition, how can I actually retrieve an array from MySQL database? Can u explain and give example how can i wrote the code?
Can u give me any useful links?

another question:

what should i do if i wrote this code(for instance):

$my_colors=unserialize($colors);

the output is array instead of
a:2:{i:0;s:3:"SPD";i:1;s:4:"SPD2";}

what should i do to ensure that i just display SPD and SPD2 instead of array or
a:2:{i:0;s:3:"SPD";i:1;s:4:"SPD2";}.

Help2!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Array in PHP and MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT