Jump to content

Retriving data from two tables


belmon

Recommended Posts

Hi

 

I have two tables.

The first one "services" contains the services

service_id = 1

service = service_one

service_id = 2

service = service_two

an so on

 

In the other table "orders", I've stored the services that clients have ordered:

order_id = 1

server_id = 1

client_id = 54

 

order_id = 2

service_id = 1

client_id = 54

 

and so on

 

I retrived the posts, already ordered and placed in the table "orders"

So far I have come.

<?php

$ordered = mysql_query("SELECT * FROM services, orders

WHERE

services.service_id = orders.service_id AND

orders.client_id = '".$_GET['id']."' ");

while ($order = mysql_fetch_array($ordered))

{

echo ' <tr>';

echo ' <td>';

 

echo ''.$order['service'].'</td>';

echo ' <td><input type="checkbox"';

if ($order['service_id'] != 0)

{

echo 'checked = "checked"';

}

echo 'name="service" value="'.$order['service_id'].'"></td>';

echo ' </tr>';

}

 

 

What I need is to retrive a COMPLETE LIST of the services in which the already ordered posts are checked in the checkboxes

(I have modified the code to simplify my question)

Thanks for any assistance

Link to comment
https://forums.phpfreaks.com/topic/273509-retriving-data-from-two-tables/
Share on other sites

Give the checkboxes name="service[]" so they are posted as an array.

 

To process

 

if (isset($_POST['service'])) {
   $servList = join (',', array_map('intval', $_POST['service']));
   $sql = "SELECT service FROM services
    WHERE service_id IN ($servList)";
   // process query
}

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.