elentz Posted December 8, 2007 Share Posted December 8, 2007 I am trying to set up a simple output to my screen the results from a query. The query will get infor from a Mysql DB from several tables. That part I have worked out. The embarassing part is that I want to take each field I get from the query and echo or print it to the screen. Eventually I want to take this information and apply it to FPDF and make a PDF out of it. Tight now I am stumped on getting the info to a page to make sure I am extracting the info. Here is what I have so far: //****************************************************** <?php // Connection to the Database //****************************************************** $conn = mysql_connect("localhost", "admin", "xxxxxxxxx"); mysql_select_db ('vtigercrm50',$conn); //****************************************************** //******Query to get the ticket information************* $sql = 'SELECT' . ' `vtiger_troubletickets`.`ticketid`,' . ' `vtiger_ticketcf`.`cf_534`,' . ' `vtiger_ticketcf`.`cf_536`,' . ' `vtiger_ticketcf`.`cf_538`,' . ' `vtiger_ticketcf`.`cf_540`,' . ' `vtiger_troubletickets`.`title`,' . ' `vtiger_troubletickets`.`description`,' . ' `vtiger_troubletickets`.`parent_id`,' . ' `vtiger_account`.`accountid`,' . ' `vtiger_accountshipads`.`ship_city`,' . ' `vtiger_accountshipads`.`ship_street`,' . ' `vtiger_accountshipads`.`ship_code`,' . ' `vtiger_accountshipads`.`ship_state`,' . ' `vtiger_account`.`phone`,' . ' `vtiger_accountscf`.`cf_472`,' . ' `vtiger_accountscf`.`cf_476`,' . ' `vtiger_accountscf`.`cf_464`,' . ' `vtiger_accountscf`.`cf_478`,' . ' `vtiger_accountscf`.`cf_484`,' . ' `vtiger_accountscf`.`cf_486`,' . ' `vtiger_accountscf`.`cf_468`' . ' FROM' . ' `vtiger_troubletickets`' . ' Inner Join `vtiger_ticketcf` ON `vtiger_troubletickets`.`ticketid` = `vtiger_ticketcf`.`ticketid`' . ' Inner Join `vtiger_account` ON `vtiger_troubletickets`.`parent_id` = `vtiger_account`.`accountid`' . ' Inner Join `vtiger_accountshipads` ON `vtiger_account`.`accountid` = `vtiger_accountshipads`.`accountaddressid`' . ' Inner Join `vtiger_accountscf` ON `vtiger_account`.`accountid` = `vtiger_accountscf`.`accountid` Where 'vtiger_troubletickets'.'ticketid' = '17271''; //************End Query**************** $result=mysql_query($sql); $title = mysql_result(title); echo $title; ?> Thanks for any suggestions anyone might have Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 8, 2007 Share Posted December 8, 2007 Better to use mysql_fetch_assoc then mysql_result: $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo '<pre>' . print_r($row, true) . '</pre>'; $row will be an associative array. I use print_r above to display the contents of the $row array. Quote Link to comment Share on other sites More sharing options...
elentz Posted December 8, 2007 Author Share Posted December 8, 2007 Thanks wildteen for the speedy reply. That got the whole array, now how do I selectively show the fields I want? Lets say I want to show cf_476 and ticketid. What I need is to be able to put those individual results into a cell in the pdf. Thanks Quote Link to comment Share on other sites More sharing options...
jacksonmj Posted December 8, 2007 Share Posted December 8, 2007 Since mysql_fetch_assoc returns the row as an array with the elements labelled using the field names, you should be able to access them through $row['cf_476'] and $row['ticketid']. Quote Link to comment Share on other sites More sharing options...
elentz Posted December 8, 2007 Author Share Posted December 8, 2007 Thank you all very much your suggestions got me over my hump!! Have a great weekend! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.