Solved

PHP or HTML Code Needed

Posted on 2011-02-28
3
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS question 4 56
Why is my implode function empty 8 42
Developers / Staff Setup 10 40
What is the valid CSS Selector Chain for this situation? 3 17
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

739 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