Query String In Php Mysql Example Step By Step
In php Passing variables value with a url is very nice thing for programmers do that .We can access value of method of passing variables as GET, the other method by POST. It is one of those things which can be easily done in php. For example. You are to query a database and for that you need to send three variables via GET – city, id, paid The common way to pass them via GET is to construct a query string as below: query string in php mysql example.
display.php
-----------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$sql=mysql_query("select * from product");
?>
<table border="1">
<tr>
<td><b>Name</b></td>
<td><b>Price</b></td>
<td><b>Image</b></td>
</tr>
<?php
while($row=mysql_fetch_array($sql))
{
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><a href="cat.php?id=<?php echo $row['category']; ?>">Detail</a></td>
<td><img src="<?php echo $row[3]; ?>" height="50px" width="50px"></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
------------------------------------------------------
cat.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$sql=mysql_query("select * from product where category='".$_GET['id']."'");
?>
<table border="1">
<tr>
<td><b>Name</b></td>
<td><b>Price</b></td>
<td><b>Image</b></td>
</tr>
<?php
while($row=mysql_fetch_array($sql))
{
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><img src="<?php echo $row[3]; ?>" height="50px" width="50px"></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
----------------------------------------------------------------------------------------
Database
above example is related to how to build query string in php mysql example
0 Comments: