Page 1 of 1

problem with statement

Posted: Tue Apr 20, 2004 6:32 pm
by surforever
there is some problem with this statement because the execution stops right before this chunk of code
can anyone help please. thanks

Code: Select all

<?
  $SQL = "SELECT p.position_name AS name FROM positions p, applicant_position ap WHERE p.id=ap.positions_id AND ap.applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_assoc($result))
  {
    echo "<LI>".$row["name"];
  }

?>

Posted: Tue Apr 20, 2004 6:41 pm
by llanitedave
Does it give you an error?

Posted: Tue Apr 20, 2004 6:43 pm
by Illusionist
could it be something before that causing it to stop execution?

Posted: Tue Apr 20, 2004 6:51 pm
by tim
just a note

you should always use mysql_fetch_array instead of mysql_fetch_assoc.


I would venture to say:
AND ap.applicant_id=".$user_id;

is incorrect.

Posted: Tue Apr 20, 2004 7:33 pm
by surforever
This is the error message that I get:

Code: Select all

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/webdev/public_html/webdev/test2/final.php on line 9
P.S. I replaced mysql_fetch_assoc() with mysql_fetch_array() and still get same error


It prints "Wishful positions" and returns that error right after it

Code: Select all

<?
  include ("inc/u_header.php");
  if (isset($_GET["user_id"]))
    $user_id = $_GET["user_id"];
  else
    $user_id=$_SESSION["user_id"];

  $SQL = "SELECT * FROM applicant WHERE id=".$user_id;
  $row = mysql_fetch_array(mysql_query($SQL));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Resume</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="admin.css">
</HEAD>

<BODY TOPMARGIN=2 LEFTMARGIN=2>
<H3 ALIGN=center>Common:</H3>
<TABLE ALIGN=center WIDTH=70% BORDER=0 CLASS=table_border CELLPADDING=2 CELLSPACING=1>
<TR><TD>
<FIELDSET>
<LEGEND><B>Applicant</B></LEGEND>
<TABLE ALIGN=center WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>
<TR>
<TD ALIGN=right>Fullname:<FONT COLOR=red>*</FONT></TD>
<TD><INPUT TYPE="text" NAME="name" READONLY SIZE=50 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["fullname"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Address:</TD>
<TD><INPUT TYPE="text" READONLY NAME="address" SIZE=50 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["address"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>City:<FONT COLOR=red>*</FONT></TD>
<TD><INPUT TYPE="text" READONLY NAME="city" SIZE=40 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["city"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>State:</TD>
<TD><INPUT TYPE="text" READONLY NAME="state" SIZE=40 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["state"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>zip-code:</TD>
<TD><INPUT TYPE="text" NAME="zip" SIZE=40 MAXLENGTH=60 CLASS=fields VALUE="<?=$row["zip"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Phone:</TD>
<TD><INPUT TYPE="text" READONLY NAME="phone" SIZE=40 CLASS=fields MAXLENGTH=60 VALUE="<?=$row["phone"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right WIDTH=35%>Fax:</TD>
<TD><INPUT TYPE="text" READONLY NAME="fax" CLASS=fields MAXLENGTH=60 VALUE="<?=$row["fax"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right WIDTH=35%>Cell:</TD>
<TD><INPUT TYPE="text" READONLY NAME="cell" CLASS=fields MAXLENGTH=60 VALUE="<?=$row["cell"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right WIDTH=35%>E-mail:<FONT COLOR=red>*</FONT></TD>
<TD><INPUT TYPE="text" NAME="email" CLASS=fields MAXLENGTH=60 VALUE="<?=$row["email"]?>"></TD>
</TR>
<TR>
<TD ALIGN=right WIDTH=35%>web-site:</TD>
<TD><INPUT TYPE="text" NAME="website" CLASS=fields MAXLENGTH=60 VALUE="<?=$row["website"]?>"></TD>
</TR>
</TABLE>
</FIELDSET>
</TD>
</TR>
<TR>
<TD>
<FIELDSET>
<LEGEND><B>Wishful positions:</B></LEGEND>
<UL>
<?
  $SQL = "SELECT p.position_name AS name FROM positions p, applicant_position ap WHERE p.id=ap.positions_id AND ap.applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_assoc($result))
  {
    echo "<LI>".$row["name"];
  }
?>
</UL>
</FIELDSET><BR>
<FIELDSET>
<LEGEND><B>Skills:</B></LEGEND>
<UL>
<?
  $SQL = "SELECT skill, expertise FROM skills WHERE applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_array($result))
  {
    echo "<LI>".$row["skill"]."; Expertise:".$row["expertise"];
  }
?>
</UL>
</FIELDSET><BR>
<FIELDSET>
<LEGEND><B>Projects:</B></LEGEND>
<UL>
<?
  $SQL = "SELECT url, responsibilities, comments FROM portfolio WHERE applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_assoc($result))
  {
    echo "<LI><B>URL:</B><A HREF="".$row["url"]."">".$row["url"]."</A>;<BR><B>Responsibilities:</B> ".$row["responsibilities"].";<BR><B>Comments:</B> ".$row["comments"]."<P>";
  }
?>
</UL>
</FIELDSET><BR>
<FIELDSET>
<LEGEND><B>Questions to employer:</B></LEGEND>
<UL>
<?
  $SQL = "SELECT a_date, q_text FROM answers WHERE applicant_id=".$user_id;
  $result = mysql_query($SQL) or die(mysql_error());
  while ($row=mysql_fetch_assoc($result))
  {
    echo "<LI><B>Date:</B> ".date("d.m.Y", strtotime($row["a_date"]))."<BR><B>Text:</B> ".$row["q_text"]."<P>";
  }
?>
</UL>
</FIELDSET>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
?>

Posted: Tue Apr 20, 2004 7:50 pm
by Unipus
try:
SELECT p.position_name AS name FROM positions p, applicant_position ap WHERE p.id=ap.positions_id AND ap.applicant_id='$user_id';

Posted: Tue Apr 20, 2004 8:03 pm
by surforever
unfortunately that didn't work

Posted: Tue Apr 20, 2004 8:23 pm
by Unipus
Well best bet then is to test your SQL queries directly, instead of within PHP. I always do this anyway before putting them into my documents, just to be sure they work how I intended.