Forum Moderators: coopster

Message Too Old, No Replies

Add variable to array - problem

extract value from DB and needs to be put into array.

         

fraksken

8:49 am on Jan 4, 2012 (gmt 0)

10+ Year Member



Hi,

I'm editing an admin panel for my convenience of throwing out the spammers. Though I'm getting some problems. Below are the parts that matter and the things I've tried already.
The system allows people to input their first and last name, It also allows them to place their partner their first and last name in there.
If a partner's name is entered, the account gets a 'couple' number (ID number associated with the partner), if not, it's zero (0)

So I want to display the names of user and partner if it's a couple.

Spambots give duplicate names.

Making initial array:
 $sQuery = "
SELECT
`tp`.`ID` as `id`,
`tp`.`NickName` AS `username`,
`tp`.`Headline` AS `headline`,
`tp`.`City` AS `city`,
`tp`.`DescriptionMe` AS `description`,
`tp`.`Email` AS `email`,
`tp`.`Couple` AS `coupleid`,
`tp`.`FirstName` AS `firstname`,
`tp`.`LastName` AS `lastname`;
$aProfiles = $GLOBALS['MySQL']->getAll($sQuery);

I added the coupleid here so I can use it to determine if it's a couple and to extract the names of the linked account.

show code:

function show($aProfiles) {
$iEmailLength = 50;
$aItems = array();
foreach($aProfiles as $aProfile)
{
$sEmail = ( mb_strlen($aProfile['email']) > $iEmailLength ) ? mb_substr($aProfile['email'], 0, $iEmailLength) . '...' : $aProfile['email'];
// BREAK 1
$aItems[$aProfile['id']] = array(
'id' => $aProfile['id'],
'username' => $aProfile['username'],
'headline' => $aProfile['headline'],
'description' => $aProfile['description'],
'firstname' => $aProfile['firstname'],
'lastname' => $aProfile['lastname'],
'email' => $sEmail,
'full_email' => $aProfile['email'],
// BREAK 2
);
//BREAK 3
}
return $GLOBALS['oAdmTemplate']->parseHtmlByName('show.html', array(
'su_repeat:items' => array_values($aItems),
'paginate' => $sPaginate
));
}

Putting $couplefirstname = "test"; on break1 and 'cplfirst' => $couplefirstname on break2 gives me a test,
Putting $couplefirstname = $aProfile['coupleid']; on break1 and 'cplfirst' => $couplefirstname on break2 gives me nothing,
($aProfile['coupleid'] does not seem to work outside of the array)
Placing 'cplfirst' => $aProfile['coupleid'], on break2 gives me the profile number of the partner.
I also tried to put this on Break 1 and break 2, but neither seem to do the job:
$coupleid = $aProfiles['coupleid'];
if($coupleid != 0){
$couplefirstname = mysql_query("SELECT `FirstName` FROM `Profiles` WHERE `ID` = $coupleid");
$couplelastname = mysql_query("SELECT `LastName` FROM `Profiles` WHERE `ID` = $coupleid");
}
else{}

(for what I've gathered: since $aProfile['coupleid'] does not return any value outside of the array.)

Can somebody please help me?

I've tried to do the IF statement in the MYSQL query, but it gave me errors.
I'm not so very good with php or mysql.

fraksken

12:09 pm on Jan 4, 2012 (gmt 0)

10+ Year Member



Problem solved: typo in a variable.

coopster

3:27 pm on Jan 6, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Glad you got it sorted! And Welcome to WebmasterWorld, fraksken.

eelixduppy

4:04 pm on Jan 6, 2012 (gmt 0)



>> typo in a variable.

This could have been caught easily if you were viewing the errors properly. For a dev environment only, set the php error reporting level to E_ALL, and for MySQL related errors, you can print them out using mysql_error(). See links:

[php.net...]
[php.net...]