Jump to content

how can I inster Database


erdem

Recommended Posts

Hi, I'm trying to insert some data to mysql database.

 

but I don't know what the MySQL structure should be and how to write it.

 

 

this is html output.

 

thanks so much.

 

Player name -

Race Color -

Team -

Average APM -

Winner?

Mike

Zerg

Red

Team 1

156

1 (win)

WinD

Zerg

Blue

Team 2

163

0 (lose)

 

and this is the code.

 

$obsString = "";
			$obsCount = 0;
			echo "<table border=\"1\"><tr><th>Player name</th><th>Race</th><th>Color</th><th>Team</th><th>Average APM<br />(experimental)</th><th>Winner?</th></tr>\n";
			foreach($players as $value) {
				if ($value['isObs']) {
					if ($obsString == "")
						$obsString = $value['name'];
					else
						$obsString .= ', '.$value['name'];
					$obsCount++;
					continue;
				}
				if ($b->isWinnerKnown())
					$wincolor = (isset($value['won']) && $value['won'] == 1)?0x00FF00:0xFF0000;
				else
					$wincolor = 0xFFFFFF;
				if ($value['isComp'] && $b->getTeamSize() !== null)
					$difficultyString = sprintf(" (%s)",SC2Replay::$difficultyLevels[$value['difficulty']]);
				else
					$difficultyString = "";
				echo sprintf("<tr><td>%s</td><td>%s</td><td><font color=\"#%s\">%s</font></td><td>%s</td><td style=\"text-align: center\">%d</td><td style=\"background-color: #%06X; text-align: center\">%d</td></tr>\n",
								$value['name'].$difficultyString,
								$value['race'],
								$value['color'],
								$value['sColor'],
								($value['team'] > 0)?"Team ".$value['team']:"-",
								($value['team'] > 0)?(round($value['apmtotal'] / ($b->getGameLength() / 60))):0,
								((isset($value['won']))?$wincolor:0xFFFFFF),
								(isset($value['won']))?$value['won']($value['team'] > 0)?"Unknown":"-")
							);
			}
			echo "</table><br />";
			if ($obsCount > 0) {
				echo "Observers ($obsCount): $obsString<br />\n";
			}

Link to comment
https://forums.phpfreaks.com/topic/256330-how-can-i-inster-database/
Share on other sites

here's what i did:

$entry would be your array, with all of your info. this foreach will split that into key value pairs, and then format them as an SQL query, and finally it will insert.

 

<?php

foreach ($entry as $key=>$value){
if ($value != '' && $value != 'Submit'){
$cols .= mysql_real_escape_string($key). ', ';
$vals .= '\''. mysql_real_escape_string($value). '\', ';
}
}

$columns = substr($cols,0,-2); // trim trailing "'," , 
$values = substr($vals,0,-2);

$sql="INSERT INTO table ( $columns )VALUES ( $values )";

 

i'm sure there are other ways to handle the trailing "',", but this works for me :)

*** EDIT post above seems to cover it better than i did :) ***

 

 

first thing would be to create a database, and then in that database you would need a table with columns with names like the ones in the array.

A unique identifier which is usually called id or perhaps in this case call it player_id, have it auto increment and as a primary key.

then have other columns, use the <th> values as a guide to what you need.

once you have this table ready you can go about setting up a database connection and sql statement to insert the data into the table on the database

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.