0

I want to get sql data for a gridjs table

var jobListAllData = [  
    ["Marketing Directortt", "Meta4Systems", "Vinninga, Sweden", "$250 - $800", "0-5 year", "Full Time"],  
    ["UI/UX designer", "Zoetic Fashion", "Cullera, Spain", "$400+", "0-2 year", "Part Time"],  
    ["Web Designer", "Force Medicines", "Ugashik, US", "$412 - $241 ", "3+ year", "Freelancer"],  
    ["Full Stack Engineer", "Syntyce Solutions", "Zuweihir, UAE", "$650 - $900", "0-1+ year", "Full Time"],  
    ["Assistant / Store Keeper", "Moetic Fashion", "Limestone, US", "$340 - $800", "0-3 year", "Intership"],  
    ["Project Manager", "Themesbrand", "California, US", "$400 - $600", "3+ year", "Part Time"],  
    ["Education Training", "Micro Design", "Germany", "$750 - $940", "1.5+ year", "Freelancer"],  
    ["Graphic Designer", "Digitech Galaxy", "Mughairah, UAE", "$160 - $230", "2-3+ year", "Full Time"],  
    ["React Developer", "iTest Factory", "KhabÄkhib, UAE", "$90 - $160", "5+ year", "Intership"],  
    ["Executive, HR Operations", "Micro Design", "Texanna, US", "$50 - $120", "1-5 year", "Part Time"],  
    ["Project Manager", "Meta4Systems", "Limestone, US", "$210 - $300", "0-2+ year", "Freelancer"],  
    ["Full Stack Engineer", "Force Medicines", "Ugashik, US", "$120 - $180", "2-5 year", "Part Time"],  
    ["Full Stack Engineer", "Digitech Galaxy", "Maidaq, UAE", "$900 - $1020", "3-5 year", "Full Time"],
    ["Marketing Director", "Zoetic Fashion", "Quesada, US", "$600 - $870", "0-5 year", "Freelancer"]  
];

this is the data format I have.

I want only:

[
    ["Marketing Directortt", "Meta4Systems", "Vinninga, Sweden", "$250 - $800", "0-5 year", "Full Time"],
    ["UI/UX designer", "Zoetic Fashion", "Cullera, Spain", "$400+", "0-2 year", "Part Time"],
    ["Web Designer", "Force Medicines", "Ugashik, US", "$412 - $241 ", "3+ year", "Freelancer"],
    ["Full Stack Engineer", "Syntyce Solutions", "Zuweihir, UAE", "$650 - $900", "0-1+ year", "Full Time"],
    ["Assistant / Store Keeper", "Moetic Fashion", "Limestone, US", "$340 - $800", "0-3 year", "Intership"],
    ["Project Manager", "Themesbrand", "California, US", "$400 - $600", "3+ year", "Part Time"],
    ["Education Training", "Micro Design", "Germany", "$750 - $940", "1.5+ year", "Freelancer"],
    ["Graphic Designer", "Digitech Galaxy", "Mughairah, UAE", "$160 - $230", "2-3+ year", "Full Time"],
    ["React Developer", "iTest Factory", "KhabÄkhib, UAE", "$90 - $160", "5+ year", "Intership"],
    ["Executive, HR Operations", "Micro Design", "Texanna, US", "$50 - $120", "1-5 year", "Part Time"],
    ["Project Manager", "Meta4Systems", "Limestone, US", "$210 - $300", "0-2+ year", "Freelancer"],
    ["Full Stack Engineer", "Force Medicines", "Ugashik, US", "$120 - $180", "2-5 year", "Part Time"],
    ["Full Stack Engineer", "Digitech Galaxy", "Maidaq, UAE", "$900 - $1020", "3-5 year", "Full Time"],
    ["Marketing Director", "Zoetic Fashion", "Quesada, US", "$600 - $870", "0-5 year", "Freelancer"]
]

I am trying this way but it doesn't work:

$resultset=mysqli_query($conn, "SELECT * FROM `campgain` ORDER BY id DESC");         

while( $record = mysqli_fetch_assoc($resultset) ) {
    
    $data.='['.$record[row1].','.$record[row2].','.$record[row3].','.$record[row4].'],';
}

$data="[$data]";

echo $data;
Pippo
  • 2,173
  • 2
  • 3
  • 16

1 Answers1

0

The request is not very clear, if you need to transform your fetched data in serialized JSON, you can do so:

$data = [];

while($record = mysqli_fetch_assoc($resultset)) {

    $data[] = [$record['row1'], $record['row2'], $record['row3'], $record['row4']];
}

echo json_encode ($data, JSON_PRETTY_PRINT);

I assume that rowX means columnX

Pippo
  • 2,173
  • 2
  • 3
  • 16