0

i know this have been asked here for many times but i really couldn't figure out how to do this. im getting this from wordpress sql request

$name = $wpdb->get_results("SELECT Chipset FROM gpu", ARRAY_N);

Array
(
    [0] => Array
        (
            [0] => GeForce GTX 670
        )

    [1] => Array
        (
            [0] => fasdasd
        )

    [2] => Array
        (
            [0] => test
        )

    [3] => Array
        (
            [0] => GeForce GTX 670
        )

    [4] => Array
        (
            [0] => GeForce GTX 560 Ti
        )

)

and for price

$price = $wpdb->get_results("SELECT Price FROM gpu", ARRAY_N);

Array
(
    [0] => Array
        (
            [0] => 403
        )

    [1] => Array
        (
            [0] => 50
        )

    [2] => Array
        (
            [0] => 288
        )

    [3] => Array
        (
            [0] => 288
        )

    [4] => Array
        (
            [0] => 288
        )

)

i need to create this format of array

Array
(
    [0] => Array
        (
            [text] => GeForce GTX 670
            [value] => 403 
        )

    [1] => Array
        (
            [text] => fasdasd
            [value] => 50
        )

    [2] => Array
        (
            [text] => test
            [value] => 288
        )

)

If you know how to get results from two columns in one query and work with that array you can. Also i wanna ask you guys if you could recommend me some good learning material where can i learn this type of combining arrays or how to use bunch of foreach's because i can't get my head around this

Ok solution to my problem is to change sql query but i want to know how to combine these arrays anyway for future.

2
  • 5
    Why can't you do SELECT Price, Chipset from gpu? Commented Apr 8, 2013 at 15:00
  • If you know this has been asked here many times, then why post another question instead of searching? Commented Apr 8, 2013 at 15:02

1 Answer 1

2

All you need to do is SELECT Chipset, Price FROM gpu to fetch both columns in a single query. Since you're working with Wordpress, a good place to start is just looking through their documentation. It's going to be helpful to get a good grasp on SQL as well. I'd recommend Tizag's MySQL Tutorial for starters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.