Jump to content


Photo

**SOLVED** mysql table searching. harder a bit.


  • Please log in to reply
2 replies to this topic

#1 blazing_bruce

blazing_bruce
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationIndia

Posted 25 March 2006 - 08:21 PM

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.


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 26 March 2006 - 10:03 AM

Try

$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";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 blazing_bruce

blazing_bruce
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationIndia

Posted 26 March 2006 - 06:24 PM

Thank you Mr.Barand. your query is working now.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users