May 25, 2018

How to display Data from a MySQL DB through PHP

freewaredownload.in free PHP MYSQL SCRIPTS

FREE PHP SCRIPT SOURCE CODE

PHP SCRIPT SOURCE CODE FREE

PHP SQL DB FREE SCRIPTS

How to Display Table Data from a MySQL DB using PHP script


<?php
$con = mysql_connect("localhost","DBuser","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_dbname", $con);

$result = mysql_query("SELECT * FROM TABLENAME");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

How to Display Data using the WHERE Clause parameters like FirstName Alphabet


<?php
$con = mysql_connect("localhost","DBUser","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_dbname", $con);

$result = mysql_query("SELECT * FROM TABLENAME

WHERE FirstName='Meher'");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }
?>


How to Display Data using the WHERE Clause and Order by Certain Field like Age ASC|DESC

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC


SELECT column_name(s)
FROM table_name
ORDER BY column1, column2


SELECT * FROM Persons WHERE
LastName=’Svendson’
AND (FirstName=’Tove’ OR FirstName=’Ola’)



<?php

$con = mysql_connect("localhost","DBuser","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_dbname", $con);

$result = mysql_query("SELECT * FROM TABLENAME ORDER BY age");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'];
  echo " " . $row['LastName'];
  echo " " . $row['Age'];
  echo "<br />";
  }

mysql_close($con);

?>

Displaying Data from a Access / SQL or MySQL DB using ODBC and PHP

ODBC is an Application Programming Interface (API) that allows you to connect to a data source (e.g. an MS Access database).

How to Create an ODBC Connection

With an ODBC connection wizard, you can connect to any database, on any computer in your network, or the remote server using the IP and DB and DB User Details, as long as an ODBC connection is available.

How to create an ODBC connection to a MS Access Database:

  • Open the Administrative Tools icon in your Control Panel.
  • Double-click on the Data Sources (ODBC) icon inside.
  • Choose the System DSN tab.
  • Click on Add in the System DSN tab.
  • Select the Microsoft Access Driver. Click Finish.
  • In the next screen, click Select to locate the database.
  • Give the database a Data Source Name (DSN).
  • Click OK.

Note that this configuration may to be done on the PC where your web site is located. If you are hosting your domain and website with some hosting company then you need to create ODBC for the DB using the Server Control panel like Plesk provided to you by the Hosting Service Provider.


<html>
<body>

<?php
$conn=odbc_connect('ODBCname','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM TABLENAME";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<table><tr>";
echo "<th>Companyname</th>";
echo "<th>Contactname</th></tr>";
while (odbc_fetch_row($rs))
  {
  $compname=odbc_result($rs,"CompanyName");
  $conname=odbc_result($rs,"ContactName");
  echo "<tr><td>$compname</td>";
  echo "<td>$conname</td></tr>";
  }
odbc_close($conn);
echo "</table>";
?>

</body>
</html>

Developers Homepage Download Free now

 FREE PHP CODE

PHP Script Description:

SQL

The PHP Script is used to show the data from a TableName from a MySQL DB using PHP. The data is neatly displayed within a HTML Table. You can use CSS to beautify the Table or the HTML Page as needed. Also using additional parameters you can Sort or order the results of your MySQL DB in different ways. Also it displays how to create an ODBC connection and display data.

Note: Copy the Source Code to notepad or any other good text editor and save as .php or .html or .css as the case may be. Give your own file name, if not described in the script.

SQL

RELATED FREEWARES

[catlist id=18]
[catlist id=5]

::