Jump to content

Querying a table for elements extracted from an array in another table.


swatisonee

Recommended Posts

Hi,

I have 2 tables. A field, Customerid in Table 1 contains upto 3 numbers separated by commas. Each of these numbers corresponds to a customerid in Table 2.

I now need to list all records in Table 1 which answer a query on Table 2. I thought of using  JOIN but since customerid in Table 1 is VARCHAR but in Table 2 is autincrement, I guess it would not work.

I then thought of using in_array but its throwing up an error i cannot figure out - i just get a blank page.

Could someone please tell me what i should be doing to correct this ?

Thanks. Swati


[code]$sqlb=    "SELECT * FROM `VisitReport` WHERE  (( (MONTH(`Visited_Date`) >= 4) AND (YEAR(`Visited_Date`) = $year0) ) || ( (MONTH(`Visited_Date`) <= 3) AND (YEAR(`Visited_Date`) = $year1) ) ) ORDER BY `Company` asc ";

//echo $sqlb;

$resultb = mysql_query($sqlb);

if ($myrowb = mysql_fetch_array($resultb))
{
do
{

$cid = $myrowb["Customerid"];   
$cidArray = array_unique(explode(',', $cid));

$sqla = "SELECT * FROM `Customers_List` WHERE  ((`BusinessState` LIKE 'AZ') || (`Business State` LIKE 'PA') ) ";

$resulta = mysql_query($sqla);

if ($myrowa = mysql_fetch_array($resulta))

{
$csid = $myrowa["Customerid"];
// echo $csid;


if ( in_array( $csid, $cidArray ) )

{
printf("<tr>
<brS.No&nbsp;<font size=2 face=Tahoma>%d,

//  and so on

</tr>",

  $i,
$myrowa["Company"],
  calculatedate($myrowb["Visited_Date"])  // and so on
);
}

}

}
while ($myrowb = mysql_fetch_array($resultb));
} [/code]
Link to comment
Share on other sites

oh i did that in the original. Since i wasjust copying the snippet that was causing the probem, it must've got left out.

The critical error is in the following part i beleive but i dont know what it is .

Any ideas ?

Thanks. Swati

[code]$cidArray = array_unique(explode(',', $cid));

$sqla = "SELECT * FROM `Customers_List` WHERE  ((`BusinessState` LIKE 'AZ') || (`Business State` LIKE 'PA') ) ";

$resulta = mysql_query($sqla);

if ($myrowa = mysql_fetch_array($resulta))

{
$csid = $myrowa["Customerid"];
// echo $csid;


if ( in_array( $csid, $cidArray ) ) [/code]
Link to comment
Share on other sites

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.