thanks for cleaning the code ^^v
i have question about stuffs like that..
actually i only make simple things.
i keep using the repeating code.but it works fine for me.but somehow i feel it is so strange.bcos
eg the
Code: Select all
include "IncludeFiles/db_config.php";
$myConn=mysql_connect($host,$uname,$pword);
$mydb=mysql_select_db($dbname,$myConn);
each time i use this in every php code.but it works fine.no errors.sometimes i try to make sql,sql2 in the code.but i screwed up.
but if i repeated the whole code.it is fine.here are some examples(no errors):
Code: Select all
<?php session_start(); ?>
<html>
<head>
<title>livestock-brands</title>
</head>
<style>
a
{
text-decoration:none;
}
</style>
<body>
<table align="center" width="750" height="455" border="1" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" colspan="3" height="90"><img src="images/logo.gif"></td>
<td valign="top" align="right" colspan="3">address</td>
</tr>
<tr>
<td height="20" width="125"><font size="-4"><a href="home.php">home</a></font></td>
<td width="125">
<?php
include "IncludeFiles/db_config.php";
$myConn=mysql_connect($host,$uname,$pword);
$mydb=mysql_select_db($dbname,$myConn);
$sql="select * from categories";
$rs=mysql_query($sql,$myConn);
$num_rows=mysql_num_rows($rs);
for($i=1;$i<=$num_rows;$i++)
{
$row=mysql_fetch_array($rs);
echo "<font size=-4>";
echo "<a href='brands.php?cid=".$row['categoryid']."'>";
echo $row['cname'];
echo "</a>";
echo "</font>";
}
mysql_close($myConn);
?>
</td>
<td width="125"> </td>
<td width="125"> </td>
<td width="125"> </td>
<td width="125"> </td>
</tr>
<tr>
<td valign="middle" align="center" colspan="6" height="330">
<?php
include "IncludeFiles/db_config.php";
$myConn=mysql_connect($host,$uname,$pword);
$mydb=mysql_select_db($dbname,$myConn);
if(isset($_GET["cid"]))
{
$_SESSION["l"]=$_GET["cid"];
$sql="select m.brandid,m.bname,m.blogoimg from brands as m inner join categories as c on c.categoryid=m.categoryid where c.categoryid=".$_GET["cid"];
}
else
{
$sql="select m.brandid,m.bname,m.blogoimg from brands as m inner join categories as c on c.categoryid=m.categoryid where c.categoryid=".$_SESSION["l"];
}
$rs=mysql_query($sql,$myConn);
$num_rows=mysql_num_rows($rs);
$rowmax=5;
echo "<table>";
for($i=0;$i<=$num_rows-1;$i++)
{
$row=mysql_fetch_array($rs);
if($i % $rowmax ==0)
echo "<tr>";
echo "<td align=center>";
echo "<font face=verdana size=-1>".$row["bname"]."</font>"."<br>";
echo "<a href='bproducts.php?cat=".$row['brandid']."'>";
echo "<img src='images/logos/".$row["blogoimg"]."' height=100 width=120><br><br>";
echo "</a>";
echo "</td>";
if ($i % $rowmax == $rowmax-1)
echo "</tr>";
}
echo "</table>";
mysql_close($myConn);
?>
</td>
</tr>
<tr>
<td align="center" colspan="6" height="15"></td>
</tr>
</table>
</body>
</html>
Code: Select all
<?php session_start(); ?>
<html>
<head>
<title>livestock-brand-products</title>
</head>
<style>
a
{
text-decoration:none;
}
</style>
<body>
<table align="center" width="750" height="455" border="1" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" colspan="3" height="90"><img src="images/logo.gif"></td>
<td valign="top" align="right" colspan="3">address</td>
</tr>
<tr>
<td height="20" width="125"><font size="-4"><a href="home.php">home</a></font></td>
<td width="125">
<?php
include "IncludeFiles/db_config.php";
$myConn=mysql_connect($host,$uname,$pword);
$mydb=mysql_select_db($dbname,$myConn);
$sql="select * from categories";
$rs=mysql_query($sql,$myConn);
$num_rows=mysql_num_rows($rs);
for($i=1;$i<=$num_rows;$i++)
{
$row=mysql_fetch_array($rs);
echo "<font size=-4>";
echo "<a href='brands.php?cid=".$row['categoryid']."'>";
echo $row['cname'];
echo "</a>";
echo "</font>";
}
mysql_close($myConn);
?>
</td>
<td width="125"> </td>
<td width="125"> </td>
<td width="125"> </td>
<td width="125"> </td>
</tr>
<tr>
<td align="center" colspan="6" height="330">
<?php
include "IncludeFiles/db_config.php";
$myConn=mysql_connect($host,$uname,$pword);
$mydb=mysql_select_db($dbname,$myConn);
if(isset($_GET["cat"]))
{
$_SESSION["c"]=$_GET["cat"];
$sql="select m.productid,m.pname,m.pimg,c.brandid,c.bname from products as m inner join brands as c on c.brandid=m.brandid where c.brandid=".$_GET["cat"]." order by m.productid desc";
}
else
{
$sql="select m.productid,m.pname,m.pimg,c.brandid,c.bname from products as m inner join brands as c on c.brandid=m.brandid where c.brandid=".$_SESSION["c"]." order by m.productid desc";
}
$rs=mysql_query($sql,$myConn);
$num_rows=mysql_num_rows($rs);
$rowmax=3;
echo "<table width='720' border=1>";
for($i=0;$i<=$num_rows-1;$i++)
{
$row=mysql_fetch_array($rs);
if($i % $rowmax ==0)
echo "<tr>";
echo "<td align=center>";
echo "<font face='verdana' size='-2'>".$row["pname"]."</font>";
echo "<br>";
echo "<a href='bdisplay.php?cat=".$row['productid']."'>";
echo "<img src='images/products/".$row["bname"]."/".$row["pimg"]."' height=100 width=120>";
echo "</a>";
echo "</td>";
if ($i % $rowmax == $rowmax-1)
echo "<tr>";
}
echo "</table>";
mysql_close($myConn);
?>
</td>
</tr>
<tr>
<td align="center" colspan="6" height="15"></td>
</tr>
</table>
</body>
</html>
is it correct if i doing in this way?in future will this cause problem?cos i found this is easy to do.that's y i repeating it.
pls correct me or let me know which one is the right way.thank you very much for the helps ^^v