/    Sign up×
Community /Pin to ProfileBookmark

SQL and loops

I have this form which consists of the following:

[QUOTE]

<TR><TD><input type=text name=’name’ style=’width:80px;’></TD>
<TD><input type=text name=’blah’ style=’width:90px;’></TD>
<TD><input type=text name=’blahblah’ style=’width:200px;’></TD>
<TD><select NAME=’rating’>
<option VALUE=”> — Rating —
<OPTION VALUE=’Blah’>Blah
<OPTION VALUE=’Blah’>Blah
</select><br>

[/QUOTE]

What I want to do is to have it displayed as many times as there are results in the database for that user. All I know at the moment is it’d start with $query = mysql_query (“select * from list where username=’$blah'”);

Thanks in advance.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@pyroAug 07.2003 — Ok, what we do then is loop through the values that it returns, with something like this:

[code=php]while($row = mysql_fetch_array($query)) {
echo $row[0]; #will echo the value of the first column in each row
}[/code]
Copy linkTweet thisAlerts:
@MacMyDayauthorAug 07.2003 — Thanks for the start. Thing is that only selects the first column, for me. I need it to select everything and display it.
Copy linkTweet thisAlerts:
@pyroAug 07.2003 — Try this out:

[code=php]while($row = mysql_fetch_array($query)) {
foreach ($row as $value) {
echo $value." "; #the ." " is to add a space after each item it prints
}

echo "<br>";
}[/code]
Copy linkTweet thisAlerts:
@MacMyDayauthorAug 07.2003 — Getting there ? It now just displays everything twice.
Copy linkTweet thisAlerts:
@pyroAug 07.2003 — Can I see your complete code?
Copy linkTweet thisAlerts:
@MacMyDayauthorAug 07.2003 — Sure, but it's really only what you've given me.

<?

include ("header.php");

include ("connect.php");

$username = getusername();

$result = mysql_query ("select * from list where username='$username'");

while ( $row = mysql_fetch_array ($result)) {

foreach ( $row as $value ) {

echo $value." " ;

}

echo "<br>" ;

}

?>
[/QUOTE]
×

Success!

Help @MacMyDay 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.27,
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,
)...