I'm DESPERATE for Table Help in .php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ladysniper
Forum Newbie
Posts: 2
Joined: Sun May 28, 2006 4:42 pm

I'm DESPERATE for Table Help in .php

Post by ladysniper »

DESPERATE doesn't begin to describe it. :( :(

Can someone PLEASE tell me what is WRONG with this code?

Now..a bit of background. It is a search results page for http://www.azsoma.info/directory.htm. (use Scottsdale for the city)

If you go look, you see that the search results post (I do have my table borders up for debugging) but it doesn't line up with the table above it...the whole scroll background doesn't show up and I cannot get my results to have a space between them. And on top of it...they want an inline frame! I haven't even attempted that...at all....

Please...can someone help me. Hell, I'll pay someone if I have to...be glad to...but this page needs to be done for the client....

Warning...long coding....

Thank you in advance....please, if someone could/would help me....

Code: Select all

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Directory Search Results</title>
  </head>

<body bgcolor="#000000">
<div align="center">

<table width="800" border="1" cellpadding="0" cellspacing="0" height="100%">
 <table width ="800" border="1" cellpadding="0" cellspacing="0" height="15%>

  <tr>
    <td width="4"></td><td valign="top" align="center" height="19%">
     <img border="0" src="images/header3.gif" width="800" height="150"></td></tr></table>

       <table width ="800" border="1" cellpadding="0" cellspacing="0" height="10%">
<tr>
             <td width ="800" height="19" bgcolor="e1d7a4" valign="top" align="center">

 <p style="margin-left: 25"><br>
 <font face="Rockwell" size="2" color="#990000"> <font color="FF7256">
 <a href="/index.htm"><font color="#990000">Home</font></a></font><font color="#990000">&nbsp;&nbsp;&nbsp;&nbsp;
 </font> <font color="FF7256">
 <a href="application.htm"><font color="#990000">Member Application</font></a><font color="#990000">&nbsp;&nbsp;&nbsp;&nbsp;
 </font>
 <a href="/membership.htm"><font color="#990000">Member Benefits/Products</font></a><font color="#990000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 </font>
 <a href="/directory.htm"><font color="#990000">Member Directory</font></a><font color="#990000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 </font>
 <a href="/news.htm"><font color="#990000">Announcements/News/Links</font></a></font></font></p></td></tr></table>




 <table width = "800" border ="1" cellpadding="0" cellspacing="0" align="center" background="images/scroll.jpg" length="800">
 <form method="post" action="http://azsoma.info/results.php">




      	<!--	<table width="800" border="1" cellpadding="1" cellspacing="0" align="center" background="images/qi-gong2_16.jpg" height="100%">          -->

<!--         <tr>

<!--          <td width="60" valign="top"><b>id</b></td>  -->
<!--          <td width="20%"><font size="3" color="990000">Full Name</font></td> -->
 <!--          <td width="30%"><font size="3" color="990000">Address</font></td> -->
<!--           <td width="10%"><font size="3" color="990000">City</font></td>  -->
<!--           <td width="10%"><font size="3" color="990000">Zip</font></td>  -->
<!--           <td width="10%"><font size="3" color="990000">Phone</font></td>  -->
<!--           <td width="20%"><font size="3" color="990000">Website Address</font></td>  -->
 <!--        </tr>  -->

        <tr>

Code: Select all

<?php
//print_r($_POST);
//echo "<br>\n";

  $hostname = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // The Thinkhost DB server.
  $username = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // The username you created for this database.
  $password = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // The password you created for the username.
  $usertable = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // The name of the table you made.
  $dbName = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // This is the name of the database you made.

  MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
  @mysql_select_db( "$dbName") or die( "Unable to select database");

//error message (not found message)begins
 // $XX = "No Record Found, to search again please close this window";

/*+-------------------------------------------------------------------------------------+
  | Query Details Begin:                                                                |
  +-------------------------------------------------------------------------------------+
  | Since I don't know if phpForms has a built in search function and I don't have time |
  | to try to decipher how they are storing/retrieving information from the tables,     |
  | this is the long way around it but it should work.                                  |
  +-------------------------------------------------------------------------------------+
  | May 2006 - AJM    re-edited by RJP                                                  |
  +-------------------------------------------------------------------------------------+*/

/*+-------------------------------------------------------------------------------------+
  | First we get all distinct records that have the matching criteria from the search   |
  | page (directory.htm)                                                                |
  +-------------------------------------------------------------------------------------+
  | Determine which fields they have used: Name, City, Zip - and build the WHERE clause |
  +-------------------------------------------------------------------------------------+*/
  $sql = "SELECT DISTINCT sub_rec_id "
        ."  FROM pf_submissions "
        ." WHERE ";

  if($_POST['Name']>"")
    $sql .= " (sub_fld_name LIKE '%name%' AND sub_fld_value LIKE '%". $_POST['Name']. "%') AND ";

  if($_POST['City']>"")
    $sql .= " (sub_fld_name LIKE '%city%' AND sub_fld_value LIKE '%". $_POST['City']. "%') AND ";

  if($_POST['Zip']>"")
    $sql .= " (sub_fld_name LIKE '%zip%' AND sub_fld_value LIKE '%". $_POST['Zip']. "%') AND ";

  $sql .= " 1=1 "
         ." ORDER BY sub_rec_id ASC";

//echo "sql=".$sql."<br>\n";
  $qry = mysql_query($sql);

/*+-------------------------------------------------------------------------------------+
  | Now, if there are any records, we'll step through getting the name first.           |
  +-------------------------------------------------------------------------------------+*/
  while($row=@mysql_fetch_array($qry))
  {
    $sqlName = "SELECT sub_fld_value "
              ."  FROM pf_submissions "
              ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
              ."   AND sub_fld_name = 'Full Name'";
//echo "sqlName=".$sqlName."<br>\n";

    $qryName = mysql_query($sqlName);
    $rowName = @mysql_fetch_row($qryName);
//print_r($rowName);
//print("<br>\n");

    print("      <tr height='20'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowName[0]."</font></td></tr><br>\n");

    /*+---------------------------------------------------------------------------------+
    | Now, if there are any records, we'll step through getting the office address.     |
    +-----------------------------------------------------------------------------------+*/
      $sqlAddress = "SELECT sub_fld_value "
                 ."  FROM pf_submissions "
                 ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
                 ."   AND sub_fld_name = 'Office Address'";
 // echo "sqlAddress=".$sqlAddress."<br>\n";

      $qryAddress = mysql_query($sqlAddress);
      $rowAddress = @mysql_fetch_row($qryAddress);
    print("      <tr height='20' valign='top'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowAddress[0]."</font></td></tr><br>\n");


  /*+-----------------------------------------------------------------------------------+
  | Now, if there are any records,  For now we get the Office City.                     |
  +-------------------------------------------------------------------------------------+*/
    $sqlCity = "SELECT sub_fld_value "
               ."  FROM pf_submissions "
               ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
               ."   AND sub_fld_name = 'Office City'";
//echo "sqlCity=".$sqlCity."<br>\n";

    $qryCity = mysql_query($sqlCity);
    $rowCity = @mysql_fetch_row($qryCity);
   print("      <tr height='20'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowCity[0]."</font></td></tr><br>\n");

   /*+-------------------------------------------------------------------------------------+
     | Now, if there are any records, we'll step through getting the Office state.           |
     | RJP 05/28/06                                                                        |
     +-------------------------------------------------------------------------------------+*/
       $sqlState = "SELECT sub_fld_value "
                  ."  FROM pf_submissions "
                  ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
                  ."   AND sub_fld_name = 'Office State'";
   //echo "sqlState=".$sqlState."<br>\n";

       $qryState = mysql_query($sqlState);
       $rowState = @mysql_fetch_row($qryState);
   print("      <tr height='20'><td valign'top'><p style='margin-left:150'><font size='2'>".$rowState[0]."</font></td></tr><br>\n");

/*+-------------------------------------------------------------------------------------+
  | Now, if there are any records, we'll step through getting the Office zip.           |
  | RJP 05/17/06                                                                        |
  +-------------------------------------------------------------------------------------+*/
    $sqlZip = "SELECT sub_fld_value "
               ."  FROM pf_submissions "
               ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
               ."   AND sub_fld_name = 'Office Zip'";
//echo "sqlZip=".$sqlZip."<br>\n";

    $qryZip = mysql_query($sqlZip);
    $rowZip = @mysql_fetch_row($qryZip);
   print("      <tr height='20'><td valign'top'><p style='margin-left:150'><font size='2'>".$rowZip[0]."</font></td></tr><br>\n");

 /*+------------------------------------------------------------------------------------+
  | Now, if there are any records, we'll step through getting the Office Phone Number.  |
  | RJP 05/17/06                                                                        |
  +-------------------------------------------------------------------------------------+*/
    $sqlPhone = "SELECT sub_fld_value "
               ."  FROM pf_submissions "
               ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
               ."   AND sub_fld_name = 'Office Phone'";
//echo "sqlPhone=".$sqlPhone."<br>\n";

    $qryPhone = mysql_query($sqlPhone);
    $rowPhone = @mysql_fetch_row($qryPhone);
   print("      <tr height='20'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowPhone[0]."</font></td></tr><br>\n");

 /*+------------------------------------------------------------------------------------+
  | Now, if there are any records, we'll step through getting the Website. RJP 05/17/06 |
  +-------------------------------------------------------------------------------------+*/
    $sqlWeb = "SELECT sub_fld_value "
               ."  FROM pf_submissions "
               ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
               ."   AND sub_fld_name = 'Website Address'";
//echo "sqlWeb=".$sqlWeb."<br>\n";

    $qryWeb = mysql_query($sqlWeb);
    $rowWeb = @mysql_fetch_row($qryWeb);
  print("      <tr height='20'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowWeb[0]."</font></td></tr><br>\n");






   print("    </tr>\n");
  }

//below this is the function for no record!!
  if (!$variable1)
  {
    print ("$XX");
   // echo "      </tr>\n";
  }
//end

?>


</table>

      </table>

     </div>
  </body>

</html>
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

You need to be carefull when posting your code. Be sure not to show us how to login into your database :)
ladysniper
Forum Newbie
Posts: 2
Joined: Sun May 28, 2006 4:42 pm

Post by ladysniper »

Ugh...I'm in a panic and didn't even pay attention to that. :(

Thanks for fixing it for me...

Anyway....anyone have any idea on the code? :(
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

First that comes to mind is there is a PHP error that is not displaying because you have error_reporting and/or display_errors off. Next thing, you are doing a heck of a lot of queries within a while loop which is going to create some performance issues for you.

What I would do, at the top of the page, add the following code, clear your cache, then rerun the page submission and see what PHP tells you.

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);
?>
Post back with the error report.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try this. This combines your code into a file and added some error checking. Run it and see what comes out. Also, know that there is a better way to to do what you are trying to do, at least with the six queries within a while lop of another query.

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);
?>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Directory Search Results</title>
  </head>

<body bgcolor="#000000">
<div align="center">

<table width="800" border="1" cellpadding="0" cellspacing="0" height="100%">
 <table width ="800" border="1" cellpadding="0" cellspacing="0" height="15%>

  <tr>
    <td width="4"></td><td valign="top" align="center" height="19%">
     <img border="0" src="images/header3.gif" width="800" height="150"></td></tr></table>

       <table width ="800" border="1" cellpadding="0" cellspacing="0" height="10%">
<tr>
             <td width ="800" height="19" bgcolor="e1d7a4" valign="top" align="center">

 <p style="margin-left: 25"><br>
 <font face="Rockwell" size="2" color="#990000"> <font color="FF7256">
 <a href="/index.htm"><font color="#990000">Home</font></a></font><font color="#990000">&nbsp;&nbsp;&nbsp;&nbsp;
 </font> <font color="FF7256">
 <a href="application.htm"><font color="#990000">Member Application</font></a><font color="#990000">&nbsp;&nbsp;&nbsp;&nbsp;
 </font>
 <a href="/membership.htm"><font color="#990000">Member Benefits/Products</font></a><font color="#990000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 </font>
 <a href="/directory.htm"><font color="#990000">Member Directory</font></a><font color="#990000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 </font>
 <a href="/news.htm"><font color="#990000">Announcements/News/Links</font></a></font></font></p></td></tr></table>




 <table width = "800" border ="1" cellpadding="0" cellspacing="0" align="center" background="images/scroll.jpg" length="800">
 <form method="post" action="http://azsoma.info/results.php">




         <!--   <table width="800" border="1" cellpadding="1" cellspacing="0" align="center" background="images/qi-gong2_16.jpg" height="100%">          -->

<!--         <tr>

<!--          <td width="60" valign="top"><b>id</b></td>  -->
<!--          <td width="20%"><font size="3" color="990000">Full Name</font></td> -->
 <!--          <td width="30%"><font size="3" color="990000">Address</font></td> -->
<!--           <td width="10%"><font size="3" color="990000">City</font></td>  -->
<!--           <td width="10%"><font size="3" color="990000">Zip</font></td>  -->
<!--           <td width="10%"><font size="3" color="990000">Phone</font></td>  -->
<!--           <td width="20%"><font size="3" color="990000">Website Address</font></td>  -->
 <!--        </tr>  -->

        <tr>
<?php
  $hostname = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // The Thinkhost DB server.
  $username = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // The username you created for this database.
  $password = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // The password you created for the username.
  $usertable = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // The name of the table you made.
  $dbName = "***DON'T SHOW US YOUR LOGIN INFO SILLY***"; // This is the name of the database you made.

  mysql_connect($hostname, $username, $password) OR DIE("DB connection unavailable");
  mysql_select_db($dbName) or die( "Unable to select database");

//error message (not found message)begins
 // $XX = "No Record Found, to search again please close this window";

/*+-------------------------------------------------------------------------------------+
  | Query Details Begin:                                                                |
  +-------------------------------------------------------------------------------------+
  | Since I don't know if phpForms has a built in search function and I don't have time |
  | to try to decipher how they are storing/retrieving information from the tables,     |
  | this is the long way around it but it should work.                                  |
  +-------------------------------------------------------------------------------------+
  | May 2006 - AJM    re-edited by RJP                                                  |
  +-------------------------------------------------------------------------------------+*/

/*+-------------------------------------------------------------------------------------+
  | First we get all distinct records that have the matching criteria from the search   |
  | page (directory.htm)                                                                |
  +-------------------------------------------------------------------------------------+
  | Determine which fields they have used: Name, City, Zip - and build the WHERE clause |
  +-------------------------------------------------------------------------------------+*/
  $sql = "SELECT DISTINCT(sub_rec_id) FROM pf_submissions WHERE";

  if( !empty($_POST['Name']) )
    $sql .= " (sub_fld_name LIKE '%name%' AND sub_fld_value LIKE '%". $_POST['Name']. "%') AND ";

  if( !empty($_POST['City']) )
    $sql .= " (sub_fld_name LIKE '%city%' AND sub_fld_value LIKE '%". $_POST['City']. "%') AND ";

  if( !empty($_POST['Zip']) )
    $sql .= " (sub_fld_name LIKE '%zip%' AND sub_fld_value LIKE '%". $_POST['Zip']. "%') AND ";

  $sql .= " 1=1 ORDER BY sub_rec_id ASC";

//echo "sql=".$sql."<br>\n";
  if ( !$qry = mysql_query($sql) )
  {
	die("Could not run the query $qry because: " . mysql_error());
  }

/*+-------------------------------------------------------------------------------------+
  | Now, if there are any records, we'll step through getting the name first.           |
  +-------------------------------------------------------------------------------------+*/
  while($row = mysql_fetch_array($qry))
  {
    $sqlName = "SELECT sub_fld_value "
              ."  FROM pf_submissions "
              ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
              ."   AND sub_fld_name = 'Full Name'";
//echo "sqlName=".$sqlName."<br>\n";

    if ( !$qryName = mysql_query($sqlName) ) 
	  die("Could Not Run The Name Query: " . mysql_error());
    $rowName = @mysql_fetch_row($qryName);
//print_r($rowName);
//print("<br>\n");

    print("      <tr height='20'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowName[0]."</font></td></tr><br>\n");

    /*+---------------------------------------------------------------------------------+
    | Now, if there are any records, we'll step through getting the office address.     |
    +-----------------------------------------------------------------------------------+*/
      $sqlAddress = "SELECT sub_fld_value "
                 ."  FROM pf_submissions "
                 ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
                 ."   AND sub_fld_name = 'Office Address'";
 // echo "sqlAddress=".$sqlAddress."<br>\n";

      if ( !$qryAddress = mysql_query($sqlAddress) ) 
	    die("Could Not Run The Address Query: " . mysql_error());
      $rowAddress = @mysql_fetch_row($qryAddress);
    print("      <tr height='20' valign='top'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowAddress[0]."</font></td></tr><br>\n");


  /*+-----------------------------------------------------------------------------------+
  | Now, if there are any records,  For now we get the Office City.                     |
  +-------------------------------------------------------------------------------------+*/
    $sqlCity = "SELECT sub_fld_value "
               ."  FROM pf_submissions "
               ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
               ."   AND sub_fld_name = 'Office City'";
//echo "sqlCity=".$sqlCity."<br>\n";

    if ( !$qryCity = mysql_query($sqlCity) )
	   die("Could Not Run The City Query: " . mysql_error());
    $rowCity = @mysql_fetch_row($qryCity);
   print("      <tr height='20'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowCity[0]."</font></td></tr><br>\n");

   /*+-------------------------------------------------------------------------------------+
     | Now, if there are any records, we'll step through getting the Office state.           |
     | RJP 05/28/06                                                                        |
     +-------------------------------------------------------------------------------------+*/
       $sqlState = "SELECT sub_fld_value "
                  ."  FROM pf_submissions "
                  ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
                  ."   AND sub_fld_name = 'Office State'";
   //echo "sqlState=".$sqlState."<br>\n";

       if ( !$qryState = mysql_query($sqlState) )
	      die("Could Not Run The State Query: " . mysql_error());
       $rowState = @mysql_fetch_row($qryState);
   print("      <tr height='20'><td valign'top'><p style='margin-left:150'><font size='2'>".$rowState[0]."</font></td></tr><br>\n");

/*+-------------------------------------------------------------------------------------+
  | Now, if there are any records, we'll step through getting the Office zip.           |
  | RJP 05/17/06                                                                        |
  +-------------------------------------------------------------------------------------+*/
    $sqlZip = "SELECT sub_fld_value "
               ."  FROM pf_submissions "
               ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
               ."   AND sub_fld_name = 'Office Zip'";
//echo "sqlZip=".$sqlZip."<br>\n";

    if ( !$qryZip = mysql_query($sqlZip) )
	   die("Could Not Run The Zip Query: " . mysql_error());
    $rowZip = @mysql_fetch_row($qryZip);
   print("      <tr height='20'><td valign'top'><p style='margin-left:150'><font size='2'>".$rowZip[0]."</font></td></tr><br>\n");

 /*+------------------------------------------------------------------------------------+
  | Now, if there are any records, we'll step through getting the Office Phone Number.  |
  | RJP 05/17/06                                                                        |
  +-------------------------------------------------------------------------------------+*/
    $sqlPhone = "SELECT sub_fld_value "
               ."  FROM pf_submissions "
               ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
               ."   AND sub_fld_name = 'Office Phone'";
//echo "sqlPhone=".$sqlPhone."<br>\n";

    if ( !$qryPhone = mysql_query($sqlPhone) )
	   die("Could Not Run The Phone Query: " . mysql_error());
    $rowPhone = @mysql_fetch_row($qryPhone);
   print("      <tr height='20'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowPhone[0]."</font></td></tr><br>\n");

 /*+------------------------------------------------------------------------------------+
  | Now, if there are any records, we'll step through getting the Website. RJP 05/17/06 |
  +-------------------------------------------------------------------------------------+*/
    $sqlWeb = "SELECT sub_fld_value "
               ."  FROM pf_submissions "
               ." WHERE sub_rec_id = '" .$row["sub_rec_id"]. "' "
               ."   AND sub_fld_name = 'Website Address'";
//echo "sqlWeb=".$sqlWeb."<br>\n";

    if ( !$qryWeb = mysql_query($sqlWeb) )
	   die("Could Not Run The Web Query: " . mysql_error());
    $rowWeb = @mysql_fetch_row($qryWeb);
  print("      <tr height='20'><td valign='top'><p style='margin-left:150'><font size='2'>".$rowWeb[0]."</font></td></tr><br>\n");






   print("    </tr>\n");
  }

//below this is the function for no record!!
  if (!$variable1)
  {
    print ("$XX");
   // echo "      </tr>\n";
  }
//end

?>
</table>

      </table>

     </div>
  </body>

</html>
Post Reply