Jump to content

mysql problem


srinivas6203

Recommended Posts

Hi

 

i am using php and mysql.

I want display total records cmpared on accountcode.

The accountcode was getting from some table.

The records are getting from another table with compare of accountcode.

But there are so many accountcodes like 9000,9001,9002 etc.

But the records are displayed only with use of single value (ex:9000 or 9001 etc)

My code is as follows

 

$sql_gcode=mysql_query("select * from table1 where uid='".$row_uid."' and tech='gtalk'");

while($row_gcode=mysql_fetch_array($sql_gcode)) {

$user_gcode=$row_gcode['accountcode'];

}

 

$sql_gtalk=mysql_query("select * from table2 where accountcode='".$user_gcode."'");

while($row_gtalk=mysql_fetch_array($sql_gtalk))

{

echo '<tr bgcolor="#cddeff"><td>'.$row_gtalk['id'].'</td><td>'.$row_gtalk['accountcode'].'</td><td>'.$row_gtalk['date_created'].'</td> </tr>';

}

 

the accountcode's are 9000,9001,9002 etc are stored in $user_gcode.

 

But the records are displayed only for single accountcode like (where accountcode='9000').

 

Cn anyone help me out.

 

thanx in advance.

Link to comment
Share on other sites

The reason that the records are only displayed for one of the codes is that the only thing that occurs in the first loop is the setting of the variable. Each time the loop runs, that variable gets overwritten, so when the next query is made only the last value for the code is used.

 

However, you dont need two queries anyway, you can just use a join. Something like this should work:

 

<?php
$sql = "SELECT table1.accountcode,table2.id,table2.date_created FROM table1,table2 WHERE table1.accountcode=table2.accountcode AND table1.uid='$row_uid' AND tech='gtalk'";
$result = mysql_query($sql) or die(mysql_error());
while(list($code,$id,$date) = mysql_fetch_row($result){
echo '<tr><td>'.$id.'</td><td>'.$code.'</td><td>'.$date.'</td></tr>'."\n";
}
?>

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.