Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

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