Link to home
Start Free TrialLog in
Avatar of array007
array007

asked on

Using mysql substring result in php mysql_fetch_array

Looks like I got myself in a new problem
I know "AS" is redundant I just added it as a trial.

I am not able to use the result in a mysql_fetch_array
Note: the query runs fine and returns expected results

$result = $db->query("
SELECT DISTINCT
SUBSTRING (username,1,1)
AS username
FROM 
my_table
WHERE
username LIKE '%'
");
 
echo '<select name="username">';
		
while ($row=$db->fetch_array($result) )
{
	$username=$row['username'];
	echo '<option>';
	echo"$username";
	echo"</options>";
}

Open in new window

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

please try this:
$result = $db->query("
SELECT DISTINCT SUBSTRING (t.username,1,1) AS username
FROM my_table t
WHERE t.username LIKE '%'
");
 

Open in new window

Avatar of array007
array007

ASKER

Thanks, but I still get only blank in the DD box
sorry, the space before the "(" is not good:
$result = $db->query("
SELECT DISTINCT SUBSTRING(t.username,1,1) AS username
FROM my_table t
WHERE t.username LIKE '%'
");

Open in new window

I made the correction before testing
so it stillis getting empty DD box
but aren't you posting the same query twice I do not see nay change, or is it me?
I think the problem is in line 18 of your snippet:

echo"</options>";

Change this to:

echo"</option>";
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You did it that space was killing it
thank you
Really...? </options> was not the problem?
as the end of a select session
it did not generate any error on  my local machine lamp Apache 2 PHP 5.2+ MySQlL5
altough while I had that typo I did not try passing any values
my focus was on the "blank" DD box value.
It should not produce any error message, it is just invalid html... I first expected it would result in a blank dropdown, but it makes sense that it does not, as <option> has an optional end tag... it is legal (in html, not in xhtml) to write <select><option>A<option>B<option>C</select>.