|
|
|
|
|
для: mindless
(07.02.2007 в 11:21)
| | конечно можно, но с учетом того, что в теле цикла есть закоменченные операторы, полагал, что "промежуточные" значения в цикле используются для каких-то доп. целей =) | |
|
|
|
|
|
|
|
для: ZuArt
(07.02.2007 в 09:26)
| | спасибо!
для получения строки вне цикла можно еще добавить оператор соединения
$this->names.=mysql_field_name($this->fields, $i). " ";
|
самый простой выход | |
|
|
|
|
|
|
|
для: mindless
(07.02.2007 в 02:46)
| | Загвоздка тут...
$this->names=mysql_field_name($this->fields, $i). " ";
$this->names=str_replace(" ",",",$this->names); // ПЕРЕНАЗНАЧЕНИЕ переменной
echo $this->names; // выводит СНАЧАЛА a, ПОТОМ b,ПОТОМ c,ПОТОМ d, // вывод ее значение на текущий "оборот" цикла - получается строка a,b,c,d за несколько выводов =)
|
можно сделать таким образом:
$tmp = array();
for ($i = 0; $i < $this->columns-1; $i++)
{
$tmp[$i]=mysql_field_name($this->fields, $i). " ";
$tmp[$i]=str_replace(" ",",",$tmp[$i]);
//$this->poz=strrpos($this->names, ",");
//$this->names=substr_replace($this->names, "", $this->poz, 1);
}
$this->names = implode(',', $tmp);
echo $this->names;
|
Этот вариант подойдет, если надо обрабатывать каждое значение в каждом "обороте" цикла, а после него иметь полную строку. | |
|
|
|
|
|
|
| в цикле получаю строку a,b,c,d,
обращаюсь (echo $this->names;) к этой строке вне цикла получаю- d,
- последнее значение - как сохранить значение вне цикла?
<?
function connect()
{
$this->links=mysql_connect($this->host, $this->login, $this->pass);
mysql_select_db($this->data);
$this->fields = mysql_list_fields($this->data,$this->table, $this->links);
$this->columns = mysql_num_fields($this->fields);
for ($i = 0; $i < $this->columns-1; $i++) {
$this->names=mysql_field_name($this->fields, $i). " ";
//$this->names=trim($this->names);
$this->names=str_replace(" ",",",$this->names);
echo $this->names; // выводит a,b,c,d,
//$this->poz=strrpos($this->names, ",");
//$this->names=substr_replace($this->names, "", $this->poz, 1);
//
}
echo $this->names; //выводит d,
$this->connect_error=mysql_error();
}
}
?>
|
| |
|
|
|
|