TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   hwo to select forgin key to insert to another table (http://www.talkphp.com/absolute-beginners/5882-hwo-select-forgin-key-insert-another-table.html)

destroyerx15 06-02-2011 10:00 PM

hwo to select forgin key to insert to another table
 
hi guys
im beginner in php


i have another question

how to insert foreign key to another table to insert

i use like this for my form that have staff_id and password

my form of login :

<form action="2.php" method="post">
staff_id : <input type="text" name="staff_id" />
STAFF_PASSWORD: <input type="text" name="STAFF_PASSWORD" />
<input type="submit" name="login" value="login"/>
</form>

and for php

i use like this :


Welcome <?php echo $_POST["staff_id"];
include("config.php");

$result = mysql_query("SELECT staff_id FROM orders WHERE staff_id=('SELECT staff_id FROM staffs ')");



?>
<table class="table">
<form action="11.php" method="post">
<tr>


<th class="th">ORDER_DESC </th>

</tr>
<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="CSF"/> CSF </td>
</tr>

<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="LFT"/> LFT </td>
</tr>

<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="RFR"/> RFR </td>
</tr>


<tr>
<td class="td"><input type="checkbox" name="checkbox[]" value="TFT"/> TFT </td>
</tr>

<tr>
<td class="td" ><input type="submit" value="Submit" name="Submit"/>
</td>
</tr>
</form>
</table>

i using nested select but no relation between two db so i have table called orders that have staff_id is forign key

can any help and tnx for solving my problem

tony 06-03-2011 01:21 AM

I don't seem to understand your problem, but I am guessing you want all the orders that have a staff_id that exists in the staffs table. If that is the case, you can do a left join:

SQL Code:
SELECT orders.staff_id
FROM orders
LEFT JOIN staffs ON orders.staff_id = staffs.staff_id

destroyerx15 06-03-2011 01:36 AM

not work the left join

mjwalsh 06-12-2011 07:48 AM

Can you try to explain your issue a little more?


All times are GMT. The time now is 12:33 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0