Andrea,
> I am a serious newbie (like less than two weeks & never programmed before),
> so I hope my code doesn't suck too bad & this isn't a really bad question...
> but here goes...
>
> I would like to modify this query so that it doesn't return the username,
> realname, and office results each time. The way the query is now, I see the
> username, realname & office results duplicated for each 'alias' result that
> is in the data. Instead, I'd like to see the username, realname & office
> only once & a list of the associated 'alias' (es) underneath it. If anyone
> can help w/ some "semi-real" code, that would be great. Since I'm new, it
> really helps to have code that actually reflects my field names so that I
> can learn from it. I appreciate any help you can provide. Thanks in
> advance! ~Andrea
> ____________________________________
>
> $query = "select users.username, users.realname, users.office,
> users.location, users.office_phone, users.alt_phone, users.password,
> alias.alias from users, alias
> where users.username like '%".$searchterm."%'
> and users.username = alias.username";
>
> $result = mysql_query($query);
>
> $num_results = mysql_num_rows($result);
>
> echo "<p>Number of Users found: ".$num_results."</p>";
>
> for ($i=0; $i <$num_results; $i++){
> $row = mysql_fetch_array($result);
> echo "<p><strong>".($i+1).". Username: ";
> echo htmlspecialchars( stripslashes($row["username"]));
> echo "<br>Real Name: ";
> echo htmlspecialchars( stripslashes($row["realname"]));
> echo "<br>Office: ";
> echo htmlspecialchars( stripslashes($row["office"]));
> echo "<br>Alias: ";
> echo htmlspecialchars( stripslashes($row["alias"]));
With respect to your request for code, in fact you need to take two steps: 1 to
understand the program/script
logic required to achieve your aims, then 2 code that logic in PHP. One of the tools
for the first step is
"pseudo-code". This offers an answer to your (logic) question in pseudo-code (with
regrets that lack of time
precludes the next step):
If you think about it, your display has (probably) a main heading, and maybe a footer.
What lies in between
(apart from white space) is groups of lines, where each group is defined/identified by
the username (etc). You
want to display the groups so that the first line identifies the group, and any
ensuing lines within the group
do not duplicate the information.
So think about writing the first line in a group. Then how would you display the
ensuing lines in each group?
How would you know if the next line belongs with the same group, or starts a new one?
Apart from ensuring that
you use all of the rows in the resultset (and no more!?) that's about the nub of it...
retrieve first row from resultset
while not eod
note group's username
display (full) line
retrieve next row
while line's username = group's username and not eod
display line (without username etc)
retrieve next row
end while line
end while not eod
NB "eod" = end of data
(rather than working of num-rows it works off the boolean response of a call to
retrieve from the resultset, eg
mysql_fetch_array())
Regards,
=dn
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]