Jump to content

Recommended Posts

I'm (still) reading information from my helpdesk using

$query_string="SELECT j.job_ticket_id, c.first_name,c.last_name,j.report_date,j.last_updated,l.location_name,j.room,j.subject,j.Question_text,s.status_type_name FROM `JOB_TICKET` j join `CLIENT` c on j.client_id = c.client_id join `STATUS_TYPE` s on j.status_type_id = s.status_type_id join `LOCATION` l on j.location_id = l.location_id where j.deleted=0 and (s.status_type_name <> 'resolved' and s.status_type_name <> 'closed' and s.status_type_name <> 'denied' and s.status_type_name <> 'cancelled') order by location_name,room;"; 
$result = mysql_query($query_string, $global_dbh)
or die("display_db_query:" . mysql_error());
while($row=mysql_fetch_array($result)) {
   $return[] = $row;
   }

which gives me an array with all the information I need that looks like this:

Array
(
    [0] => 77
    [job_ticket_id] => 77
    [1] => First1
    [first_name] => First1
    [2] => Last1
    [last_name] => Last1
    [3] => 2009-09-30 14:01:57
    [report_date] => 2009-09-30 14:01:57
    [4] => 2009-09-30 14:03:57
    [last_updated] => 2009-09-30 14:03:57
    [5] => Lewis Building (US)
    [location_name] => Lewis Building (US)
    [6] => 
    [room] => 
    [7] => digitising software
    [subject] => digitising software
    [8] => Could the tape digitising software be put back on UPP-LANG-X02 please
    [Question_text] => Could the tape digitising software be put back on UPP-LANG-X02 please
    [9] => Open
    [status_type_name] => Open
)
Array
(
    [0] => 355
    [job_ticket_id] => 355
    [1] => First
    [first_name] => First
    [2] => Last
    [last_name] => Last
    [3] => 2009-10-16 11:11:30
    [report_date] => 2009-10-16 11:11:30
    [4] => 2009-10-16 11:15:47
    [last_updated] => 2009-10-16 11:15:47
    [5] => Lewis Building (US)
    [location_name] => Lewis Building (US)
    [6] => 
    [room] => 
    [7] => You tube
    [subject] => You tube
    [8] => Although there have been updates and youtube is working in Y10 office, it is not working in room 3 UP-R03 cpmputer. I would really appreciate an early resolution of this as I rely on History clips for use with my students
    [Question_text] => Although there have been updates and youtube is working in Y10 office, it is not working in room 3 UP-R03 cpmputer. I would really appreciate an early resolution of this as I rely on History clips for use with my students
    [9] => Open
    [status_type_name] => Open
)

 

I'm then running through the array creating a table from the data, a new table for each room.

What I'm stuck on is making the "table create" function automatically adapt to the number of fields in the array.  I shoudl have 10 fields returned by the query but I've got 20.  I'd like to have it so that the table header row has the names of the fields returned and so that if I change the Sql query to return more or less fields it automatically compensates.  What I'm not sure of is why I've got 20 array fields returned for 10 fields in the query.

 

How can I get a list the array elements so that I can choose just the named ones?

 

or is there a more elegant way...

Link to comment
https://forums.phpfreaks.com/topic/179057-sql-query-read-into-an-array/
Share on other sites

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.