For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > January 2006 > Re: How can I get just one row from selected column?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How can I get just one row from selected column?
Jim Michaels

2006-01-29, 9:55 pm


"Hilarion" <hilarion@SPAM.op.SMIECI.pl> wrote in message
news:dpgdhj$t9k$1@news.onet.pl...
>
>
> I think that Leszek wanted to ask "how can I get just one COLUMN from...",
> in which case LIMIT clause will not be what he looks for.
> As others explained - Leszek used the PHP mysql functions output in
> a wrong way, and it had nothing to do with SQL syntax.



Actually, he wanted "just one row from a selected column". If he was
speaking about a *particular* row, I would suggest a WHERE clause (SELECT
$kolumna FROM $tablea WHERE id=5), or a counter+if approach.
I am not sure exactly what it is he is trying to do.. maybe trying to pick
out a row to put a SELECTED attribute on the <option> on or something?
(speak up!)
$count=1;
while($wiersz=mysql_fetch_array($wynik,M
YSQL_ASSOC))
{
echo "<option value=$wiersz>$wiersz</option> <br />";
if (4==count) {
do something here
}
$count++;
}

the problem with this is, how are you going to guarantee that there will
always be more than 4 rows, if this is what he is really asking?

And if he is wanting just the first row from a SELECT, yeah, a LIMIT 1 would
be good to append on the statement. but I would suggest the following code
below in case you get no rows (you can drop the else part if you want):
He should remove the <br /> tag out of the <select></select> area - it
should not be beside an <option> tag. it's illegal - it will really mess
things up for the browser and you may get inconsistent cross-browser
renderings. I think maybe what he was trying for was \n instead, which the
browser ignores, but looks good when viewing code.
$wynik=mysql_query($zapytanie);
if ($wiersz=mysql_fetch_array($wynik,MYSQL_
ASSOC)) {
echo "<option value=$wiersz>$wiersz</option>\n";
} else {
echo "<!--no rows.-->";
}


>
>
> Hilarion



Jim Michaels

2006-01-29, 9:55 pm


"Jim Michaels" <jmichae3@yahoo.com> wrote in message
news:sZqdnfGR7oThFEDeRVn-vQ@comcast.com...
>
> "Hilarion" <hilarion@SPAM.op.SMIECI.pl> wrote in message
> news:dpgdhj$t9k$1@news.onet.pl...


OOPS! code fix. array referenced wrong. didn't catch this until a later
post. fixed below.
[color=darkred]
>
>
> Actually, he wanted "just one row from a selected column". If he was
> speaking about a *particular* row, I would suggest a WHERE clause (SELECT
> $kolumna FROM $tablea WHERE id=5), or a counter+if approach.
> I am not sure exactly what it is he is trying to do.. maybe trying to pick
> out a row to put a SELECTED attribute on the <option> on or something?
> (speak up!)

$count=1;
while($wiersz=mysql_fetch_array($wynik,M
YSQL_ASSOC))
{
echo "<option value=$wiersz[$kolumna]>$wiersz[$kolumna]</option> <br
/>";
if (4==count) {
do something here
}
$count++;
}
>
> the problem with this is, how are you going to guarantee that there will
> always be more than 4 rows, if this is what he is really asking?
>
> And if he is wanting just the first row from a SELECT, yeah, a LIMIT 1
> would be good to append on the statement. but I would suggest the
> following code below in case you get no rows (you can drop the else part
> if you want):
> He should remove the <br /> tag out of the <select></select> area - it
> should not be beside an <option> tag. it's illegal - it will really mess
> things up for the browser and you may get inconsistent cross-browser
> renderings. I think maybe what he was trying for was \n instead, which
> the browser ignores, but looks good when viewing code.

$wynik=mysql_query($zapytanie);
if ($wiersz=mysql_fetch_array($wynik,MYSQL_
ASSOC)) {
echo "<option value=$wiersz[$kolumna]>$wiersz[$kolumna]</option>\n";
} else {
echo "<!--no rows.-->";
}
>
>
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com