Solved

PHP or HTML Code Needed

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Row insertion failed. Array 5 46
Character counter breaks after adding EmojiOne Area 4 19
Html Newline 7 20
SQL querys that gives me from one table into another. 2 23
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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

791 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