Bluehost.com Web Hosting $6.95

Display Records (brief summary and full details)

This is a discussion on Display Records (brief summary and full details) within the PHP General forums, part of the PHP Programming Forums category; Hello All, I am trying to create a small MySQL application using PHP. I have a table of contacts with ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-24-2003
Pushpinder Singh Garcha
 
Posts: n/a
Default Display Records (brief summary and full details)

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";\0\0

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






Reply With Quote
  #2 (permalink)  
Old 07-25-2003
Tom Rogers
 
Posts: n/a
Default Re: [PHP] Display Records (brief summary and full details)

Hi,

Friday, July 25, 2003, 7:13:27 AM, you wrote:
PSG> Hello All,

PSG> I am trying to create a small MySQL application using PHP. I have a
PSG> table of contacts with each record having over 30 fields. I have a
PSG> search page where a logged-in admin can search for a particular record
PSG> on the basis of certain parameters.

PSG> This is a sample code:


PSG> $sql1 = "SELECT * from `contacts` WHERE $where";

PSG> while ($row = mysql_fetch_array($result1)) {

PSG> // Alternate the bgcolor of each row for visibility
PSG> ($even % 2) == 0 ? $bgcolor = "#EFEFEF" : $bgcolor =
PSG> "#eeffff";
PSG> $even = $even + 1;

PSG> // print the actual row
PSG> echo "<TR BGCOLOR=$bgcolor>
PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
PSG> face=\"Verdana, Arial, Helvetica, sans-serif\">$row[company]</font></TD>
PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
PSG> face=\"Verdana, Arial, Helvetica, sans-serif\">$row[name_1]</font></TD>
PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
PSG> face=\"Verdana, Arial, Helvetica, sans-serif\">$row[phone_1]</font></TD>
PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
PSG> face=\"Verdana, Arial, Helvetica, sans-serif\">$row[city]</font></TD>
PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
PSG> face=\"Verdana, Arial, Helvetica, sans-serif\">$row[url]</font></TD>
PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
PSG> face=\"Verdana, Arial, Helvetica, sans-serif\">$row[email_1]</font></TD>
PSG> <TD align=\"center\"><font color=\"#333333\" size=\"1\"
PSG> face=\"Verdana, Arial, Helvetica, sans-serif\"><a
PSG> href=\"profile.php\">Link</a></font></TD>
PSG> </TR>";

PSG> // try to register the variable
PSG> $_SESSION['link'] = $row[company];
PSG> } // end while
PSG> // print the end of the table
PSG> echo "</TABLE></body></html>";


PSG> The above tables displays the results of the query in a table form
PSG> with only the main fields of the record. The last column of the table
PSG> contains a link to view the full-contents of the record. when the user
PSG> clicks this link, he will go to another script called
PSG> "profile.php" which will display all the contents of the record. In
PSG> order to do this I will need to store all the primary keys (in this
PSG> case the name of the company) of each record from the result set and
PSG> then use it to retrieve all the contents. I have been successful in
PSG> trying to do this for a single row (record) of the result by
PSG> registering it as an session variable called ['link']


PSG> I am at a loss to figure out how to store the names of the first column
PSG> of the result set i.e. the company name. Is it possible to create an
PSG> array of the session variable ['link'] ?? Another approach would be
PSG> to get the names of the companies as a separate query and register them
PSG> as an array of session variables.


PSG> any suggestions will be welcome. Thanks in advance.

PSG> --Pushpinder

in the href put

....<a href=\"profile.php?name=".$row['name']."\">...

Make a seperate array as you loop

$companies[$row['name']] = $row;

in your session store it as

$_SESSION['link'] = $companies;

You can then access it in profile php as


$details = $_SESSION['link']['$_GET['name']]


--
regards,
Tom

Reply With Quote
  #3 (permalink)  
Old 07-25-2003
Pushpinder Singh Garcha
 
Posts: n/a
Default Re: [PHP] Display Records (brief summary and full details)

Thanks Tom,

I appreciate your help ! however I have a 2 quick questions...

1.) should we not save the names of the companies as $companies[$row]
= $row['company']; \0\0
2.) the approach of accessing the variable as $details =
$_SESSION['link']['$_GET['name']] is not
working , when I try to echo the $details is get something else.
I am not sure how we use the
$_SESSION[ ] [ ] with 2 variables as shown.


any help will be appreciated.

regards
--Pushpinder


On Thursday, July 24, 2003, at 08:10 PM, Tom Rogers wrote:

> Hi,
>
> Friday, July 25, 2003, 7:13:27 AM, you wrote:
> PSG> Hello All,
>
> PSG> I am trying to create a small MySQL application using PHP. I
> have a
> PSG> table of contacts with each record having over 30 fields. I have a
> PSG> search page where a logged-in admin can search for a particular
> record
> PSG> on the basis of certain parameters.
>
> PSG> This is a sample code:
>
>
> PSG> $sql1 = "SELECT * from `contacts` WHERE $where";
>
> PSG> while ($row = mysql_fetch_array($result1)) {
>
> PSG> // Alternate the bgcolor of each row for visibility
> PSG> ($even % 2) == 0 ? $bgcolor = "#EFEFEF" : $bgcolor =
> PSG> "#eeffff";
> PSG> $even = $even + 1;
>
> PSG> // print the actual row
> PSG> echo "<TR BGCOLOR=$bgcolor>
> PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> PSG> face=\"Verdana, Arial, Helvetica,
> sans-serif\">$row[company]</font></TD>
> PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> PSG> face=\"Verdana, Arial, Helvetica,
> sans-serif\">$row[name_1]</font></TD>
> PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> PSG> face=\"Verdana, Arial, Helvetica,
> sans-serif\">$row[phone_1]</font></TD>
> PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> PSG> face=\"Verdana, Arial, Helvetica,
> sans-serif\">$row[city]</font></TD>
> PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> PSG> face=\"Verdana, Arial, Helvetica,
> sans-serif\">$row[url]</font></TD>
> PSG> <TD align=\"left\"><font color=\"#666666\" size=\"1\"
> PSG> face=\"Verdana, Arial, Helvetica,
> sans-serif\">$row[email_1]</font></TD>
> PSG> <TD align=\"center\"><font color=\"#333333\" size=\"1\"
> PSG> face=\"Verdana, Arial, Helvetica, sans-serif\"><a
> PSG> href=\"profile.php\">Link</a></font></TD>
> PSG> </TR>";
>
> PSG> // try to register the variable
> PSG> $_SESSION['link'] = $row[company];
> PSG> } // end while
> PSG> // print the end of the table
> PSG> echo "</TABLE></body></html>";
>
>
> PSG> The above tables displays the results of the query in a table form
> PSG> with only the main fields of the record. The last column of the
> table
> PSG> contains a link to view the full-contents of the record. when the
> user
> PSG> clicks this link, he will go to another script called
> PSG> "profile.php" which will display all the contents of the record.
> In
> PSG> order to do this I will need to store all the primary keys (in
> this
> PSG> case the name of the company) of each record from the result set
> and
> PSG> then use it to retrieve all the contents. I have been successful
> in
> PSG> trying to do this for a single row (record) of the result by
> PSG> registering it as an session variable called ['link']
>
>
> PSG> I am at a loss to figure out how to store the names of the first
> column
> PSG> of the result set i.e. the company name. Is it possible to create
> an
> PSG> array of the session variable ['link'] ?? Another approach
> would be
> PSG> to get the names of the companies as a separate query and
> register them
> PSG> as an array of session variables.
>
>
> PSG> any suggestions will be welcome. Thanks in advance.
>
> PSG> --Pushpinder
>
> in the href put
>
> ...<a href=\"profile.php?name=".$row['name']."\">...
>
> Make a seperate array as you loop
>
> $companies[$row['name']] = $row;
>
> in your session store it as
>
> $_SESSION['link'] = $companies;
>
> You can then access it in profile php as
>
>
> $details = $_SESSION['link']['$_GET['name']]
>
>
> --
> regards,
> Tom
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


Reply With Quote
  #4 (permalink)  
Old 07-26-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] Display Records (brief summary and full details)

* Thus wrote Pushpinder Singh Garcha (pgarcha@adelphia.net):
> Thanks Tom,
>
> I appreciate your help ! however I have a 2 quick questions...
>
> 1.) should we not save the names of the companies as $companies[$row]
> = w['company'];

I'm not sure in what context or what purpose you wish to do so.
There is, in general, nothing wrong with storing your information
like that.

> 2.) the approach of accessing the variable as $details =
> $_SESSION['link']['$_GET['name']] is not
> working , when I try to echo the $details is get something else.
> I am not sure how we use the
> $_SESSION[ ] [ ] with 2 variables as shown.
>


I assume you mean:
$_SESSION['link'][$_GET['name']];

If you could provide an example on how you set the array that would
be easier to let you know why your output is not comming back
right.

Please Compose a new message and type a subject when starting a new
topic.

Curt
--
"I used to think I was indecisive, but now I'm not so sure."
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:51 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0