User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,397 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,648 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 648 | Replies: 12
Reply
Join Date: Nov 2007
Posts: 96
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

Help help in sql query

  #1  
Mar 4th, 2008
hi

i want to fetch username from another table based on the id generated in the temopary table.
 <?php
    @ $rpp;        //Records Per Page
    @ $cps;        //Current Page Starting row number
    @ $lps;        //Last Page Starting row number
    @ $a;        //will be used to print the starting row number that is shown in the page
    @ $b;         //will be used to print the ending row number that is shown in the page

  if(empty($_GET["cps"]))
    {          $cps = "0";          }
    else
    {          $cps = $_GET["cps"];      }
    $a = $cps+1;
    $rpp = "10";
    $lps = $cps - $rpp; //Calculating the starting row number for previous page
   if ($cps <> 0)
    {
        $prv =  "<a href='myagreement.php?cps=$lps"."&user1=".$_SESSION['employerid']."'>Previous</a>";
    }
    else   
    {
        $prv =  "<font color='cccccc'>Previous</font>";
    }
   mysql_query("DROP TABLE TEMPORARY IF EXISTS Mytemp");
   mysql_query("CREATE TEMPORARY TABLE Mytemp SELECT resumeid,ttdate,ttime from agreements WHERE buyerid='".$_SESSION['employerid']."' order by ttdate DESC");
   $q="Select SQL_CALC_FOUND_ROWS * from Mytemp limit $cps, $rpp ";
    $rs=mysql_query($q) or die(mysql_error());
    $nr = mysql_num_rows($rs); //Number of rows found with LIMIT in actiong r
    $q0="Select FOUND_ROWS()";
    $rs0=mysql_query($q0) or die(mysql_error());
    $row0=mysql_fetch_array($rs0);
    $nr0 = $row0["FOUND_ROWS()"]; //Number of rows found without LIMIT in action
    if (($nr0 < 10) || ($nr < 10))
    {
           $b = $nr0;     }
    else
    {
        $b = ($cps) + $rpp;     }
      ?>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="90%" align="center">
<tr><td><b><font face="verdana" size=2></b></font><b><font face="verdana" size=2 color="#9999CC"></font></b></td></tr>
  <tr><td align=left colspan="2"><b><font face="verdana" size=1 color="#9999CC"><? echo "$nr0 Records Found"; ?></font></b></td></tr>
  <tr><td align='left' colspan="2"><b><font face="verdana" size=1 color="#9999CC"><? echo "Showing Records from $a to $b"; ?></font></b></td></tr>
</tr>
    <?
$i=$nr0;
    while ($row=mysql_fetch_array($rs))
    {
         $cps = $cps +1;
$idd=$row[2];
 $result=mysql_query("SELECT username from login where username='.$idd.'");
  while ($line=mysql_fetch_array($result))
    {
  echo "<tr>";
echo "<td>";
echo "<table  bgcolor='#fefefe' width='73%'  align='center' border='0'>";
 echo "<tr><td width='55%'><font face='verdana' size=1><strong>Resume ID : </strong></font><a href='agreement1.php?agreeid=".$row[0]."'>RB".$row[0]."</td><td width='25%'><font face='verdana' size=1><strong>Agreement Signed With</strong></font>$line[0]</td></tr>";
echo "<tr><td width='25%'><font face='verdana' size=1><strong>Date  </strong></font>".$row[1]."</td><td width='25%'><font face='verdana' size=1><strong>Time  </strong></font>".$row[2]."</td></tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
  }
    echo "<tr><td align='right' colspan=2>$prv";
     if ($cps == $nr0)
    {         echo "  |  <font color='CCCCCC'>Next</font>";      }
    else
    {
        if ($nr0 > 5)
        {
            echo "  |  <a href='myagreement.php?cps=$cps&lps=$lps&user1=".$_SESSION['employerid']."'>Next</a>";
        }       }        ?>
Last edited by cscgal : Mar 4th, 2008 at 12:26 am. Reason: Code tags instead of ICode
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: Somewhere in Germany
Posts: 53
Reputation: JRSofty is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
JRSofty's Avatar
JRSofty JRSofty is offline Offline
Junior Poster in Training

Re: help in sql query

  #2  
Mar 5th, 2008
How about reposting that and removing all of the PHP and HTML and just post the SQL statements that you want to run along with a description of the originating table.

This might help us to determine what the problem with your particular SQL queries are.
Reply With Quote  
Join Date: Nov 2007
Posts: 96
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

Re: help in sql query

  #3  
Mar 5th, 2008
SELECT post_resume.res_title, post_resume.candidate_type, post_resume.owner, post_resume.ind_type, post_resume.career, post_resume.resume, employer.association
FROM post_resume, employer
WHERE post_resume.ind_type = '".$industype."'
AND post_resume.career = '".$careerlevel."'
AND employer.association = 'cg'
AND post_resume.owner != '18'
ORDER BY tdate DESC

sorry for posting all the codes in sql.i want something like the above query.when i tried executing the above query ...all the rows are getting displayed three time.............please do tell me the error
Reply With Quote  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: help in sql query

  #4  
Mar 5th, 2008
Use "GROUP BY" clause.
Reply With Quote  
Join Date: Nov 2007
Posts: 96
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

Re: help in sql query

  #5  
Mar 5th, 2008
i tried tat...it is showing error msg

SELECT post_resume.res_title, post_resume.candidate_type, post_resume.owner, post_resume.ind_type, post_resume.career, post_resume.resume, employer.association
FROM post_resume, employer
WHERE post_resume.ind_type = '".$industype."'
AND post_resume.career = '".$careerlevel."'
AND employer.association = 'cg'
AND post_resume.owner != '18'
ORDER BY tdate DESC group by employer.association
Reply With Quote  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: help in sql query

  #6  
Mar 5th, 2008
Originally Posted by kings View Post
i tried tat...it is showing error msg

SELECT post_resume.res_title, post_resume.candidate_type, post_resume.owner, post_resume.ind_type, post_resume.career, post_resume.resume, employer.association
FROM post_resume, employer
WHERE post_resume.ind_type = '".$industype."'
AND post_resume.career = '".$careerlevel."'
AND employer.association = 'cg'
AND post_resume.owner != '18'
ORDER BY tdate DESC group by employer.association


try:
SELECT post_resume.res_title, post_resume.candidate_type, post_resume.owner, post_resume.ind_type, post_resume.career, post_resume.resume, employer.association
FROM post_resume, employer
WHERE post_resume.ind_type = '".$industype."'
AND post_resume.career = '".$careerlevel."'
AND employer.association = 'cg'
AND post_resume.owner != '18'
GROUP BY employer.association
ORDER BY tdate DESC
Reply With Quote  
Join Date: Nov 2007
Posts: 96
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

Re: help in sql query

  #7  
Mar 5th, 2008
output
MySQL returned an empty result set (i.e. zero rows).
Reply With Quote  
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: help in sql query

  #8  
Mar 5th, 2008
U please check the query in PHP Myadmin wheather u r getting any values for ur query...
Reply With Quote  
Join Date: Nov 2007
Posts: 96
Reputation: kings is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster in Training

Re: help in sql query

  #9  
Mar 5th, 2008
ya i checked it in php myadmin only
Reply With Quote  
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: help in sql query

  #10  
Mar 5th, 2008
Try this by joining the tables using the INNER JOIN....

SELECT * FROM post_resume INNER JOIN employer
ON (post_resume.ind_type = '".$industype."'
AND post_resume.career = '".$careerlevel."'
AND employer.association = 'cg'
AND post_resume.owner != '18')
ORDER BY tdate DESC group by employer.association

Hope this will work!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC