Page 1 of 1

Resource ID #6 issues

Posted: Mon Apr 17, 2006 10:47 pm
by tristanlee85
Here is my code:

Code: Select all

$getmanager="SELECT name FROM members WHERE user = '$fedex_username'";
$manager=mysql_query($getmanager);
When $manager is called, "Resource ID #6" is echo'd. I tried mysql_result() and that didn't work either. What's going on?

Posted: Mon Apr 17, 2006 10:50 pm
by RobertGonzalez
mysql_query returns the resource id of the query. You need to fetch the array using mysql_fetch_array() in order to get the data out.

Code: Select all

<?php
$query = "SELECT name FROM members WHERE user = '$fedex_username'";
$result = mysql_query($result) or die();
while ($row = mysql_fetch_array($result)) {
    $my_array = $row;
}
?>
Now access your data from within the array $my_array.

PS You could also echo your data from with the while loop also. I like to set the data into arrays for use later. This is just personal preference.

Posted: Mon Apr 17, 2006 10:59 pm
by tristanlee85
Well, I did this and it worked:

Code: Select all

$getmanager="SELECT name FROM members WHERE user = '$fedex_username'";
$manager=mysql_query($getmanager);
$manager_name = mysql_fetch_row($manager);
And then later on down the page I echoed out the "name" like this:

Code: Select all

<? echo "value=\"$manager_name[0]\">";
It worked, but I'm not sure why it worked. I saw this example on another post. Why do I use the [0]?

Posted: Mon Apr 17, 2006 11:02 pm
by RobertGonzalez
0 in that case happens to be the index of the array you are using. The array should be set up something like $array[int_index]['dbfieldname']. You can use a for loop to run through it or other looping procedure.