help in sql query

Reply

Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

help in sql query

 
0
  #1
Mar 4th, 2008
hi

i want to fetch username from another table based on the id generated in the temopary table.
  1. <?php
  2. @ $rpp; //Records Per Page
  3. @ $cps; //Current Page Starting row number
  4. @ $lps; //Last Page Starting row number
  5. @ $a; //will be used to print the starting row number that is shown in the page
  6. @ $b; //will be used to print the ending row number that is shown in the page
  7.  
  8. if(empty($_GET["cps"]))
  9. { $cps = "0"; }
  10. else
  11. { $cps = $_GET["cps"]; }
  12. $a = $cps+1;
  13. $rpp = "10";
  14. $lps = $cps - $rpp; //Calculating the starting row number for previous page
  15. if ($cps <> 0)
  16. {
  17. $prv = "<a href='myagreement.php?cps=$lps"."&user1=".$_SESSION['employerid']."'>Previous</a>";
  18. }
  19. else
  20. {
  21. $prv = "<font color='cccccc'>Previous</font>";
  22. }
  23. mysql_query("DROP TABLE TEMPORARY IF EXISTS Mytemp");
  24. mysql_query("CREATE TEMPORARY TABLE Mytemp SELECT resumeid,ttdate,ttime from agreements WHERE buyerid='".$_SESSION['employerid']."' order by ttdate DESC");
  25. $q="Select SQL_CALC_FOUND_ROWS * from Mytemp limit $cps, $rpp ";
  26. $rs=mysql_query($q) or die(mysql_error());
  27. $nr = mysql_num_rows($rs); //Number of rows found with LIMIT in actiong r
  28. $q0="Select FOUND_ROWS()";
  29. $rs0=mysql_query($q0) or die(mysql_error());
  30. $row0=mysql_fetch_array($rs0);
  31. $nr0 = $row0["FOUND_ROWS()"]; //Number of rows found without LIMIT in action
  32. if (($nr0 < 10) || ($nr < 10))
  33. {
  34. $b = $nr0; }
  35. else
  36. {
  37. $b = ($cps) + $rpp; }
  38. ?>
  39. <br>
  40. <table border="0" cellpadding="0" cellspacing="0" width="90%" align="center">
  41. <tr><td><b><font face="verdana" size=2></b></font><b><font face="verdana" size=2 color="#9999CC"></font></b></td></tr>
  42. <tr><td align=left colspan="2"><b><font face="verdana" size=1 color="#9999CC"><? echo "$nr0 Records Found"; ?></font></b></td></tr>
  43. <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>
  44. </tr>
  45. <?
  46. $i=$nr0;
  47. while ($row=mysql_fetch_array($rs))
  48. {
  49. $cps = $cps +1;
  50. $idd=$row[2];
  51. $result=mysql_query("SELECT username from login where username='.$idd.'");
  52. while ($line=mysql_fetch_array($result))
  53. {
  54. echo "<tr>";
  55. echo "<td>";
  56. echo "<table bgcolor='#fefefe' width='73%' align='center' border='0'>";
  57. 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>";
  58. 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>";
  59. echo "</table>";
  60. echo "</td>";
  61. echo "</tr>";
  62. }
  63. echo "<tr><td align='right' colspan=2>$prv";
  64. if ($cps == $nr0)
  65. { echo " | <font color='CCCCCC'>Next</font>"; }
  66. else
  67. {
  68. if ($nr0 > 5)
  69. {
  70. echo " | <a href='myagreement.php?cps=$cps&lps=$lps&user1=".$_SESSION['employerid']."'>Next</a>";
  71. } } ?>
Last edited by cscgal; Mar 4th, 2008 at 1:26 am. Reason: Code tags instead of ICode
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 68
Reputation: JRSofty is an unknown quantity at this point 
Solved Threads: 10
JRSofty's Avatar
JRSofty JRSofty is offline Offline
Junior Poster in Training

Re: help in sql query

 
0
  #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.
JRSofty Programming | .NET Dreaming | GalahTech

If your question is solved then mark the thread solved. If someone gives you good advice then give them some rep.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

Re: help in sql query

 
0
  #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 Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: help in sql query

 
0
  #4
Mar 5th, 2008
Use "GROUP BY" clause.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

Re: help in sql query

 
0
  #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 Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: help in sql query

 
0
  #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 Quick reply to this message  
Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

Re: help in sql query

 
0
  #7
Mar 5th, 2008
output
MySQL returned an empty result set (i.e. zero rows).
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 78
Reputation: jino is an unknown quantity at this point 
Solved Threads: 5
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: help in sql query

 
0
  #8
Mar 5th, 2008
U please check the query in PHP Myadmin wheather u r getting any values for ur query...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

Re: help in sql query

 
0
  #9
Mar 5th, 2008
ya i checked it in php myadmin only
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 78
Reputation: jino is an unknown quantity at this point 
Solved Threads: 5
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: help in sql query

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC