Jump to content
  • 0

array()


banyman
 Share

Question

Подскажите, пожалуйста....

Нужно вытащить из БД данные.. не пойму, как с помощью массива выстроить конструкцию вида:

$aMenus = array(
'Строка данных',
'Еще Строка данных',
'И еще Строка данных',
...
);

Нужные данный хранятся в одном поле БД $rowMenu[3]

В итоге хочу получить:

	$aMenus = array(
'.......???.....',
);

$i = 1;
foreach ( $aMenus as $key => $record ) {
$sResult .= '<li class="item-'.$i.'"><a href="."><span class="bling"><span class="bullet">';
$sResult .=$record;
$sResult .= '</span></span></a></li>';
$i++;
}

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Задача вообще такая.

Нужно вывести меню вида:

	  <ul class="left">
<li class="item-1"><a href="."><span class="bling"><span class="bullet">Меню </span></span></a></li>
<li class="item-2"><a href="."><span class="bling"><span class="bullet">Меню </span></span></a></li>
<li class="item-3 two-line"><a href="."><span class="bling"><span class="bullet">Меню Меню </span></span></a></li>
<li class="item-4 small"><a href="."><span class="bling"><span class="bullet">Меню </span></span></a></li>
<li class="item-5"><a href="."><span class="bling"><span class="bullet">Меню </span></span></a></li>
<li class="item-6"><a href="."><span class="bling"><span class="bullet">Меню </span></span></a></li>
<li class="item-7"><a href="."><span class="bling"><span class="bullet">Меню </span></span></a></li>
<li class="item-8"><a href="."><span class="bling"><span class="bullet">Меню </span></span></a></li>
<li class="item-9 special two-line"><a href="."><span class="bling"><span class="bullet">Меню </span></span></a></li>
</ul>

Все это циклом выводится из БД, но нужно при этом пронумеровать класс стилей item-1 item-2 и т.д. от 1 до 8

Link to comment
Share on other sites

  • 0

ТЕма закрыта :D

$SQL = "SELECT * FROM `table` WHERE 1";
$rs = mysql_query($SQL);
$aMenus = array();
while($data=mysql_fetch_assoc($rs)) {
$aMenus[] = $data['menu'];
}

$i = 1;
foreach ( $aMenus as $key => $record ) {
$sResult .= '<li class="item-'.$i.'"><a href="."><span class="bling"><span class="bullet">';
$sResult .=$record;
$sResult .= '</span></span></a></li>';
$i++;
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy