0

I have a PHP table in this format:

$Output = array (
    'strSMD' => array (
        'name' => 'blabla',
        'server' => 'https:/blabla.com',
        'profile' => 'https://blabla.com/Search.aspx?query=My+Name',
        'profiletext' => "<li class=\"smd\">My profile at Bla Bla</li>",
        'linktext' => "<li class=\"smd\">Buy from Bla Bla</li>"         
    ),
    'strSMP' => array (
        'name' => 'someother',
        'server' => 'https://someother.com',
        'profile' => 'https://www.someother.com/my-name/',
        'profiletext' => "<li> Some other text....</li>",
        'linktext' => "<li>Just another text</li>"          
    ),
    'strMN' => array(
        'name' => 'onemore',
        'server' => 'https://www.onemore.com',
        'profile' => 'https://www.onemore.com/profile/my-name/',
        'profiletext' => "<li> One More text</li>",
        'linktext' =>  "<li"> One more linktext</span></li>"
    ),
        //etc
);

Now I want to put it in a database. I thought about two tables, one with vendorcodes (strSMD, etc.) and one with vendor info (name, server, etc.) But I can't find out a query that gives this output array in PHP. Join gives me a flat array with the vendorcodes as array value. Does anybody have thoughts about a structure/query?

8
  • 1
    Why do you think codes must be in a separate table? What else would be in that table? Commented Jan 26 at 16:02
  • 1
    This just looks like three records of data with a string value to uniquely identify them. It's not really clear to me why this needs to be more than one table, or what prevents querying that table. What exactly did you try and what specific problem did you encounter? Commented Jan 26 at 16:10
  • Nothing, I just can't findout to keep the labels separate. I don't want: array( 'vendorcode' =>'strSMD', 'name' => 'blabla', 'server' => 'https:/blabla.com', 'profile' => 'blabla.com/Search.aspx?query=My+Name', 'profiletext' => "<li class=\"smd\">My profile at Bla Bla</li>", 'linktext' => "<li class=\"smd\">Buy from Bla Bla</li>" ),//etc as output, But how can I have the stringvalue to identify them and keep the array structure? Commented Jan 26 at 16:12
  • 2
    And what's the problem with doing something like $data = []; foreach ($result as $row) { $data[$row['code']] = [whatever you want to put into this array];}? Commented Jan 26 at 16:15
  • 1
    @Edward please note that mysql is a relational database, so its results will always be in a tabular format. You can try to generate json as string in a column value, but even that will not look exactly like your current php structure and your query will be a lot more complicated. You need to transform your data in php to the structure in your question as Your Common Sense suggested. Since the 3 arrays have the same keys, I would say you need a single table to store them. Commented Jan 26 at 17:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.