bagaimana membuat switch case tapi data dari database

 <?php
switch ($i) {
    case "apple":
        echo "i is apple";
        break;
    case "bar":
        echo "i is bar";
        break;
    case "cake":
        echo "i is cake";
        break;
}
?>
avatar Obbytokun
@Obbytokun

186 Kontribusi 16 Poin

Diperbarui 6 tahun yang lalu

7 Jawaban:

contoh datanya gimana ?

avatar aganovic85
@aganovic85

5 Kontribusi 0 Poin

Dipost 6 tahun yang lalu

<pre> SELECT (CASE WHEN id = "apple" THEN "i is apple" WHEN id = "bar" THEN "i is bar" WHEN id = "cake" THEN "i is cake" END) AS item FROM tableName </pre>

avatar gunalirezqimauludi
@gunalirezqimauludi

350 Kontribusi 243 Poin

Dipost 6 tahun yang lalu

<pre> &lt;?php

$uid = $_SESSION['uid']; $grp = $_SESSION['grp'];

include 'conection.php'; $sql=mssql_query("SELECT xh,name,flag FROM [appl_navi] JOIN [appl_role] on xh = ar_xh where flag&gt;0 and (ar_uid ='".$uid."' or ar_tid ='".$grp."' ) ");

while ($datasubmenu = mssql_fetch_assoc($sql)){

echo '

&lt;li class="dropdown"&gt; &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt; &lt;i class="fa fa-folder"&gt;&lt;/i&gt;'.$datasubmenu['name'].'&lt;b class="fa fa-plus dropdown-plus"&gt;&lt;/b&gt; &lt;/a&gt;'; while ($datasubmenu = mssql_fetch_assoc($sql)){

echo ' &lt;ul class="dropdown-menu"&gt; &lt;li class="dropdown"&gt;

&amp;lt;a href=&quot;#&quot; class=&quot;dropdown-toggle&quot; data-toggle=&quot;dropdown&quot;&amp;gt;
     &amp;lt;i class=&quot;fa fa-folder&quot;&amp;gt;&amp;lt;/i&amp;gt; &#039;.$datasubmenu[&#039;name&#039;].&#039;&amp;lt;b class=&quot;fa fa-plus dropdown-plus&quot;&amp;gt; &amp;lt;/b&amp;gt;
        &amp;lt;/a&amp;gt; 

&lt;ul class="dropdown-menu"&gt; '; while ($datasubmenu = mssql_fetch_assoc($sql)){

echo '

&amp;lt;li&amp;gt;&amp;lt;a href=&quot;

	&amp;lt;? SELECT (case when xh = &quot;10120110&quot; THEN 
				  &quot;chart.php&quot;
			when xh = &quot;10120120&quot; THEN 
				  &quot;blank_page&quot;
			when xh = &quot;10120150&quot; THEN 
				  &quot;chart2.php&quot;
			when xh = &quot;10120160&quot; THEN 
				  &quot;chart3.php&quot; 
			END) AS xh FROM [APPL_NAVI] ?&amp;gt;

&lt;i class="fa fa-caret-right"&gt;&lt;/i&gt; '.$datasubmenu['name'].'&lt;/a&gt;&lt;/li&gt; '; echo' &lt;/li&gt;';

}

}

}

?&gt; </pre> udah saya coba gan tapi gak berhasil link tidak berjalan

avatar Obbytokun
@Obbytokun

186 Kontribusi 16 Poin

Dipost 6 tahun yang lalu

message error nya apa?

avatar gunalirezqimauludi
@gunalirezqimauludi

350 Kontribusi 243 Poin

Dipost 6 tahun yang lalu

<a href=' https://drive.google.com/open?id=1fpe2Exhdvs6LTA7LtvK757c0oKlGnlO2 '> https://drive.google.com/open?id=1fpe2Exhdvs6LTA7LtvK757c0oKlGnlO2 </a>

kaya gini bang

avatar Obbytokun
@Obbytokun

186 Kontribusi 16 Poin

Dipost 6 tahun yang lalu

Itu url nya yg salah mas /home/<?=....

Url nya err, itu tag php nya nongol di url, coba mana script bagian nampilin href nya..

avatar gunalirezqimauludi
@gunalirezqimauludi

350 Kontribusi 243 Poin

Dipost 6 tahun yang lalu

mas itu masukin script yang mas kasih simpan nya di dalam href apa dimana ?

avatar Obbytokun
@Obbytokun

186 Kontribusi 16 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban