Jump to content

How to use simple foreach ?


MagicFire

Recommended Posts

Hi,

 

I would like to use this simple php cycle. I have an array of strings, lets say

 

$list = array ('name1','name2','name3');

 

and with each of this elements I need to go thru this array and do something like this:

 

foreach($list as $item){
    $stav = $db->Execute("SELECT * FROM `".$table."` WHERE `id_skype`='".$item."'");
    $id=$shop['status'];
    switch($id){
	  case "0":
	    $filename="unknown";
	    break;
	  case "1":
	    $filename="offline";
	    break;
	  case "2":
	    $filename="online";
	   break;
	  case "3":
	    $filename="away";
	    break;
	  case "4":
	    $filename="xa";
	    break;
	  case "5":
	    $filename="dnd";
	    break;
	  default:
	    $filename="offline";
	    break;
   }

 

But it seems that he don't do the loop even once. Where is the problem?

 

And second problem. Am I able to assign variable value to variable name? Example:

 

self::smarty->assign($variable_name,$variable_value);

 

It would be very usefull for me in the loop shown above. Because I need to separate individual states of each user.

 

Thanks

Link to comment
Share on other sites

I'm sorry. There should be $shop instead $stav. Second question is about the loop posted here. In array list are three names (but could be more or less), which I need later pass to the template. This procedure I need to show Skype status of users defined in $list. The reason why I take it from database is that the procedure of checking status is a little longer for direct access.

But because I don't know how many are them or which one will be used in template (it could be all or just two of them), I need the array, that would have the array key identical to the user names.

So that I can in template get something like this:

states['name1'] = 2

without any needs for changing or adding some code to the loop.

But I need the variable filename too, because I'm using my own pictures of Skype status. I have one php script, which was doing that directly in pure PHP way ( not with using PS DB interface), but I stucked in sending

header('Content-Type: image/png');

. I don't know why, this script works perfectly in Joomla. I guess I'm missing something.

Edited by MagicFire (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...