Forum Moderators: coopster
$special_query = mysql_query("SELECT columnb FROM tablea WHERE columna=some_value");
$special_query2 = mysql_fetch_array($special_query);
print_r($special_query2);
--And this is the output
Array ( [0] => row1columnb [columnb] => row1columnb )
Am I not understanding the basics or something? The [0] turned out right but why is the next one labeled [columnb]? I also have many more values in columna that equal some_value... Please help!
Like this:
Array
(
[ 0] => 'value'
['field_name1'] => 'value',
[ 1] => 'value2',
['field_name2'] => 'value2',
[ 2] => 'value3',
['field_name3'] => 'value3',
...
) [edited by: Psychopsia at 6:32 pm (utc) on Sep. 16, 2006]
Because of your query. If you want all columns, then change your query to something like this:
$special_query = mysql_query("[b]SELECT * FROM tablea WHERE columna=some_value[/b]");
$special_query2 = mysql_fetch_array($special_query);
echo '<pre>';
print_r($special_query2);
echo '</pre>';
Good luck!
[pre]
$special_query = mysql_query("SELECT * FROM tablea WHERE columna=some_value");
while($row = mysql_fetch_array($special_query)) {
echo '<pre>';
print_r($row);
echo '</pre>';
}
[/pre] There is more information regarding this subject in our library [webmasterworld.com]. Here's one such thread: [webmasterworld.com...]
I hope this is what you are looking for. By the way, Welcome to WebmasterWorld! (I forgot to welcome you).
Best of luck! ;)
TABLEA
COLUMNA ¦ COLUMNB
a ¦ 1
a ¦ 2
a ¦ 3
a ¦ 4
b ¦ 1
b ¦ 2
c ¦ 3
Let's say I wanted to have an array of all values in COLUMNB where COLUMNA=a. How would I form that query in PHP?
I'm sorry for all the confusion!
[pre]
$colb = [url=http://www.php.net/manual/en/function.array.php]array[/url]();
$special_query = mysql_query("SELECT columnb FROM tablea WHERE columna=some_value");
while($row = mysql_fetch_array($special_query)) {
[url=http://www.php.net/manual/en/function.array-push.php]array_push[/url]($colb,$row['columnb']);
}
echo '<pre>';
print_r($colb);
echo '</pre>';
[/pre] Hope this is it! Good luck :)
$colb = array();
$special_query = mysql_query("SELECT interests FROM student_interest WHERE email_address='" . $_SESSION['Username'] . "'");
while($row = mysql_fetch_array($special_query))
{
array_push($colb,$row['interests']);
}
echo '<pre>';
print_r($colb);
echo '</pre>';