|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
||||
|
||||
|
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"])); |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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...
|
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Modify a MySQL query using PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|