/    Sign up×
Community /Pin to ProfileBookmark

Multiple Select statments

I am trying to select distinct last names (lname) and if there are duplicate people with the same last name to have them be redirected to a new page.

I cannot get the redirect to work.

[code=php]$query = “SELECT count(‘lname’) AS ‘count’ FROM cle_signup WHERE (SELECT DISTINCT lname FROM cle_signup WHERE lname=’$trimmed’)”;
$result = mysql_query($query) or die(“Couldn’t execute query: “.mysql_error());
while ($rows=mysql_fetch_array($result)){
$name = “<br /><p class=”subheadblue”>$rows[fname] $rows[lname]</p>”;
$total=$rows[‘count’];
if ($total > 1) {
echo ‘<p class=”subheadblue”><a href=”calculator2.php?name=’.$rows[‘fname’].’,’.$rows[‘lname’].'”>’;
echo “$name</a></p>”;
} else {
echo ‘<meta http-equiv=”refresh” content=”0;url=calculator3.php?name=’.$rows[‘lname’].'”>’;
}
}
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@beau_kangMar 18.2011 — Your redirect isn't working cause you only have [I]count [/I] as the only field being outputted. You need to include [I]fname[/I] and [I]lname[/I] in your SELECT statement in order to view them. Of course, if you do that then your count for the last names will always be 1.

I would suggest putting the results of the query into an array and then use that to see how many occurances of the last name is found that way. Not totally sure what you are trying to accomplish with this program, but those are my thoughts at least.
Copy linkTweet thisAlerts:
@beylahauthorMar 18.2011 — could you give me guidance on how to make the array - i have not done one before
Copy linkTweet thisAlerts:
@beau_kangMar 18.2011 — Well, here's an example of how to use an array in your case

[code=php]
$members = array();
$query = "SELECT lname, fname FROM cle_signup ORDER BY lname, fname";
$result = mysql_query($query) or die("Couldn't execute query: ".mysql_error());

while($get = mysql_fetch_array($query)) {
[INDENT]$members['fname'][] = $get['fname'];[/INDENT]
[INDENT]$members['lname'][] = $get['lname'];[/INDENT]
}
[/code]


That would be the easiest way to set up an array in your case, in my opinion. Other might have some better ideas on how to do it, but this should at least get you in the right direction. You might want to do a few google searches and see what else is out there.
Copy linkTweet thisAlerts:
@beylahauthorMar 18.2011 — i am sorry i am completely lost.

i dont understand how the array brings the lname into the count or = $trimmed
×

Success!

Help @beylah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...