/    Sign up×
Community /Pin to ProfileBookmark

easy question: brain fart

Okay… not difficult, I know, but I can’t figure it out! I’ve got a Select statement in PHP. It only selects one field, but I cannot get that one field into PHP as a variable. It’s just the one and it’s been selected… how do I use it now?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ellisglAug 15.2007 — Select as in mysql?

if so - $row = mysql_fetch_assoc($qry);

then $var = $row['field'];

If you're talking HTML -

<select name="blah">

<option value="whatever>What ever!</option>

</select>


Then it would be $var = $_POST['blah'];
Copy linkTweet thisAlerts:
@dz_boyauthorAug 15.2007 — Does that work if there will be [I]two [/I]records under the same field name?
Copy linkTweet thisAlerts:
@ellisglAug 16.2007 — Not sure what you mean.
Copy linkTweet thisAlerts:
@dz_boyauthorAug 16.2007 — I have customers in a SQL table, and they all have unique customer id numbers. Each customer can join several different groups, which also have unique id numbers. I have a table with just a group id column and a customer id column. If said customer is part of two groups, my "select group id where customer id =X" statement in PHP for the database will return two records. Does the method you posted earlier work even if the field name in the $row[' '] will be the same for both returned records?

I guess my question is how can I return two records from the same column in the table. I'm sorry this was put so confusingly.
Copy linkTweet thisAlerts:
@ellisglAug 16.2007 — Ah - then do

while($row = mysql_fetch_asscoc($qry)

{

echo $row['group_id'],'<br />';

}


That will loop thru all the records that would be related to that user.
Copy linkTweet thisAlerts:
@dz_boyauthorAug 16.2007 — Can that loop be used to store each group id in a separate variable, rather than print it? So if a user is a member of 3 groups, can a variable be set for each of the three that way? I ask this because it seems as if you just changed the echo statement to assign the variable, that same variable name would be used and therefore overwrite itself each time the loop executed. Am I wrong? Sorry for the questions... I'm very new at this.
Copy linkTweet thisAlerts:
@dz_boyauthorAug 17.2007 — Alright-- I've got code for this problem now.

[CODE]$sql2 = 'SELECT item_id from List_Xref WHERE list_id = ''. $list_id .'';
$result2 = @mysql_query($sql2);
while($row2 = mysql_fetch_asscoc($result2)
{
$item_id = $row2['item_id'];
}[/CODE]


Will this store each item_id in a separate variable? I won't be able to control how many item_ids there are at any given time, so a loop of some kind will be needed, right? My goal, once I have stored all the item_id's, is to use them to reference another table with more information about each item. Any thoughts?
×

Success!

Help @dz_boy 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 6.13,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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