Inserting Multiple Data in the table

A

Anonymous

Guest
Hi, ive RTFM and all over the web all morning and early afternoon.

I am having difficulties.

Is it possible to Insert multiple data into a database table at one time?

an example

two columns

Beckham Man UTD
Owen Liverpool
Henry Arsenal

Thats what my page looks like.

I want to insert all three of them lines into the database in one table.

But all it does at the moment is inserts

Henry Arsenal

it does the last line all the time.

Pweese Help

Thanks Very Much

Adam
 
Because i am getting the details from the database, this makes my problem a little bit difficult.

On the page where it displays, Beckham Man UTD, Owen Liverpool, Henry Arsenal. It doesnt actually say there names,

the code is
echo "
<tr>
<td>Player</td>
<td>Club</td>
</tr>";

while ( $row = mysql_fetch_array( $sql_result ) )

{

$player = $row["player"];
$club = $row["club"];

echo "

<tr>
<td>$player</td>
<td>$club</td>
</tr>";

So this get all the players and clubs in the database. So i dont actually say player club three times, just once.

im looking for something like

if $num_rows = number of rows in DB

then insert * into table

How would i go about this please.

Cheers
 
AaaDee said:
Because i am getting the details from the database, this makes my problem a little bit difficult.

On the page where it displays, Beckham Man UTD, Owen Liverpool, Henry Arsenal. It doesnt actually say there names,

the code is
echo "
<tr>
<td>Player</td>
<td>Club</td>
</tr>";

while ( $row = mysql_fetch_array( $sql_result ) )

{

$player = $row["player"];
$club = $row["club"];

echo "

<tr>
<td>$player</td>
<td>$club</td>
</tr>";

So this get all the players and clubs in the database. So i dont actually say player club three times, just once.

im looking for something like

if $num_rows = number of rows in DB

then insert * into table

How would i go about this please.

Cheers
Hello my young little friend!
I'm propose you create function what will be do some operations with array, something like that:
Code:
$str_array = array("Beckham"-> "Man UTD", "Owen" -> "Liverpool", "Henry" -> "Arsenal");

# SQL add/remove function
function do_sql($str_array, $actions)
$count_act = count($str_array);
if ($action == "add")
{
 for ($i=0 $i=>$count_act $i++)
      {
      [i]actions for add value and key to DB[/i]
      }
}
elseif ($action == "remove"
{
[i]I think that you understand that need to do[/i]
}

Try in next time use function for simlify your code. It's easy. Good luck!
:wink:
 
Hiya mate.

Sorry, i kind of messed the first msg up, because i gave the impression that the results was hardcoded in.

But the code is

while ( $row = mysql_fetch_array( $sql_result ) )

{

$player = $row["player"];
$club = $row["club"];

echo "

<tr>
<td>$player</td>
<td>$club</td>
</tr>";


I get what you mean for the array, and have tried it on hardcoded results, which works (thank you)

but how will i able to set the arrays like

$str_array = array("$player"-> "$club");

Is it impossible to so, so it adds all the results, and doesnt overwrite the data like it looks to be doing at the moment!

Adam
 
AaaDee said:
Hiya mate.

Sorry, i kind of messed the first msg up, because i gave the impression that the results was hardcoded in.

But the code is

while ( $row = mysql_fetch_array( $sql_result ) )

{

$player = $row["player"];
$club = $row["club"];

echo "

<tr>
<td>$player</td>
<td>$club</td>
</tr>";


I get what you mean for the array, and have tried it on hardcoded results, which works (thank you)

but how will i able to set the arrays like

$str_array = array("$player"-> "$club");

Is it impossible to so, so it adds all the results, and doesnt overwrite the data like it looks to be doing at the moment!

Adam
Blin Adam why you not want just think.
Read next: http://www.php.net/manual/en/function.array.php carefuly
 
Back
Top