error mssql_fetch_assoc() expects parameter 1 to be resource, string given in

bagaimana menyelesaikan masalah ini ?


<?php

   include "conection.php";

    if($_POST['id']) {
    $id = $_POST['id'];
    $sql = ("SELECT * from [cust_pric] where cp_cid='$id'");

    while($row = mssql_fetch_assoc($sql) ){
       echo'
            <table class="table">
                <tr>
                    <td>cp_cid</td>
                    <td>:</td>
                    <td>'.$row['cp_cid'].'</td>
                </tr>
                <tr>
                    <td>cp_mate</td>
                    <td>:</td>
                    <td>'.$row['cp_mate'].'</td>
                </tr>
                <tr>
                    <td>cp_hues</td>
                    <td>:</td>
                    <td>'.$row['cp_hues'].'</td>
                </tr>
            </table>
      ';


        }

    }

?>


avatar Obbytokun
@Obbytokun

186 Kontribusi 16 Poin

Diperbarui 5 tahun yang lalu

2 Jawaban:

coba seperti ini gan

<pre> &lt;?php

include "conection.php";

if($_POST[&#039;id&#039;]) {
$id = $_POST[&#039;id&#039;];
$sql = mysql_query($koneksi,&quot;SELECT * from [cust_pric] where cp_cid=&#039;$id&#039;&quot;);

while($row = mysql_fetch_assoc($sql) ){
   echo&#039;
        &amp;lt;table class=&quot;table&quot;&amp;gt;
            &amp;lt;tr&amp;gt;
                &amp;lt;td&amp;gt;cp_cid&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;:&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;&#039;.$row[&#039;cp_cid&#039;].&#039;&amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
                &amp;lt;td&amp;gt;cp_mate&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;:&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;&#039;.$row[&#039;cp_mate&#039;].&#039;&amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
                &amp;lt;td&amp;gt;cp_hues&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;:&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;&#039;.$row[&#039;cp_hues&#039;].&#039;&amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
        &amp;lt;/table&amp;gt;
  &#039;;


    }

}

?&gt; </pre>

avatar irya
@irya

59 Kontribusi 13 Poin

Dipost 5 tahun yang lalu

Kamu kurang querynya <pre> //contoh $result = mssql_query($koneksiDb,$sql); while($row = mssql_fetch_assoc($result)) { //code here } </pre> semoga membantu ^^

avatar bosque
@bosque

187 Kontribusi 104 Poin

Dipost 5 tahun yang lalu

Login untuk ikut Jawaban