Forum Moderators: coopster
$query = "INSERT INTO hardware (specifications) VALUES (".implode(",",$specifications).")";
If the values in the array are text values, you will need to add quotes
$query = "INSERT INTO hardware (specifications) VALUES ("'.implode("','",$specifications)."')";
mysql_query($query);
Also, if you don't want duplicate values, switch the "INTO" to "IGNORE" and only unique values will be inserted into the table.
Hope thats what youre asking for.
$query = mysql_query("SELECT specifications FROM hardware");
while($array = mysql_fetch_array($query,MYSQL_ASSOC)
{
echo $array['specifications'],'<br>';
}
This is querying the table for the results you inserted before, it should echo all the values in the DB under the 'specifications' field. Note "mysql fetch array", the function basically grabs the info from a db and puts it into an array.
$query = mysql_query("SELECT specifications FROM hardware");
while($array = mysql_fetch_array($query,MYSQL_ASSOC)
{
for loop here
echo $array['specifications'][$i],'<br>';
}
Given $i increments by one after each for loop.
[edited by: irock at 10:43 pm (utc) on Aug. 10, 2003]
Each result in mysql_fetch_array is an array in itself, i.e. all rows are their own array.
afaik, if you wanted to put them all back in the single array you could do this (maybe there's a better way?)
$array2 = array();
$query = mysql_query("SELECT specifications FROM hardware");
while($array = mysql_fetch_array($query,MYSQL_ASSOC)
{
array_push($array2,$array['specifications'];
}
print_r($array2);
That will end up with a single array with all the values (in order) retrieved from your table.
Storing array into mysql...
$value = addslashes(serialize($array));
$query = "INSERT INTO table (column) VALUES (\"$value\")"
and upon retrieval
$query = "SELECT column FROM table";
......
while($row = mysql_fetch_array($result)) {
$value = unserialize(stripslashes($row["column"]));
}
How does this compare to yours?
Thanks again... much appreciated your help!