Solved

PHP or HTML Code Needed

Posted on 2011-02-28
3
219 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now