Jump to content

search problem


zura08

Recommended Posts

i had problem when i do the search result. i want to make if key in data in search textbox,all the data will appear in the textfield. this if my example code.

$conn=mysql_connect('localhost','root','');

mysql_select_db("zns_inventori", $conn);

 

if (!empty($_POST['carian'])){

$carian = $_POST['carian'];

 

$sql = "SELECT * FROM stok where Kod_siri LIKE '%$carian%'";

$result = mysql_query($sql);

$bil_rekod = mysql_num_rows($result);

if ($bil_rekod <= 0)

{

echo "<br><center><font face='Verdana' color ='blue' size='4' >MAAF, Carian Anda Tidak Berjaya. No Pendaftaran yang Anda Masukkan Tiada Dalam Pangkalan Data.<br><br>";

}

else

{

 

?>

   

    <form id="form1" name="form1" method="post" action="">

  <table width="501">

                <tr>

                  <td height="37" class="style12">Kod Siri </td>

                  <td class="style12">:</td>

                  <td><label>

                    <input type="text" name="textfield" id="Kod_siri" value="<?php echo $Kod_siri ?>" />

                  </label></td>

                </tr>

                <tr>

                  <td width="176" height="37" class="style12">Nama Produk </td>

                  <td width="18" class="style12">:</td>

                  <td width="285"><input type="text" name="textfield2" id="Nama_item" value="<?php echo $nama_item?>" /></td>

                </tr>

                <tr>

                  <td height="36" class="style12">Kategori Produk </td>

                  <td class="style12">:</td>

                  <td><input type="text" name="textfield3" id="Jenis_item" value="<?php echo $jenis_item?>"  /></td>

                </tr>

                <tr>

                  <td height="33" class="style12">Kuantiti</td>

                  <td class="style12">:</td>

                  <td><input type="text" name="textfield4" id="Kuantiti" value="<?php echo $Kuantiti?>"  /></td>

                </tr>

                <tr>

                  <td height="40" class="style12">Harga (RM) </td>

                  <td class="style12">:</td>

                  <td><input type="text" name="textfield5" id="Harga" value="<?php echo $Harga?>" /></td>

                </tr>

              </table>

            </form>

<?php

while ($row = mysql_fetch_array($result)) {

?>

  <tr>

    <td><?php echo($row['Kod_siri'])?></td>

    <td><?php echo($row['Nama_item'])?></td>

    <td><?php echo($row['Jenis_item'])?></td>

    <td><?php echo($row['Kuantiti'])?></td>

    <td><?php echo($row['Harga'])?></td>

 

 

Link to comment
https://forums.phpfreaks.com/topic/130259-search-problem/
Share on other sites

you mean like this (untested)

$conn=mysql_connect('localhost','root','');
mysql_select_db("zns_inventori", $conn);

if (!empty($_POST['carian'])){
$carian = $_POST['carian'];

$sql = "SELECT * FROM stok where Kod_siri LIKE '%$carian%'";
$result = mysql_query($sql);
$bil_rekod = mysql_num_rows($result);
if ($bil_rekod <= 0)
{   
         echo "<br><center><font face='Verdana' color ='blue' size='4' >MAAF, Carian Anda Tidak Berjaya. No Pendaftaran yang Anda Masukkan Tiada Dalam Pangkalan Data.<br><br>";
   }
   else
   {
while ($row = mysql_fetch_array($result)) {
?>
         
          <form id="form1" name="form1" method="post" action="">
           <table width="501">
                <tr>
                  <td height="37" class="style12">Kod Siri </td>
                  <td class="style12">:</td>
                  <td><label>
                    <input type="text" name="textfield" id="Kod_siri" value="<?php echo($row['Kod_siri'])?>" />
                  </label></td>
                </tr>
                <tr>
                  <td width="176" height="37" class="style12">Nama Produk </td>
                  <td width="18" class="style12">:</td>
                  <td width="285"><input type="text" name="textfield2" id="Nama_item" value="<?php echo($row['Nama_item'])?>" /></td>
                </tr>
                <tr>
                  <td height="36" class="style12">Kategori Produk </td>
                  <td class="style12">:</td>
                  <td><input type="text" name="textfield3" id="Jenis_item" value="<?php echo($row['Jenis_item'])?>"  /></td>
                </tr>
                <tr>
                  <td height="33" class="style12">Kuantiti</td>
                  <td class="style12">:</td>
                  <td><input type="text" name="textfield4" id="Kuantiti" value="<?php echo($row['Kuantiti'])?>"  /></td>
                </tr>
                <tr>
                  <td height="40" class="style12">Harga (RM) </td>
                  <td class="style12">:</td>
                  <td><input type="text" name="textfield5" id="Harga" value="<?php echo($row['Harga'])?>" /></td>
                </tr>
              </table>
            </form>
<?php
}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675510
Share on other sites

your missing

$row = mysql_fetch_array($result);

 

add here

if ($bil_rekod <= 0)
{	
		echo "<br><center><font face='Verdana' color ='blue' size='4' >MAAF, Carian Anda Tidak Berjaya. Kod Siri yang Anda Masukkan Tiada Dalam Pangkalan Data.<br><br>";
}
else
{
$row = mysql_fetch_array($result); //<--------------
?>

Link to comment
https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675792
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.