Display Records (brief summary and full details)

From: Date: Thu, 24 Jul 2003 21:13:27 +0000
Subject: Display Records (brief summary and full details)
Groups: php.general 
Request: Send a blank email to php-general+get-156743@lists.php.net to get a copy of this message
Hello All, I am trying to create a small MySQL application using PHP. I have a table of contacts with each record having over 30 fields. I have a search page where a logged-in admin can search for a particular record on the basis of certain parameters. This is a sample code:
         $sql1 = "SELECT * from contacts WHERE $where";
        while ($row = mysql_fetch_array($result1)) {
        // Alternate the bgcolor of each row for visibility
            ($even % 2) == 0 ? $bgcolor = "#EFEFEF" : $bgcolor = "#eeffff";
                $even = $even + 1;
        // print the actual row
               echo   "<TR BGCOLOR=$bgcolor>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$row[company]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$row[name_1]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$row[phone_1]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$row[city]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$row[url]</font></TD>
    <TD align=\"left\"><font color=\"#666666\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$row[email_1]</font></TD>
    <TD align=\"center\"><font color=\"#333333\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\"><a href=\"profile.php\">Link</a></font></TD>
</TR>";
        // try to register the variable
$_SESSION['link'] = $row[company];
        } // end while
       // print the end of the table
          echo "</TABLE></body></html>";
The above tables displays the results of the query in a table form with only the main fields of the record. The last column of the table contains a link to view the full-contents of the record. when the user clicks this link, he will go to another script called "profile.php" which will display all the contents of the record. In order to do this I will need to store all the primary keys (in this case the name of the company) of each record from the result set and then use it to retrieve all the contents. I have been successful in trying to do this for a single row (record) of the result by registering it as an session variable called ['link'] I am at a loss to figure out how to store the names of the first column of the result set i.e. the company name. Is it possible to create an array of the session variable ['link'] ?? Another approach would be to get the names of the companies as a separate query and register them as an array of session variables. any suggestions will be welcome. Thanks in advance. --Pushpinder

« previous php.general (#156743) next »