Jump to content

[SOLVED] using both numeric keys and associative keys in mysql_fetch_array


Recommended Posts

here is a query:

$query = mysql_query("SELECT * FROM table WHERE field='$this'");

 

now I make an array from the results:

$row = mysql_fetch_array($query);

 

 

Yes I realize you can use a while statement to use associate keys to call on each row of the result, and then do something, but I specifically DO NOT WANT TO DO THIS

 

Here I sum up the results:

$total = mysql_num_rows($query); //lets say $total = 5

 

 

I now want to call a specific row # and then call a certain field from that row

 

let's say a field is named 'whateverfield'

 

so I want to say look in $row[0]

        and now look for the value of $row['whateverfield'] in this particular row

 

 

can this be done? without a while statement?

 

I want to do this for example:

 

for ($i=0; $i<=$total; $i++) {

//call an associative key from a specific row from the $row array

}

 

 

-thanks

 

Once I was thinking like you then I found a class to do this job

I use a class that has a member function named adv_output()

That Outputs the Following

Array
(
    [0] => Array
        (
            [id] => 2
            [usr] => Sunanda
            [psw] => N2M0YThkMDljYTM3NjJhZjYxZTU5NTIwOTQzZGMyNjQ5NGY4OTQxYg==
            [sex] => male
            [age] => 18
            [country] => India
            [occupation] => Same as Neel
            [about] => I am About To test it
        )

    [1] => Array
        (
            [id] => 3
            [usr] => nbs
            [psw] => MDNkZTZjNTcwYmZlMjRiZmMzMjhjY2Q3Y2E0NmI3NmVhZGFmNDMzNA==
            [sex] => male
            [age] => 17
            [country] => India
            [occupation] => Say Helo
            [about] => I am About To test it
        )

And it has also a output() function that Outputs

Array
(
    [id] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 4
            [3] => 5
        )

    [usr] => Array
        (
            [0] => Sunanda
            [1] => nbs
            [2] => girl
            [3] => new_girl
        )

I think you need the Second one.

I've got it from http://zigmoyd.sourceforge.net/man/db.php#browse

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.