zura08 Posted October 27, 2008 Share Posted October 27, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/ Share on other sites More sharing options...
MadTechie Posted October 27, 2008 Share Posted October 27, 2008 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 } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675510 Share on other sites More sharing options...
zura08 Posted October 27, 2008 Author Share Posted October 27, 2008 i already try the code u give me but the data still cannot appear in the textfield... :'( Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675533 Share on other sites More sharing options...
MadTechie Posted October 27, 2008 Share Posted October 27, 2008 check the sql statment.. can verify the output.. are you getting the expected results? Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675568 Share on other sites More sharing options...
zura08 Posted October 27, 2008 Author Share Posted October 27, 2008 yes i'm expected result if i put the data.for example if i put the serial number in the search field..all the information about the item will appear in the textfield. Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675638 Share on other sites More sharing options...
MadTechie Posted October 27, 2008 Share Posted October 27, 2008 okay.. so whats the problem ? Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675725 Share on other sites More sharing options...
zura08 Posted October 27, 2008 Author Share Posted October 27, 2008 the problem is the data not appear in the textfield. this i attach the page. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675732 Share on other sites More sharing options...
zura08 Posted October 27, 2008 Author Share Posted October 27, 2008 please help me what the problem with my coding... Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675780 Share on other sites More sharing options...
MadTechie Posted October 27, 2008 Share Posted October 27, 2008 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); //<-------------- ?> Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675792 Share on other sites More sharing options...
zura08 Posted October 27, 2008 Author Share Posted October 27, 2008 the data still not appear...i already put that statement n try make search but the it still not working.. Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-675801 Share on other sites More sharing options...
MadTechie Posted October 28, 2008 Share Posted October 28, 2008 Short of "data still not appear" can you give some more detail ? heres some things that make help if the form appearing? is the SQL statment correct any errors etc please add others Quote Link to comment https://forums.phpfreaks.com/topic/130259-search-problem/#findComment-676235 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.