Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 need help entry database

Author  Topic 

loveblue
Starting Member

1 Post

Posted - 2009-04-03 : 02:55:55
hai .... I need help .....
I have a database table "device" and "event".
column table "device" content "account" and "dev_id".
while in table "event" content "account", "dev_id" and "event".

table in the "device" I have the following data:
"account" "dev_id"
demo red_car
demo blue_car
admin red_car

I want to insert data to table "event". if there is data entry with "dev_id" blue_car, the data insert to the table there are no problems. the problem appears when there is equality that is "dev_id" red_car because both dev_id are owned by the demo and admin accounts.

I want to ask for assistance on how to enter data to the table "event" occurs when conditions such as the above there are similarities "dev_id" red_car. so that data entered is complete all that is

"account" "dev_id" "event"
demo red_car stop
admin red_car stop

here is my php

<?
//conn1--------------------------------------------------------------------------------------------------------
$host1="localhost";
$user1="root";
$pass1="xxxx";
$conn1 = mysql_connect("$host1","$user1","$pass1");
mysql_select_db("tes", $conn1);

$query_id = "select account from device where dev_id = '$vehicle_id'";
$jawab = mysql_query($query_id,$conn1);
while ($row_id = mysql_fetch_array($jawab)) {
$accid = $row_id['account'];
}

//insert----------------------------------------------------------------------

$sql = "INSERT INTO event(account,dev_id,event) VALUES (";
$sql .= "'". addslashes($accid) . "'";
$sql .= ",'" . addslashes($vehicle_id) . "'";
$sql .= ",'" . addslashes($event) . "'";
$sql .= ");";
echo "Data insertion \r\n".$sql;
mysql_query($sql,$conn1);

--------------------------------------

I use php socket to receive the data. data processed and entered into the database.
at the time of entering into the database that what I want to ask. when data is selected in the query there are 2 or more how to enter the database.
$query_id = "select account from device where dev_id = '$vehicle_id'";

here is what i'v got from the dump

string(52) "select account from device where dev_id = 'red_car'"
string(5) "admin"
string(4) "demo"

Data insertion INSERT INTO event(account,dev_id,event) VALUES ('demo','red_car','stop')

only one data inserted....account demo.
i need admin account is inserted with data to

thank you very much

really need help

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-04 : 07:19:27
Are you using SQL Server or Mysql?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -