Jump to content


[Resolved] PHP question


  • This topic is locked This topic is locked
6 replies to this topic

#1 Jayzon277

    Etomite Forum Newbie

  • Member
  • 12 posts

Posted 21 January 2008 - 07:45 PM

Hi!

I'd like to write a little snippet which lists all users on a certain page. My problem is: I can't get it to work properly. The database-query looks like this:
$data_members = $etomite->getIntTableRows(
                      $fields="fullname,email",
                      $from="user_attributes", 
                      $where="role=2",
                      $sort="",
                      $dir="ASC",
                      $limit="",
                      $push=true);

This works really well, I'm able to display the array's content with return_r etc.

My problem is: I can't find a correct foreach-command to list the array's content. I've got no idea about the foreach-command. I tried to google it & implement things I read, but nothing really worked.

Could someone please post a correct way to get the fullname & the e-mail-address for every member listed? I think I can add the html-stuff for myself. But I just can't get the foreach (which needs a further foreach included I think) to work.

Sorry for this stupid question, but I really can't find a way to get this working.

Greetings,

Jayzon

#2 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 21 January 2008 - 08:42 PM

Although you can do it manually using a foreach or for or while, etomite has built in API that help with this part of it too. I tried to link you to Ralph's tutorial that explains this well but the site is down at the moment, but you could try it later (see his profile).

The one I use the most is mergeCodeVariables($content="",$rs="",$prefix="{",$suffix="}",$oddStyle="",$evenStyle="",$tag="div")
where $content is your chunk of html using placeholders { } for insertion points for your data, $rs is the array yoou have above, $prefix and $suffix are the insertion tags, $oddStyle and $evenStyle allow you to set in-line styling or a class, and $tag allows you to optionally set a html container for each record.

$content="{fullname}{email}";
$output=$etomite->mergeCodeVariables($content, $data_members, ...etc);
return $output;

#3 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 22 January 2008 - 03:40 AM

Cris is correct, both in regard to my site being down and the use of a Chunk and mergeCodeVariables()... But, to answer your question about foreach() here, I'll give an example... It's basic but should get you going...

// attempt to abstract data from database
$data_members = $etomite->getIntTableRows(
  $fields="fullname,email",
  $from="user_attributes", 
  $where="role=2",
  $sort="",
  $dir="ASC",
  $limit="",
  $push=true); // $push tells the function to return the results as a multi-dimensional array

// if a resultset was returned, as an array in our case, process it
if($data_members)
{
  // loop through the resultset using foreach
  foreach($data_members as $row)
  {
    // render our desired output from the data row which is also an array
    $output .= "Name: {$row['fullname']}<br/>Email: {$row['email']}<br/><br/>";
  }
}

// return our rendered data to caller
return $output;


#4 Jayzon277

    Etomite Forum Newbie

  • Member
  • 12 posts

Posted 22 January 2008 - 10:07 AM

Thanks for your fast reply!

Now that I see the solution, it seems logic to me ;-)

I think I'll try the API-version first. Is that one in the documentation somewhere? Then sorry for not seeing!

I'll tell you here whether things worked out right or not.

Thanks once again!

Greetings,
Jayzon

#5 Jayzon277

    Etomite Forum Newbie

  • Member
  • 12 posts

Posted 24 January 2008 - 08:14 PM

Hi!

Your suggestions really work out great! I managed to get everything almost as I wanted it to. There's just one single issue I'm dealing with right now. Is it possible to change on of the {}-elements with php?
What I want to do exactly is:
strtolower(str_replace(" ","_","{fullname}"));
Simple reason is: There are pictures of every member named: firstname_lastname.jpg
Since I already have the full name, I'd only have to change it. Is this somehow possible?
The example above resultet in a "normal" fullname-output.

Thanks for any help!

Greetings,
Jayzon

#6 Jayzon277

    Etomite Forum Newbie

  • Member
  • 12 posts

Posted 24 January 2008 - 08:29 PM

Got it ;-)

I used the foreach, works great!

Thanks again for your help!

Greetings,
Jayzon


(see the result of this soon here: http://www.campusrel...mitglieder.html)

#7 Dean

    Loves Etomite Forums!

  • Admin
  • 4,758 posts
  • Gender:Male

Posted 24 January 2008 - 08:41 PM

Glad you got it sorted!

closed as no longer needed





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users