Results 1 to 7 of 7
Hi folks,
I have a php script;
# cat /home/satimis/sqlusers.php
Code:
<?php
$host="localhost"; //Database host.
$user="root"; //Database username.
$pass="apassword"; //Database password.
$dbase="maildb"; //Database.
$connect=mysql_connect($host,$user,$pass); //Connect to the database.
mysql_select_db($dbase, $connect);
...
- 05-29-2009 #1Linux Guru
- Join Date
- Sep 2004
- Posts
- 1,546
How to display data on mysql_table in table form
Hi folks,
I have a php script;
# cat /home/satimis/sqlusers.phpOn running;Code:<?php $host="localhost"; //Database host. $user="root"; //Database username. $pass="apassword"; //Database password. $dbase="maildb"; //Database. $connect=mysql_connect($host,$user,$pass); //Connect to the database. mysql_select_db($dbase, $connect); $Q = "SELECT * FROM users"; // select everything $result = mysql_query($Q); while ($row = mysql_fetch_assoc ($result) ) { // loop through the result set echo $row["id"] . "<br>"; echo $row["name"] . "<br>"; echo $row["crypt"] . "<br>"; } ?>
# php /home/satimis/sqlusers.phpit printouts the data of mysql_table "users" but not in table form.Code:satimis@satimis.com<br>satimis<br>0e3QZ140ZrOOE<br>smsliu@satimis.com<br>smsliu<br>0eWBW8//TnfEg<br>albert@satimis.com<br>albert<br>XNP5IEvi8VZS6<br>patricia@satimis.com<br>patricia<br>0eg78AAkIGLWM<br> postmaster@satimis.com<br>postmaster<br>0e130m.vyL/aU<br>albertcheung@satimis.com<br>Albert Cheung<br>XXvTmrqgLrBGY<br>root@vz2:/#
I tried putting the script on /var/www/ and renamed it as "index.html" On browser to evoke the file it did not help. No data was displayed.
Please help how to display the data on a mysql_table in table form. TIA
B.R.
satimis
- 05-29-2009 #2
Do you mean
Code:<?php $host="localhost"; //Database host. $user="root"; //Database username. $pass="apassword"; //Database password. $dbase="maildb"; //Database. $connect=mysql_connect($host,$user,$pass); //Connect to the database. mysql_select_db($dbase, $connect); $Q = "SELECT * FROM users"; // select everything $result = mysql_query($Q); echo '<table>; while ($row = mysql_fetch_assoc ($result) ) { // loop through the result set echo '<tr>'; echo "<td>{$row["id"]}</td>"; echo "<td>{$row["name"]}</td>"; echo "<td>{$row["crypt"]}</td>"; echo '</tr>'; } echo '</table>'; ?>If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 05-29-2009 #3Linux Guru
- Join Date
- Sep 2004
- Posts
- 1,546
- 05-30-2009 #4
(Blush)
should beCode:echo '<table>;
Code:echo '<table>';
If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 05-30-2009 #5Linux Guru
- Join Date
- Sep 2004
- Posts
- 1,546
Sorry, still fail.
Code:Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in /var/www/sqlusers.php on line 8 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/sqlusers.php on line 9 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/sqlusers.php on line 13
line 8line 9Code:$connect=mysql_connect($host,$user,$pass); //Connect to the database.
line 13Code:mysql_select_db($dbase, $connect);
Code:while ($row = mysql_fetch_assoc ($result) ) { // loop through the result set
# cat /var/www/sqlusers.phpB.R.Code:<?php $host="localhost"; //Database host. $user="root"; //Database username. $pass="apassword"; //Database password. $dbase="maildb"; //Database. $connect=mysql_connect($host,$user,$pass); //Connect to the database. mysql_select_db($dbase, $connect); $Q = "SELECT * FROM users"; // select everything $result = mysql_query($Q); echo '<table>'; while ($row = mysql_fetch_assoc ($result) ) { // loop through the result set echo '<tr>'; echo "<td>{$row["id"]}</td>"; echo "<td>{$row["name"]}</td>"; echo "<td>{$row["crypt"]}</td>"; echo '</tr>'; } echo '</table>'; ?>
satimis
- 05-30-2009 #6Can't help you with that I'm afraid unless you want to tell me all your passwordsAccess denied for user 'root'@'localhost'
If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 05-30-2009 #7Linux Guru
- Join Date
- Sep 2004
- Posts
- 1,546
Hi elija,
There is nothing to do with password.
Following script works nicely displaying the output in table form but without table frame ;
# cat /var/www/sqlusers.phpI'm still looking around for solution adding frame to the table.Code:<?php //These variables will determine the search parameters later $host="localhost"; //Database host. $user="root"; //Database username. $pass="apassword"; //Database password. $dbase="maildb"; //Database. $connect=mysql_connect($host,$user,$pass); //Connect to the database. mysql_select_db($dbase, $connect); //after the connection is made use the INSERT command to enter the values in the db $Q = "SELECT * FROM users"; // select everything //result set $result = mysql_query($Q); //creating the table /w headers echo "<html><body>"; echo "<table><tr><td>id</td><td>name</td><td>crypt</td></tr>"; //row for each record while ($row = mysql_fetch_assoc ($result) ) { // loop through the result set echo"<tr><td>" . $row['id'] . "</td><td>" . $row['name'] . "</td><td>" . $row['crypt'] . "</td></tr>"; } echo "</table>"; echo "</body></html>"; //close the db mysql_close(); ?>
B.R.
satimis


Reply With Quote
