Page 1 of 1

Creating a table with 3 columns from DB

Posted: Fri Sep 05, 2003 2:18 am
by mudkicker
Hi again,

I have a question if you can help me or just give me an idea, it will be much appreciated. I have a product database and by showing the products. I show them in 1 column all the way down! But my client asked me to do this so that in 1 row will be 3 products. How can I create the structure? Do you have any ideas?

Posted: Fri Sep 05, 2003 3:06 am
by JayBird
show me the code you are using to produce one column, and i'll change it to produce 3.

Mark

Posted: Fri Sep 05, 2003 3:15 am
by mudkicker

Code: Select all

<?
					mysql_connect("localhost","farkgrup_webgues");
					mysql_select_db("farkgrup_farkgrup") or die ("Cannot connect to database");

					$query = mysql_query("SELECT `id`,`group`,`type`,`code`,`name` FROM `products` WHERE 1 AND `group` = '$group' AND `type` = '$type'");
					$gname = mysql_query("SELECT gname FROM groups WHERE gid='$group'");
					$tname = mysql_query("SELECT tname FROM types WHERE tid='$type'");

					if (mysql_error())
						{
							echo "Database Error : ";
							echo mysql_error();
						}

					$number = mysql_numrows($query);
					
					if ($number == "0")
					{
					echo "<br><br><br><center><font class='maintext'>Arad&#305;&#287;&#305;n&#305;z kriterlere göre ürün bulunamad&#305;!</font></center>";
					}
					else
					{
					$group = mysql_result($gname,"gname");
					$type = mysql_result($tname,"tname");
					
					echo "<tr><td><font color='#ff0000' class='a'>$group: $type</font></td>";
					echo "<td><a href='urunler.php' class='maintext'><center><b>Geri</b></center></a></td></tr>";
					$i = 0;	
					$smallpath = "_s.jpg";
					$largepath = ".jpg";

					while ($i < $number):


					$code = mysql_result($query,$i,"code");
					$name = mysql_result($query,$i,"name");

					echo "<tr>";
					echo "<td><b>Ürün Kodu: </b>$code<br><b>Ürün Ad&#305;: </b>$name</td><td><center><a href='english/images/";
					echo $code."".$largepath;
					echo "' target='_blank'><img src='english/images/";
					echo $code."".$smallpath;
					echo "' width='78' height='78' border='0'></a><br></center></td>";
					echo "</tr>";
				
					$i++;
					endwhile;
					}
				mysql_close();
				
?>

Posted: Fri Sep 05, 2003 3:57 am
by JayBird
Try this for size. i couldn't test it cos i don't have your DB.

Should give you a clue of how to achieve what you want though.

Any more probs, gimme a shout.

Code: Select all

<? 
               mysql_connect("localhost","farkgrup_webgues"); 
               mysql_select_db("farkgrup_farkgrup") or die ("Cannot connect to database"); 

               $query = mysql_query("SELECT `id`,`group`,`type`,`code`,`name` FROM `products` WHERE 1 AND `group` = '$group' AND `type` = '$type'"); 
               $gname = mysql_query("SELECT gname FROM groups WHERE gid='$group'"); 
               $tname = mysql_query("SELECT tname FROM types WHERE tid='$type'"); 

               if (mysql_error()) 
                  { 
                     echo "Database Error : "; 
                     echo mysql_error(); 
                  } 

               $number = mysql_num_rows($query); 
                
               if ($number == "0") 
               { 
               echo "<br><br><br><center><font class='maintext'>Arad&#305;&#287;&#305;n&#305;z kriterlere göre ürün bulunamad&#305;!</font></center>"; 
               } 
               else 
               { 
               $group = mysql_result($gname,"gname"); 
               $type = mysql_result($tname,"tname"); 
                
               echo "<tr><td><font color='#ff0000' class='a'>$group: $type</font></td>"; 
               echo "<td><a href='urunler.php' class='maintext'><center><b>Geri</b></center></a></td></tr>"; 
               $i = 0;    
               $smallpath = "_s.jpg"; 
               $largepath = ".jpg"; 

               //while ($i < $number): 
			   $result = mysql_query($query) or die(mysql_error());
			   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {


               //$code = mysql_result($query,$i,"code"); 
               //$name = mysql_result($query,$i,"name"); 

				$new_row = 1;

               if ($new_row == 1) {
			   		echo "<tr>"; 
				}
               echo "<td><b>Ürün Kodu: </b>$code<br><b>Ürün Ad&#305;: </b>".$line['name']."</td><td><center><a href='english/images/"; 
               echo $line['code']."".$largepath; 
               echo "' target='_blank'><img src='english/images/"; 
               echo $line['code']."".$smallpath; 
               echo "' width='78' height='78' border='0'></a><br></center></td>";  
			   if ($new_row == 3) {
			   		echo "</tr>";
					$new_row = 1;
				} else {
					$new_row++;
				}
			   //$i++; 
               //endwhile; 
               } 
            mysql_close(); 
             
?>
Mark

Posted: Fri Sep 05, 2003 5:56 am
by mudkicker
i can't do it. it doesn't work... any other ideas or a fresh script? :(

Posted: Fri Sep 05, 2003 5:57 am
by JayBird
there's no such thing as can't.

Can i view your original script running somewhere?

Posted: Fri Sep 05, 2003 6:01 am
by mudkicker
http://www.farkgrup.com/urunler.php

pick a thing. then another one will open. there you go. but this script is f*cked up... :(

Posted: Sat Sep 06, 2003 1:23 pm
by mudkicker
anyone have any other idea? :(

Posted: Sun Sep 07, 2003 1:46 pm
by mudkicker

Code: Select all

<?php
					mysql_connect("localhost","root","boot");
					mysql_select_db("farkgrup") or die ("Cannot connect to database");

					$query = mysql_query("SELECT `id`,`group`,`type`,`code`,`name` FROM `products` WHERE 1 AND `group` = '$group' AND `type` = '$type'");
					$gname = mysql_query("SELECT gname FROM groups WHERE gid='$group'");
					$tname = mysql_query("SELECT tname FROM types WHERE tid='$type'");

					if (mysql_error())
						{
							echo "Database Error : ";
							echo mysql_error();
						}

					$number = mysql_numrows($query);
					
					if ($number == "0")
					{
					?>
					<br><br><br>
					<center>
					<font class="maintext">
					Arad&#305;&#287;&#305;n&#305;z kriterlere göre ürün bulunamad&#305;!
					</font>
					</center>
					<?
					}
					else
					{
					$group = mysql_result($gname,"gname");
					$type = mysql_result($tname,"tname");
					
					echo "<tr><td><font color='#ff0000' class='a'>$group: $type</font></td>";
					echo "<td><a href='urunler.php' class='maintext'><center><b>Geri</b></center></a></td></tr>";
					
					$i = 0;
					$smallpath = "_s.jpg";
					$largepath = ".jpg";
					
					echo "<tr>";
					while ($i < $number)
					{
					$code = mysql_result($query,$i,"code");
					$name = mysql_result($query,$i,"name");
					$j = ($i+1)%3;
					if ($j == 1) { echo "<tr>"; }
					/*
					echo "<td><b>Ürün Kodu: </b>$code<br><b>Ürün Ad&#305;: </b>$name</td>";
					echo "<td><center><a href='english/images/";
					echo $code.$largepath;
					echo "' target='_blank'><img src='english/images/";
					echo $code.$smallpath;
					echo "' width='78' height='78' border='0'></a><br></center></td>";
					*/
					?>
<td>
<table width="140" border="0" cellspacing="0" cellpadding="0" class="maintext2">
<tr> 
<td colspan="2"> 
<center>
<a href="english/images/<? echo $code.$largepath; ?>" target="_blank">
<img src="english/images/<? echo $code.$smallpath; ?>" width="78" height="78" align="absmiddle" border="0">
</center>
</td>
</tr>
<tr> 
<td><b>Kod:</b></td>
<td><?=$code?></td>
</tr>
<tr> 
<td></td>
<td><?=$name?></td>
</tr>
</table>
</td>
<?
					if ($j == 0) {echo "</tr>"; }
					$i++;
					}
					echo "</tr>";
					}
				mysql_close();
				

?>
i did it :)