vBulletin

Thank you for visiting. This is our website archive. Please visit our main website by clicking the banner above.
vBulletin FAQ is dedicated to helping the forum owner build, manage and profit from his vBulletin Forum
vBulletin Web Hosting - Free skins and styles for your vBulletin - Search Engine Optimization




Display MySQL table using php

Susan
01-26-2006, 09:55 AM
Hello All,

I am looking for a php script that I can upload to my site that will display one of my MySQL tables and only certain fields from the database. Any assistance is much appreciated.

thanks

mikelbeck
01-26-2006, 01:38 PM
Take a look here:

http://www.freewebmasterhelp.com/tutorials/phpmysql

It has information about how to interact with MySQL from php. From reading that article you should be able to write your own script pretty easily.

If you need more help post in this thread or you can PM me on this site.

Taylor
01-26-2006, 03:45 PM
Perhaps this will help:

viewfields.php
<html>
<head><title>Your Page Title</title></head>
<body>
<?php
$database="yourdbname";
mysql_connect ("localhost", "yourusername", "yourpassword");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT field1, field2, field3 FROM yourtable" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=250 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
?>
</body>
</html>
Simply plug in your information in these lines:
$database="yourdbname";
mysql_connect ("localhost", "yourusername", "yourpassword");
$result = mysql_query( "SELECT field1, field2, field3 FROM yourtable" )

hope this helps;)

Susan
01-27-2006, 03:27 PM
Thanks -

Okay what you suggested ~taylor worked fine.

Now I have one more issue to resolve. How do I list each record in a vertical format instead of a linear format. I want each record to be listed like so:

Name
address
phone
.....
...

tia

Taylor
01-28-2006, 06:05 PM
Give this a try:
viewvertical.php<html>
<head>
<title>Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<h1>Search Results</h1>
<?php
$database="database_name";
mysql_connect ("localhost", "username", "password");
@mysql_select_db($database) or die( "Unable to select database");
$query = "select * from tablename";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

echo "<p>Number matches found: ".$num_results."</p>";
echo "<hr>";

for ($i=0; $i <$num_results; $i++)
{

$row = mysql_fetch_array($result);
echo "<p><strong># ";
echo stripslashes($row["contact_id"]);
echo "<p><strong>Name: ";
echo stripslashes($row["first_name"]);
echo "<p><strong>Category: ";
echo stripslashes($row["lastname"]);
echo "<p><strong>Comment: ";
echo stripslashes($row["comments"]);
echo "<hr>";
echo "</p>";
}
?>
</body>
</html> Of course edit the connection string and your field names to echo..;)

AnıL Karahan
11-13-2007, 07:11 AM
[]Perhaps this will help:

viewfields.php
<html>
<head><title>Your Page Title</title></head>
<body>
<?php
$database="yourdbname";
mysql_connect ("localhost", "yourusername", "yourpassword");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT field1, field2, field3 FROM yourtable" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
pint "<table width=250 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
?>
</body>
</html>
Simply plug in your information in these lines:
$database="yourdbname";
mysql_connect ("localhost", "yourusername", "yourpassword");
$result = mysql_query( "SELECT field1, field2, field3 FROM yourtable" )

Of course edit the connection string and your field names to :)


vBulletin

seo book

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum