scaleautostyle Posted July 4, 2010 Share Posted July 4, 2010 I made a table in my while to display the result of the query. everything work NUMBER 1. but now I want to put a header at the top of this table to identify each column. I try to make an other table just before the while with the same size of TD width than my table do in the while but... doesn't work.. hum in fact it work... it gave me a table but the width is not the same as the one I got in the while loop. this is my final code without the header. if someone can help me finding a way to solve this problem it will be VERY appreciate yours sebastien this is the code <?php include_once("db_connection.php"); if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; //-query the database table $sql="SELECT kit_id, kit_number, kit_name, description, manufacturer_kit, manufacturer_reel, engine_detail, year_prod_kit, year_prod_reel, scale, image_id FROM kit WHERE kit_name LIKE '%" . $name ."%' OR description LIKE '%" . $name . "%' OR manufacturer_kit LIKE '%" . $name ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $description =$row['description']; $manufacturer_kit=$row['manufacturer_kit']; $kit_id=$row['kit_id']; $kit_number=$row['kit_number']; $kit_name=$row['kit_name']; $engine_detail=$row['engine_detail']; $year_prod_reel=$row['year_prod_reel']; $scale=$row['scale']; $image_id=$row['image_id']; echo " <table align=center width=\"990\" border=\"\">\n"; echo " <tr>\n"; echo" <td align=center width='83'> $manufacturer_kit \n"; echo" <td align=center width='25'> $scale \n"; echo" <td align=center width='60'> $kit_number \n"; echo" <td align=center width='290'> $kit_name \n"; echo" <td width='400'> $description \n"; echo" <td align=center width='50'> $year_prod_reel \n"; echo" <td align=center width='35'> $engine_detail \n"; echo" <td width='75'> <img src='".$image_id."' width='75' height='50'/>"; echo " </tr>\n"; echo " </table>\n"; } } else{ echo "<p>Please enter a search query</p>"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/206678-an-easy-one-for-you-how-to/ Share on other sites More sharing options...
lore_lanu Posted July 4, 2010 Share Posted July 4, 2010 If I understand correctly, couldn't you just move your <table> tag out of the while loop and make a row of table headers there? That way the headers won't repeat while the the results will be displayed underneath. It seems that you are creating a new table for each row of data. Also: This is assuming your data is outputting correctly... and you don't seem to be closing your <td> tags.... Link to comment https://forums.phpfreaks.com/topic/206678-an-easy-one-for-you-how-to/#findComment-1080926 Share on other sites More sharing options...
shortysbest Posted July 4, 2010 Share Posted July 4, 2010 try this? <?php include_once("db_connection.php"); if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; //-query the database table $sql="SELECT kit_id, kit_number, kit_name, description, manufacturer_kit, manufacturer_reel, engine_detail, year_prod_kit, year_prod_reel, scale, image_id FROM kit WHERE kit_name LIKE '%" . $name ."%' OR description LIKE '%" . $name . "%' OR manufacturer_kit LIKE '%" . $name ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set echo " <table align=center width=\"990\" border=\"\">\n"; while($row=mysql_fetch_array($result)){ $description =$row['description']; $manufacturer_kit=$row['manufacturer_kit']; $kit_id=$row['kit_id']; $kit_number=$row['kit_number']; $kit_name=$row['kit_name']; $engine_detail=$row['engine_detail']; $year_prod_reel=$row['year_prod_reel']; $scale=$row['scale']; $image_id=$row['image_id']; echo " <tr>\n"; echo" <td align=center width='83'> $manufacturer_kit \n"; echo" <td align=center width='25'> $scale \n"; echo" <td align=center width='60'> $kit_number \n"; echo" <td align=center width='290'> $kit_name \n"; echo" <td width='400'> $description \n"; echo" <td align=center width='50'> $year_prod_reel \n"; echo" <td align=center width='35'> $engine_detail \n"; echo" <td width='75'> <img src='".$image_id."' width='75' height='50'/>"; echo " </tr>\n"; } echo " </table>\n"; } else{ echo "<p>Please enter a search query</p>"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/206678-an-easy-one-for-you-how-to/#findComment-1080928 Share on other sites More sharing options...
Ruzzas Posted July 4, 2010 Share Posted July 4, 2010 try this? <?php include_once("db_connection.php"); if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; //-query the database table $sql="SELECT kit_id, kit_number, kit_name, description, manufacturer_kit, manufacturer_reel, engine_detail, year_prod_kit, year_prod_reel, scale, image_id FROM kit WHERE kit_name LIKE '%" . $name ."%' OR description LIKE '%" . $name . "%' OR manufacturer_kit LIKE '%" . $name ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set echo " <table align=center width=\"990\" border=\"\">\n"; while($row=mysql_fetch_array($result)){ $description =$row['description']; $manufacturer_kit=$row['manufacturer_kit']; $kit_id=$row['kit_id']; $kit_number=$row['kit_number']; $kit_name=$row['kit_name']; $engine_detail=$row['engine_detail']; $year_prod_reel=$row['year_prod_reel']; $scale=$row['scale']; $image_id=$row['image_id']; echo " <tr>\n"; echo" <td align=center width='83'> $manufacturer_kit \n"; echo" <td align=center width='25'> $scale \n"; echo" <td align=center width='60'> $kit_number \n"; echo" <td align=center width='290'> $kit_name \n"; echo" <td width='400'> $description \n"; echo" <td align=center width='50'> $year_prod_reel \n"; echo" <td align=center width='35'> $engine_detail \n"; echo" <td width='75'> <img src='".$image_id."' width='75' height='50'/>"; echo " </tr>\n"; } echo " </table>\n"; } else{ echo "<p>Please enter a search query</p>"; } } } ?> Gosh that is the most uncleaned code ive ever seen. I dont understand how you work with that. Link to comment https://forums.phpfreaks.com/topic/206678-an-easy-one-for-you-how-to/#findComment-1080937 Share on other sites More sharing options...
scaleautostyle Posted July 4, 2010 Author Share Posted July 4, 2010 was to tired. so now it work like I want.. so this is the code I got. o if someone else got the same problem you will got a working code to start sorry for the one who told me it's the worst uncleaned code he seen... but the quote code you got is not mine. check VS this one. anyway. thanks to everybody to guide me in the good direction. will post an other question for an other problem. yours sebastien <?php include_once("db_connection.php"); if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; //-query the database table $sql="SELECT kit_id, kit_number, kit_name, description, manufacturer_kit, manufacturer_reel, engine_detail, year_prod_kit, year_prod_reel, scale, image_id FROM kit WHERE kit_name LIKE '%" . $name ."%' OR description LIKE '%" . $name . "%' OR manufacturer_kit LIKE '%" . $name ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-make the header of the table echo " <table align=center width=\"990\" border=\"\">\n"; echo " <tr>\n"; echo" <td nowrap align=center width='83'> kit manufacturer \n"; echo" <td nowrap align=center width='25'> scale \n"; echo" <td nowrap align=center width='60'> kit number \n"; echo" <td nowrap align=center width='290'> kit name \n"; echo" <td nowrap width='400'> description \n"; echo" <td nowrap align=center width='70'> year of reel production of car \n"; echo" <td nowrap align=center width='70'> complete engine detail\n"; echo" <td nowrap align=center width='75'> Picture\n"; echo " <tr>\n"; //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $description =$row['description']; $manufacturer_kit=$row['manufacturer_kit']; $kit_id=$row['kit_id']; $kit_number=$row['kit_number']; $kit_name=$row['kit_name']; $engine_detail=$row['engine_detail']; $year_prod_reel=$row['year_prod_reel']; $scale=$row['scale']; $image_id=$row['image_id']; //-create table of item during he while loop echo " <table align=center width=\"990\" border=\"\">\n"; echo" <td nowrap align=center width='83'> $manufacturer_kit \n"; echo" <td nowrap align=center width='25'> $scale \n"; echo" <td nowrap align=center width='60'> $kit_number \n"; echo" <td nowrap align=center width='290'> $kit_name \n"; echo" <td nowrap width='400'> $description \n"; echo" <td nowrap align=center width='70'> $year_prod_reel \n"; echo" <td nowrap align=center width='70'> $engine_detail \n"; echo" <td nowrap width='75'> <img src='".$image_id."' width='75' height='50'/>"; echo " </tr>\n"; echo " </table>\n"; echo " </tr>\n"; echo " </table>\n"; } } else{ echo "<p>Please enter a search query</p>"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/206678-an-easy-one-for-you-how-to/#findComment-1080962 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.