By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

SQL wont display results

matheussousuke
100+
P: 249
Well, the page is not displaying the sql results, perhaps there is something wrong in this line, but I still dont know how to fix:



Expand|Select|Wrap|Line Numbers
  1. echo "<tr bgcolor=\"$col\"><td><a class=TN href=\"javascript:popUp('preview.php?uname=$a1[uname]&ename=$ename')\"> $a2[0] $a2[1]</a></td><td> $a1[clname] </td></tr>";
  2.  
Is it the
Expand|Select|Wrap|Line Numbers
  1.  $a2[0] $a2[1]
part?




The code:

Expand|Select|Wrap|Line Numbers
  1. {
  2.  
  3.     $q2 = "select fname, lname from job_seeker_info where uname = \"$a1[uname]\" ";
  4.  
  5.     $r2 = mysql_query($q2) or die(mysql_error());
  6.  
  7.     $a2 = mysql_fetch_array($r2);
  8.  
  9.  
  10.  
  11.      if($col == "cococo")
  12.  
  13.         { 
  14.  
  15.          $col = "dddddd"; 
  16.  
  17.         }
  18.  
  19.                   else
  20.  
  21.         { 
  22.  
  23.         $col = "cococo"; 
  24.  
  25.         } 
  26.  
  27.  
  28.  
  29.     echo "<tr bgcolor=\"$col\"><td><a class=TN href=\"javascript:popUp('preview.php?uname=$a1[uname]&ename=$ename')\"> $a2[0] $a2[1]</a></td><td> $a1[clname] </td></tr>";
  30.  
  31. }
  32.  
If you want the full code, let me know.
Dec 2 '11 #1
Share this Question
Share on Google+
36 Replies


matheussousuke
100+
P: 249
Please, someone, I know it's friday, but...
Dec 2 '11 #2

zorgi
Expert 100+
P: 431
Quick look and this is what I see:

$a1[uname] should probably be $a1['uname'] lines 3 & 29
$a1[clname] should probably be $a1['clname'] line 29
Dec 2 '11 #3

matheussousuke
100+
P: 249
I put the quotes, and now I get this:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/sitee/public_html/employers/employers15.php on line 83
Dec 2 '11 #4

zorgi
Expert 100+
P: 431
Its probably because of the way you construct your query string. What is on line 83?
Dec 2 '11 #5

matheussousuke
100+
P: 249
lol, on line 83 it's the line I altered.

Expand|Select|Wrap|Line Numbers
  1. uname=$a1['uname']&ename=$ename')\"> $a2[0] $a2[1]
Dec 2 '11 #6

zorgi
Expert 100+
P: 431
uname=$a1['uname']&ename=$ename'

should be

uname=".$a1['uname']."&ename=$ename'
Dec 3 '11 #7

matheussousuke
100+
P: 249
I did this:

Expand|Select|Wrap|Line Numbers
  1.     echo "<tr bgcolor=\"$col\"><td><a class=TN href=\"javascript:popUp('preview.php?uname=".$a1['uname']."&ename=$ename')\"> $a2[0] $a2[1]</a></td><td> $a1[clname] </td></tr>";
  2.  
  3. }
It didnt work and the part .$a1['uname']. changed color, showing the code is wrong. =/
Dec 3 '11 #8

zorgi
Expert 100+
P: 431
You might want to have a look at String Operators because you did same mistake on the same line more than once.
Dec 3 '11 #9

matheussousuke
100+
P: 249
I've read, but it's very basic, didn't find the solution for my quotes issue.
Dec 3 '11 #10

matheussousuke
100+
P: 249
What if it's not that line, is this part correct?


Expand|Select|Wrap|Line Numbers
  1. {
  2.  
  3.     $q2 = "select fname, lname from job_seeker_info where uname = \"$a1[uname]\" ";
  4.  
  5.     $r2 = mysql_query($q2) or die(mysql_error());
  6.  
  7.     $a2 = mysql_fetch_array($r2);
  8.  
  9.  
  10.  
  11.      if($col == "cococo")
  12.  
  13.         { 
  14.  
  15.          $col = "dddddd"; 
  16.  
  17.         }
  18.  
  19.                   else
  20.  
  21.         { 
  22.  
  23.         $col = "cococo"; 
  24.  
  25.         } 
  26.  
Dec 3 '11 #11

zorgi
Expert 100+
P: 431
I agree, it is very basic, but you didn't apply those basic principles to your code. Example:
Expand|Select|Wrap|Line Numbers
  1. $a = array("uname" => "matheussousuke", "sname" => "surname");
What you are doing to echo uname element of an array is this:
Expand|Select|Wrap|Line Numbers
  1. echo $a[uname];
when you should be doing this:
Expand|Select|Wrap|Line Numbers
  1. echo $a['uname'];
You are also doing something like this:
Expand|Select|Wrap|Line Numbers
  1. echo $a['uname'] $a['sname'];
And that is exactly what that basic lesson is all about:
Expand|Select|Wrap|Line Numbers
  1. echo $a['uname']." ".$a['sname'];
Just apply this to your code and let us know how it went ;)
Dec 3 '11 #12

matheussousuke
100+
P: 249
OK, I'll do it, but forgive my newbie lames if you find some. :P
Dec 3 '11 #13

omerbutt
100+
P: 638
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  echo "<tr bgcolor=".$col."><td><a class=TN href=\"javascript:popUp('preview.php?uname=".$a1['uname']."&ename=$ename')\"> ".$a2[0].$a2[1]."</a>
  3.  </td><td>". $a1['clname']." </td></tr>";
  4.  
try this replace with you code
regards,
Omer Aslam
Dec 3 '11 #14

matheussousuke
100+
P: 249
I tried but look at the code's color:

Dec 3 '11 #15

zorgi
Expert 100+
P: 431
Did you actually try to run that code. It looks like your editor is just highlighting strings in that colour.
Dec 3 '11 #16

matheussousuke
100+
P: 249
of course, here:

Dec 3 '11 #17

matheussousuke
100+
P: 249
As you can see, there is nothing between Nível and << Voltar field.
Dec 3 '11 #18

zorgi
Expert 100+
P: 431
Is there suppose to be? Can you set border on your table to 1 or inspect that part of your html with firebug so you can see what is echoed? Also do var_dump on all of your variables to see what they contain.
Dec 3 '11 #19

matheussousuke
100+
P: 249
There should be results bellow "Nível", they are:
Name and Knowledge Level.

Can I use the Chrome Console?
Dec 3 '11 #20

matheussousuke
100+
P: 249
Just as I expected, there is nothing below it, it like the php is not displaying the data:

The HTML part from the loaded page:
Expand|Select|Wrap|Line Numbers
  1. <table align="center" width="500" cellspacing="0">
  2.  
  3.     <caption align="center"><b> Candidatos para a vaga N° 1 / posição Pessoas com conhecimento em informática </b><br><font size="2"> Esta oferta foi visualizada 10 vezes e há 6 interessado(s). </font> </caption>
  4.  
  5.     <tbody><tr bgcolor="gray" style="font-family:arial; font-size:11; color:000000; font-weight:bold"><td width="150">Nome </td><td>Nível </td></tr></tbody></table>
Dec 3 '11 #21

zorgi
Expert 100+
P: 431
Giving me fragments of code like this doesn't help as error can be somewhere else. I absolutly can not see connection between your HTML and your php.
Dec 3 '11 #22

matheussousuke
100+
P: 249
The full code:

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. // Sistema de Empregos baseado no script Diesel Job Site versão 1.4
  4.  
  5.  
  6.  
  7. include_once "accesscontrol.php";
  8.  
  9. include_once "../configuration.inc.php";
  10.  
  11.  
  12.  
  13. $q1 = "select * from job_aplicants t1, job_careerlevel t2 where t1.aplicant = t2.uname and t1.job_id = \"$_GET[job_id]\" order by t2.clnumber desc";
  14.  
  15. $r1 = mysql_query($q1) or die(mysql_error());
  16.  
  17.  
  18.  
  19. //number of offer rerviews
  20.  
  21. $q22 = "select nv from job_post where job_id = \"$_GET[job_id]\" ";
  22.  
  23. $r22 = mysql_query($q22) or die(mysql_error());
  24.  
  25. $a22 = mysql_fetch_array($r22);
  26.  
  27.  
  28.  
  29. //number of offer aplicants
  30.  
  31. $q33 = "select count(aplicant) from job_aplicants where job_id = \"$_GET[job_id]\" ";
  32.  
  33. $r33 = mysql_query($q33) or die(mysql_error());
  34.  
  35. $a33 = mysql_fetch_array($r33);
  36.  
  37.  
  38.  
  39.  
  40.  
  41. echo "<br><br><br><table align=center width=500 cellspacing=0>
  42.  
  43.     <caption align=center><b> Candidatos para a vaga N° $_GET[job_id] / posição $position </b><br><font size=2> Esta oferta foi visualizada $a22[0] vezes e há $a33[0] interessado(s). </font> </caption>
  44.  
  45.     <tr bgcolor=gray style=\"font-family:arial; font-size:11; color:$s3white; font-weight:bold\"><td width=150>Nome </td><td>Nível </td></tr>";
  46.  
  47.  
  48.  
  49. $col = "cococo";
  50.  
  51.  
  52.  
  53. while ($a1 = mysql_fetch_array($r1))
  54.  
  55. {
  56.  
  57.     $q2 = "select fname, lname from job_seeker_info where uname = \"$a1[uname]\" ";
  58.  
  59.     $r2 = mysql_query($q2) or die(mysql_error());
  60.  
  61.     $a2 = mysql_fetch_array($r2);
  62.  
  63.  
  64.  
  65.      if($col == "cococo")
  66.  
  67.         { 
  68.  
  69.          $col = "dddddd"; 
  70.  
  71.         }
  72.  
  73.                   else
  74.  
  75.         { 
  76.  
  77.         $col = "cococo"; 
  78.  
  79.         } 
  80.  
  81. echo "<tr bgcolor=".$col."><td><a class=TN href=\"javascript:popUp('preview.php?uname=".$a1['uname']."&ename=$ename')\"> ".$a2[0].$a2[1]."</a>
  82.  </td><td>". $a1['clname']." </td></tr>";
  83. }
  84.  
  85. /*
  86.     echo "<tr bgcolor=\"$col\"><td><a class=TN href=\"javascript:popUp('preview.php?uname=$a1[uname]&ename=$ename')\"> $a2[0] $a2[1]</a></td><td> $a1[clname] </td></tr>";
  87. */
  88.  
  89. echo "</table><center><br><a class=TN href=employers7.php> << voltar</a></center>";
  90.  
  91.  
  92.  
  93. ?>
  94.  
  95. <? include_once('../footer.php'); ?>
Dec 3 '11 #23

zorgi
Expert 100+
P: 431
can you do var_dump($a1) on line 56
Dec 3 '11 #24

matheussousuke
100+
P: 249
Parse error: syntax error, unexpected T_VARIABLE in /home/balcaoce/public_html/employers/employers15.php on line 57
Dec 3 '11 #25

zorgi
Expert 100+
P: 431
what is on lines 56,57,58
Dec 3 '11 #26

matheussousuke
100+
P: 249
I have an idea, I sent you a copy of the file through PM.
Dec 3 '11 #27

zorgi
Expert 100+
P: 431
Did you do that var_dump?!
Dec 3 '11 #28

matheussousuke
100+
P: 249
I did, I did it closing the tags, cause before I was receiving errors.

I inserted it in the line 56:

?><? var_dump($a1) ?><?

Got no error, but no results.
Dec 3 '11 #29

zorgi
Expert 100+
P: 431
First of all you forgot semicolon. Semicolon signifies the end of a PHP statement so you should get some error.

var_dump($a1);

Can you also do var_dump for $r1 on line 52.
Dec 3 '11 #30

matheussousuke
100+
P: 249
Inserted the semicolon, still the same thing. And at line 52 I inserted ?><? var_dump($r1); ?><? and got this result:
resource(16) of type (mysql result)
Dec 3 '11 #31

zorgi
Expert 100+
P: 431
Ok it looks like your while loop is never executed becuse there is nothing to loop through. Check your SQL statement. Echo it out and check its well constructed. I would also use command line or phpMyAdmin to get results directly from database.

Also please go to this page: http://php.net/manual/en/language.types.array.php and read "Why is $foo[bar] wrong?"
Dec 3 '11 #32

matheussousuke
100+
P: 249
So

Expand|Select|Wrap|Line Numbers
  1. echo "<tr bgcolor=".$col."><td><a class=TN href=\"javascript:popUp('preview.php?uname=".$a1['uname']."&ename=$ename')\"> ".$a2[0].$a2[1]."</a>
  2.  </td><td>". $a1['clname']." </td></tr>";
  3. }
is correct?
Dec 3 '11 #33

matheussousuke
100+
P: 249
But that's so weird. This line
Expand|Select|Wrap|Line Numbers
  1. Esta oferta foi visualizada 10 vezes e há 6 interessado(s).
says the job has been viewed 10 times and that there is 6 interested people in it. if it says there is 6 interested people so that means somehow it is counting from real tables?
Dec 3 '11 #34

zorgi
Expert 100+
P: 431
about:
Expand|Select|Wrap|Line Numbers
  1. echo "<tr bgcolor=".$col."><td><a class=TN href=\"javascript:popUp('preview.php?uname=".$a1['uname']."&ename=$ename')\"> ".$a2[0].$a2[1]."</a>
  2.  </td><td>". $a1['clname']." </td></tr>";
Whay don't you check it? Simply create test.php and copy that code into it. Provide any values to the variables needed and run it.
Dec 3 '11 #35

matheussousuke
100+
P: 249
I did a test, submitted my own job application, and it worked. :S
I dont know, maybe the system delete old applications.

By the way, now I'm having an attachment issue. I'll work around it, and if I have any problem, I go back and open another topic, but I dont think I'll have.
Dec 3 '11 #36

matheussousuke
100+
P: 249
PS: Thank you very much for staying and helping me during 2 days. :D
Dec 3 '11 #37

Post your reply

Sign in to post your reply or Sign up for a free account.