Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old January 17th, 2002, 03:00 PM
wisconsinative's Avatar
wisconsinative wisconsinative is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: Somewhere in the desert of Arizona
Posts: 63 wisconsinative User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m
Reputation Power: 7
Modify a MySQL query using PHP

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. Does this make sense? Can anyone help? Thank you in advance!!

____________________________________

$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"]));

Reply With Quote
  #2  
Old January 17th, 2002, 04:20 PM
NoXcuz's Avatar
NoXcuz NoXcuz is offline
Wiking
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Sep 2000
Location: Sweden
Posts: 3,608 NoXcuz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 49 m 27 sec
Reputation Power: 11
Since you're new here, I'll go easy on you...
It's considered bad and rude to crosspost as this place, so please don't do so in the future.
Try the answer in the MySQL forum...

//NoXcuz
__________________
UN*X is sexy!
who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep

Reply With Quote
  #3  
Old January 17th, 2002, 04:27 PM
wisconsinative's Avatar
wisconsinative wisconsinative is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: Somewhere in the desert of Arizona
Posts: 63 wisconsinative User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m
Reputation Power: 7
Yeah... I'm really sorry... I noticed that not too many people post in this area, so I thought the other forum might be better. I realized that after I posted here. Won't happen again...

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Modify a MySQL query using PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway