/    Sign up×
Community /Pin to ProfileBookmark

Select multiple fields

Hey guys,

I have a database that I can’t edit… a screenshot of it is attached.

This db has a unique ‘subscriber_id’ for each person, and it stores their first name under ‘field_id’ 1 and the last name under ‘field_id’ 2…. if I’m saying that correctly. The attached image should help explain that.

I want to query this database so that it outputs the first name and last name, then a <br>

So far I have the following code (very simple):

[code=php]<?php
$con = mysql_connect(“localhost”,”xxx”,”xxx”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db(“pintmeis_pmsignup”, $con);

$result = mysql_query(“SELECT `pm_subscriber_data`.* FROM pm_subscriber_data WHERE field_id=’1′”);

while($row = mysql_fetch_array($result))
{
echo $row[‘value’];
echo “<br />”;
}

mysql_close($con);
?>[/code]

And this correctly displays the first name. But I have no idea how to make it display the last name.

I tried this (and other variations of it):
[B]WHERE field_id=’1′ OR field_id=’2′[/B]
but this outputs the first name and last name on separate lines, and it orders the names wrong in many cases.

I’m at a loss here… any help would be much appreciated.

Thanks so much!

I have this code executed on this page if it helps:
[url]http://www.pintmeisters.com/subscribers.php[/url]

EDIT: forgot to attach image

[upl-file uuid=9bb9bf25-12bd-4455-afca-b006781de80c size=30kB]ss1.jpg[/upl-file]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@dtm32236authorAug 27.2008 — Nevermind - I got it all figured out:

[code=php]$result = mysql_query("SELECT pm_subscriber_data.* FROM pm_subscriber_data WHERE field_id IN (1, 2) ORDER BY subscriber_id ASC, field_id ASC");

$tags = array(1=>'<li>%s', 2=>' %s</li>');

echo "<ol class='registered'>";
while($row = mysql_fetch_array($result)){
printf($tags[$row['field_id']], $row['value']);
}
echo "</ol>";[/code]
×

Success!

Help @dtm32236 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.18,
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,
)...