Inserting Multiple Data in the table

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
AaaDee
New php-forum User
New php-forum User
Posts: 25
Joined: Mon Jun 24, 2002 1:10 am
Location: Huddersfield
Contact:

Inserting Multiple Data in the table

Postby AaaDee » Tue Jul 23, 2002 6:17 am

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

User avatar
AaaDee
New php-forum User
New php-forum User
Posts: 25
Joined: Mon Jun 24, 2002 1:10 am
Location: Huddersfield
Contact:

Postby AaaDee » Wed Jul 24, 2002 12:39 am

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

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Wed Jul 24, 2002 10:53 pm

AaaDee wrote: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: Select all

$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:

User avatar
AaaDee
New php-forum User
New php-forum User
Posts: 25
Joined: Mon Jun 24, 2002 1:10 am
Location: Huddersfield
Contact:

Postby AaaDee » Mon Jul 29, 2002 1:31 am

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

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Mon Jul 29, 2002 5:18 am

AaaDee wrote: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


Return to “PHP coding => General”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest