Solved

PHP or HTML Code Needed

Posted on 2011-02-28
3
230 Views
Last Modified: 2012-05-11
I have a mysql database that I've entered some data into via the PHPADMIN page. Is there any way I can display all of this information in a browser? The mysql database name is PEND & the table is PENDING. The fileds are only f_name, l_name, assn_date, interv_date, and actual_date.

I already have a LAMP server setup to throw the code into the www folder. If I could get some help with the code I think I can take it from there. Thanks
0
Comment
Question by:wantabe2
3 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 167 total points
ID: 34997194
Try this, replacing the user and pass with your own

<?php
error_reporting(E_ALL);
$link = mysql_connect('localhost','user','password') or die(mysql_error());
mysql_select_db("PEND") or die(mysql_error());

$query = "select f_name, l_name, assn_date, interv_date, actual_date from PENDING";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo"$row[f_name], $row[l_name], $row[assn_date], $row[interv_date], $row[actual_date]";
}
?>

Open in new window

0
 
LVL 6

Assisted Solution

by:MatthewP
MatthewP earned 166 total points
ID: 34997271
To connect to mysql:
http://php.net/manual/en/function.mysql-connect.php

To select the database:
http://www.php.net/manual/en/function.mysql-select-db.php

To run a SELECT query:
http://www.php.net/manual/en/function.mysql-query.php

To fetch rows of data:
http://www.php.net/manual/en/function.mysql-fetch-array.php

An example of all of this you should be able to modify with your own HTML: You will need to replace what's in CAPS below with your own credentials / SQL query:

$host="localhost";
$database = "MY_DATABASE_NAME";
$username = "USER_NAME";
$password = "PASSWORD";

$dbh=mysql_connect($host,$username,$password) or die("Could not connect to mysql");
$select=mysql_select_db($database,$dbh) or die ("Cannot select database");

$sql="SELECT * from MY_TABLE"; // Add your own query here

$query=mysql_query($sql);

while ($rows=mysql_fetch_array($query)){
        foreach ($rows as $fieldname => $value){
                print "$fieldname = $value<br />";
        }
        print "<hr>";
}

Open in new window

0
 
LVL 3

Assisted Solution

by:pius_babbun
pius_babbun earned 167 total points
ID: 34997282
Hi ,Please check if this code is helpful ,.
<?php
$conn 		= mysql_connect('hostname','db_username','db_pass');

$database   = mysql_select_db('database_name',$conn);//database_name = PENDING

$query      = "SELECT f_name, l_name, assn_date, interv_date,  actual_date FROM database_table_name ";

$result		= mysql_query($query) or die('Database Error:'.mysql_error());

$num_rows   = mysql_num_rows($results);

?>
<table>
<?php for($i=0;$i<$num_rows;$i++){ ?>
<?php $rows[]	= mysql_fetch_array($results);?>
	<tr>
		<td><?=$rows[$i]['f_name']?><td>
		<td><?=$rows[$i]['l_name']?><td>
		<td><?=$rows[$i]['assn_date']?><td>
		<td><?=$rows[$i]['interv_date']?><td>
		<td><?=$rows[$i]['actual_date']?><td>
	<tr>
<?php } ?>
</table>

Open in new window

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question