/    Sign up×
Community /Pin to ProfileBookmark

MySQL Question

Alright, I am not quite sure how to do this, hopefully I can explain it well enough so someone can help me. It OUGHT to be simple, I just cant seem to figure it out.

[CODE]$query1 = “SELECT id, name FROM dyn”;
$results1 = mysql_query($query1) or die(mysql_error());

while ($dyn = mysql_fetch_assoc($results1)) {
foreach ($dyn as $a) {
echo $a;
echo “<br />”;
}
}[/CODE]

That is straightforward. There are 11 occurrences that this query outputs. And I only want one of them, particularly I want the one where $dyn[‘id’] = $ahop[‘id’] (another variable I have on this page.

What would be the best way to do this?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ShmohelauthorNov 14.2004 — Of course, I spend 45 minutes trying to figure it out, I resort to posting on the boards, and 2 minutes later it occurs to me.

For anyone else, this is what I did:

<i>
</i>$dyn = mysql_fetch_assoc($results1);
if ($dyn['id'] = $ahop['id']) {
foreach ($dyn as $a) {
echo $a;
echo "&lt;br /&gt;";
}
}
Copy linkTweet thisAlerts:
@Paul_JrNov 14.2004 — [i]Originally posted by Shmohel [/i]
<i>
</i>$dyn = mysql_fetch_assoc($results1);
if ($dyn['id'] [color=red][b]=[/b][/color] $ahop['id']) {
foreach ($dyn as $a) {
echo $a;
echo "&lt;br /&gt;";
}
}
[/QUOTE]

That should be two equals signs ("=="); = is the assignment operator, whereas == is the comparison operator.
×

Success!

Help @Shmohel 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.19,
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,
)...