Jump to content

Recommended Posts

hello all,
i have a table named rest

RID CID
1 | 2
1 | 3
1 | 4
2 | 2
2 | 3
3 | 2
3 | 4
4 | 2
4 | 3
i want to list records which accepts the cards (CID).

first i have 4 check boxes in search.php

for($i=1;$i<=$total_cards;$i++)
{
$fetch = mysql_fetch_row($pass_cards);
$id=$fetch[0];
$name = $fetch[1];
echo("<input type='checkbox' name='card[]' value='$id' />$name");
}

in list.php
i want to show the list of records based on check box's value

getting post values by
$checked = $HTTP_POST_VARS['card'];

now i want to list all the records which having all the CID values.

if i checking the check box 2 and 3 (which is CID)
then list.php will show 1,2,4 (RID)

i have tried in many ways, but no use.

this is wil be a simple MySQL query. please help me.
Link to comment
https://forums.phpfreaks.com/topic/5802-solved-mysql-table-searching-harder-a-bit/
Share on other sites

Try

[code]$cardList = join (',' , $_POST['card']);
$k = count($_POST['card']);

$sql = "SELECT RID, COUNT(*) as reccount
           FROM rest
           WHERE CID IN ($cardList)
           GROUP BY RID
           HAVING reccount = $k";[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.