$own_company = fetch_owned_companies($user_info['uid']); if ($news['companyid'] == $own_company[0]['companyid']) { $viewer_user_lvl = 7; } else { $viewer_user_lvl = user_lvl($news['id']); }
Make Array Dynamic
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Make Array Dynamic
I need to make the [0] dynamic so that it displays all of the companies in the array.
Re: Make Array Dynamic
Use a while loop to fetch the data instead.
As a general example:
As a general example:
$query = mysql_query("SELECT `title` FROM `posts`"); while ( $row = mysql_fetch_assoc($query) ) { if ( 'condition here' ) { $var = 1; } }Is that what you mean?
Please check out my CodeCanyon items.
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Re: Make Array Dynamic
Tino,Tino wrote:Use a while loop to fetch the data instead.
As a general example:
$query = mysql_query("SELECT `title` FROM `posts`"); while ( $row = mysql_fetch_assoc($query) ) { if ( 'condition here' ) { $var = 1; } }Is that what you mean?
I am using a while loop in my function to fetch the data.
The <pre> is displayed as...
Output
Array ( => Array ( [companyid] => 1 [companyname] => s [companytag] => [companywebsite] => http://s.com [country] => 1 [state] => 0 [city] => [industry] => 4 [stage] => 2 [capitalrequested] => [guestviews] => 0 [iviews] => 3 [eviews] => 3 ) )I suppose what I should have said is that the array is dynamic, but I am not performing a dynamic check.
Re: Make Array Dynamic
This code looks familiar
You would need to us ea foreach loop to loop over all of the returned companies
You would need to us ea foreach loop to loop over all of the returned companies
foreach ($own_company as $company){ // do something }But it may be better to create a new function that checks the database to see if the given company id belongs to the logged in use, which you could do with a single query.
SELECT COUNT(`companid`) FROM `companies` WHERE `companyid` = {$cid} AND `user_id` = {$GLOBALS['user_info']['uid']}I can't really remember the field names that are used, but that should give you the idea.
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Re: Make Array Dynamic
Yes, that is exactly what I am going to do. I'm just going to make an is_admin function. That should do what I need to in a much nicer way.jacek wrote:This code looks familiar
You would need to us ea foreach loop to loop over all of the returned companies
foreach ($own_company as $company){ // do something }But it may be better to create a new function that checks the database to see if the given company id belongs to the logged in use, which you could do with a single query.
SELECT COUNT(`companid`) FROM `companies` WHERE `companyid` = {$cid} AND `user_id` = {$GLOBALS['user_info']['uid']}I can't really remember the field names that are used, but that should give you the idea.
Re: Make Array Dynamic
was there not already an is_company_owner() type function ?unemployment wrote:Yes, that is exactly what I am going to do. I'm just going to make an is_admin function. That should do what I need to in a much nicer way.
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Re: Make Array Dynamic
No, I checked and there wasn't.jacek wrote:was there not already an is_company_owner() type function ?unemployment wrote:Yes, that is exactly what I am going to do. I'm just going to make an is_admin function. That should do what I need to in a much nicer way.
I'm getting this error on my new function. Warning: mysql_result(): Unable to jump to row 0 on MySQL result index.
function is_admin($uid, $cid) { $uid = (int)$uid; $cid = (int)$cid; $sql = "SELECT `users`.`id` AS `uid`, `companies`.`companyid` AS `cid`, `companies`.`adminid` AS `aid` FROM `companies` LEFT JOIN `users` ON `users`.`id` = companies.adminid WHERE `users`.`id` = {$uid} AND `companies`.`companyid` = {$cid}"; $user = mysql_query($sql); return (mysql_result($user, 0) == '1') ? true : false; }
Re: Make Array Dynamic
Can't you just do
$sql = "SELECT COUNT(`companies`.`companyid`) FROM `companies` WHERE `companies`.`adminid` = {$uid} AND `companies`.`companyid` = {$cid}";??
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Re: Make Array Dynamic
Yupjacek wrote:Can't you just do
$sql = "SELECT COUNT(`companies`.`companyid`) FROM `companies` WHERE `companies`.`adminid` = {$uid} AND `companies`.`companyid` = {$cid}";??