Jump to content
WebFlake
  • 0

PHP response


Battlezz

Question

hello, i am currently trying to get the data back from sql / database aka invoice data.

 

the method im currently using is 

$user_in = (\IPS\Db::i()->select('*', 'nexus_invoices', 'i_member',$member_id ))->first();

but the problem is the ->first(); is its only responding the first invoice, if there is 2 

 

wondering if their is any other way to get all data with the correct member id
 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
$users_in = (\IPS\Db::i()->select('*', 'nexus_invoices', 'i_member',$member_id ));


foreach ($users_in as $user_in) {
	//example usage of it
	//echo $user_in['ps_id']
}

also, using first-> without checking it will give internal server error. If you only want to get first query the way you should use is:

$user_in = (\IPS\Db::i()->select('*', 'nexus_invoices', 'i_member',$member_id ));

if (count($user_in) > 0) {
	$user_in = $user_in->first();
}

 

Also, forgot to mention, you should put your where statement in array.

array('i_member=?', $member_id')

 

Edited by SamCheets
Link to comment
Share on other sites

  • 0

Well, `->first()` is named for what it's used for. Getting the first results from the query. If you have multiple records you want to use, then remove the `->first()` and treat the variable `$user_in` as a collection. That means you either need to iterate on the result and do something or use it as a whole. With the correct member id is where you set the `where` clause for your query.

If something is unclear, please refer to the developer documentation: https://invisioncommunity.com/developers/docs/general/

Link to comment
Share on other sites

  • 0
1 hour ago, Stevew said:

Well, `->first()` is named for what it's used for. Getting the first results from the query. If you have multiple records you want to use, then remove the `->first()` and treat the variable `$user_in` as a collection. That means you either need to iterate on the result and do something or use it as a whole. With the correct member id is where you set the `where` clause for your query.

If something is unclear, please refer to the developer documentation: https://invisioncommunity.com/developers/docs/general/

do you have any sort of example, i cannot find anything on the documentation about this.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...