photo

Richard Wisniewski

shared this question
5 years ago

Employees Involved

photo

PIV Support

Admin

Statistics

3
Comments
576
Views

Relates to

Share

1
votes

ADOdb Lite and arrays

I am writing a new addon. I'm having issues using the ADOdb Lite commands. Essentially I am looking to return the results of a sql query (which returns only values in one column) into an array. I currently have this snippet of code that will show me the array structure.

  1. function mycomps_view_comps() {
  2. global $conn;
  3. $sql = 'SELECT listingsdb_id FROM mycomps WHERE userdb_id = 1';
  4. $recordSet = $conn->GetArray($sql);
  5. return print_r($recordSet);
  6. }
My print_r array result looks like this:

Array ( [0] => Array ( [0] => 567 [listingsdb_id] => 567 ) [1] => Array ( [0] => 359 [listingsdb_id] => 359 ) )

I only need values with [listingsdb_id]. The values would be imploded into a comma separated string.

How can I store just the listingsdb_id values into their own array?

Thanks again for taking the time to view my qustion.

Add Comment

Comments (3)

photo Employee
1

I would suggest using PHP's built-in PDO abstraction layer instead of ADODBlite as the latter will be going away at a future date.

http://php.net/manual/en/book.pdo.php

Otherwise:

  1. $sql = 'SELECT listingsdb_id FROM mycomps WHERE userdb_id = 1';
  2. $recordSet = $conn->Execute($sql);
  3. $listing_ID =$recordSet->fields['listingsdb_id'];

photo
1

Thank You.

I was unaware that was available in php. This leads me to ask, could show an example how to achieve the action above using the PHP PDO abstraction layer?

It would server as a fantastic starting example.

Thanks again and Happy New Year!

photo
1

Using ADOdb Lite I was able to create this function to create a string of the listing ID numbers separated by a comma into as a single variable:

  1. $sql = 'SELECT listingsdb_id FROM mycomps WHERE userdb_id = 1';
  2. $recordSet = $conn->execute($sql);
  3. $count = $recordSet->RecordCount();
  4. $display = '';
  5. while ($count != 0){
  6. if ($count > 1){
  7. $listing_ID = $recordSet->fields['listingsdb_id'];
  8. $display .= $listing_ID . ',';
  9. $recordSet->MoveNext();
  10. $count--;
  11. }else{
  12. $listing_ID = $recordSet->fields['listingsdb_id'];
  13. $display .= $listing_ID;
  14. $count--;
  15. }
  16. }
Thank you for your help. I look foward to an example of how to use PHP PDO to query the database. I'm not sure if we can use the global $conn or need to create a new variable for connection info.

Thanks again!

Leave Comment

photo

Attach files...

The file must be a jpg, gif, png, bmp, ico, pdf, doc, rtf, txt, zip or rar no more than 20M