Creating a table with 3 columns from DB
Moderator: General Moderators
- mudkicker
- Forum Contributor
- Posts: 479
- Joined: Wed Jul 09, 2003 6:11 pm
- Location: Istanbul, TR
- Contact:
Creating a table with 3 columns from DB
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?
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?
- mudkicker
- Forum Contributor
- Posts: 479
- Joined: Wed Jul 09, 2003 6:11 pm
- Location: Istanbul, TR
- Contact:
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ığınız kriterlere göre ürün bulunamadı!</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ı: </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();
?>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.
Mark
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ığınız kriterlere göre ürün bulunamadı!</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ı: </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();
?>- mudkicker
- Forum Contributor
- Posts: 479
- Joined: Wed Jul 09, 2003 6:11 pm
- Location: Istanbul, TR
- Contact:
http://www.farkgrup.com/urunler.php
pick a thing. then another one will open. there you go. but this script is f*cked up...
pick a thing. then another one will open. there you go. but this script is f*cked up...
- mudkicker
- Forum Contributor
- Posts: 479
- Joined: Wed Jul 09, 2003 6:11 pm
- Location: Istanbul, TR
- Contact:
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ığınız kriterlere göre ürün bulunamadı!
</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ı: </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();
?>