Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 17th, 2003, 03:03 AM
casullian_454 casullian_454 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 1 casullian_454 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Inserting array data into MySQL database

I have following fields plus primary key ID field in my database

Symbol Price Date Time Change Open High Low Volume

I have following data stored in $data

Array ( [0] => Array ( [0] => RHAT [1] => 7.34 [2] => 7/16/2003 [3] => 3:59pm [4] => -0.35 [5] => 7.73 [6] => 7.80 [7] => 7.24 [8] => 1610487 ) [1] => Array ( [0] => MSFT [1] => 27.52 [2] => 7/16/2003 [3] => 4:00pm [4] => +0.25 [5] => 27.56 [6] => 27.62 [7] => 27.20 [8] => 50506828 ) [2] => Array ( [0] => INTC [1] => 25.31 [2] => 7/16/2003 [3] => 4:00pm [4] => +1.21 [5] => 25.24 [6] => 25.50 [7] => 24.82 [8] => 129156912 ) )

What is standard PHP method to insert these three records into my database?

Thanks Cas

Reply With Quote
  #2  
Old July 17th, 2003, 08:48 AM
SilkySmooth's Avatar
SilkySmooth SilkySmooth is offline
Newbie :P
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2001
Location: In the PHP Engine :-)
Posts: 2,880 SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 32 m 23 sec
Reputation Power: 15
If the data is always going to be accurate then you could do something like this:

PHP Code:
for ($a=0$a count of main array; $a++)
{
INSERT INTO table VALUES ('".$data[$a][0]."','".$data[$a][1]."','".$data[$a][2]."'.....etc



HTH
__________________
---------------------
-- SilkySmooth --
---------------------
Proxy | Little Directory

Reply With Quote
  #3  
Old October 9th, 2003, 04:46 AM
ante ante is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 ante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have a problem that I hope someone can help me with..
My code is like this (index.php file obtained from psychostats, running on a PHP-Nuke site, with Apache server, mysql)

<?php
if (!isset($mainfile)) { include("mainfile.php"); }
$index = 1;
include("header.php");
include("functions.php");
OpenTable();

// Make sure a valid sort was given
if (!preg_match('/^(name|totalkills|totaldeaths|kpm|kdr|skill)$/i',$sort))
$sort = 'skill';
$sort = strtolower($sort);

// Total names to list on a single page. Change this to whatever you want.
if (!preg_match('/^\d+$/', $limit)) $limit = 100;

// Nothing else below this line needs to be changed unless you want to
customize the layout
//
----------------------------------------------------------------------------------------

if (!preg_match('/^\d+$/', $start)) $start = 0;

$cell1 = 'plrrow1';
$cell2 = 'plrrow2';
$cell = '';


// Set the variables for the database access:
$host = "localhost";
$user = "user";
$password = "pass";
$dbname = "nuke";

$Link = mysql_connect ($host, $user, $password);

global $prefix;

$playerlist = array();
$playerlist[] = array(
"plrname" => stripslashes("\[TEST\]test"),
"plrhtml" => stripslashes("player_W01LQkldU2Fkbw\.php"),
"plrrank" => "4",
"plrskill" => "1345",
"plrtotalkills" => "433",
"plrtotaldeaths" => "293",
"plrkdr" => "1.48",
"plrkpm" => "0.69",
"plrwonids" => "",
"plraliases" => stripslashes("\[TEST\]test"),
"plricon" => stripslashes("player\.gif"),
"plrclanicon" => stripslashes("\<a\
href\=\'clanpage__test_\.php\'\>\<img\ src\=\'clan\.gif\'\ width\=\"18\"\
height\=\"14\"\ border\=\"0\"\ alt\=\"\[TEST\]\"\>\<\/a\>"),
); // [TEST]test

$Query = "INSERT INTO ".$prefix."_psychostats (rankid, pname, kills, deaths, kd, kpm, skill)
VALUES (".$playerlist['plrrank'].",".$playerlist['plrname'].",".$playerlist['plrtotalkills'].",".$playerlist['plrtotaldeaths'].",".$playerlist['plrkdr'].",".$playerlist['plrkpm'].",".$playerlist['plrskill'].)";


print ("$playerlist[plrrank]");
print ("The query is:<BR>$Query<p>\n");

if (mysql_db_query ($dbname, $Query, $Link)) {
print ("Your information has been updated =;0)<BR>\n");
} else {
print ("Your information has not been updated<BR>\n");
}
mysql_close ($Link);
?>

RESULT:

The $Query is showed in print, but no values just ('','',''.....)
Maybe its not possible to do it like this, anyway if u have some
suggestion they are greatly appriciated..

Plz help, Thanks,
Ante

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Inserting array data into MySQL database


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