Jump to content

list users


hpub

Recommended Posts

how can I list a user from a table and show the results in a grid with different color eg frist in blue color second on white , 3rd on blue 4th in with etc

I do need to set select command and I have db name and ip on a file called dbconfig.php from wd calendar so I just need to read the info

 

ps: I cant post links so search for wd calendar and see the dbconfig.php in php folder

Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/
Share on other sites

You can use something like this to loop through as many colours as want in the rows. Put the colours in an array and use $i++%$n as the index to select the row colour from the array (where $i is row counter and $n is the number of colours in the array)

$sql = "SELECT username FROM user";
$res = $db->query($sql);
$output = '';
$i = 0;

// array of colour values
$colours = array ('#80FFFF', '#50CFCF', '#209F9F');
$n = count($colours);

while ($row = $res->fetch_assoc()) {
    $output .= "<tr><td style='background-color:{$colours[$i++%$n]}'>{$row['username']}</td></tr>\n";
}
echo "<table style='border-collapse: collapse; width:150px' border='1' cellpadding='5'>
    $output
    </table>";

This example gives:

 

post-3105-0-90428900-1410637061_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1490999
Share on other sites

i got this to connect to db also

 

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Time</title>
</head>
<body>
<?php
$db_conx = mysqli_connnect('MY_WEBSITE.secureserver.net', 'MY_USERNAME',
'MY_PASSWORD', 'DATABASE_NAME');

// Evaluate the connection
if (mysqli_connect_errno()) {
    echo "cannot connect to database";
    echo mysqli_connect_error();
    exit();
}
else {
     echo "Successful database connection, happy coding!!!";
}
?>
</body>
</html>

 

but i got 500 error

 

 

 

...but this code producce the expected result

 

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Time</title>
</head>
<body>
<?php
    $today = date('y-m-d');
    print "(<p><b>Today is $today</b></p>)";

    $time = date('h-g-s');
    echo "(<p><b>and the time is $time</b></p>)";

    print("<p>Parentheses</p>");
?>
</body>
</html>

 

i dont know why in frist case i got 500 error any ideia?

Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491009
Share on other sites

i used this code 

 

<?php
$username = "myuser";
$password = "mypass";
$hostname = "myserver";

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";

//select a database to work with
$selected = mysql_select_db("calendar",$dbhandle)
  or die("Impossivel seleccionar base de dados");

 

}
//close the connection
mysql_close($dbhandle);
?>

 

for example when i use this if i mistake one numer on server ip it should say unable to connect but instead if gives a 500 error

any any other error with will not show and gives the 500 error

 

 

because then i add this and it gives me the 500 error:

 

//execute the SQL query and return records
$result = mysql_query("SELECT Description FROM no_calendar");
echo mysql_errno($result) . ": " . mysql_error($result) . "\n";

 

 

also i'm trying to create a new table but it gives an error at last line

 

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

CREATE TABLE `aluno` (
  `Id` int(11) NOT NULL auto_increment,
  `idfoto` int(11) character set utf8 default NOT NULL,
  `idaula` int(11) character set utf8 default NOT NULL,
  `Nome` varchar(200) character set utf8 default NOT NULL,
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

 

 

any help is much apreciated

Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491038
Share on other sites

ok i will use code tag

 

yes what i understand is that when everything is Ok IT SHOWS the 500 error

when not it gives the error

like now:

 

Connected to MySQL
Cant found DB

 

(i put the wrong name in db to test and it shows the error message, as suposed)

but when i try to execute a query i cant it gives 500 error

Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491051
Share on other sites

Again, how do you connect to this remote database from your personal computer or the remote server? Where do you deploy your php / database scripts?

As for the syntax error coming from your GUI, no need to apply charset encoding to columns with integer types.

Try, the following works for me:

CREATE TABLE `aluno`(
`Id` int(11) NOT NULL auto_increment,
`idfoto` int(11) NOT NULL, 
`idaula` int(11) NOT NULL,
`Nome` varchar(200) charset utf8 collate utf8_unicode_ci NOT NULL,
PRIMARY KEY  (`Id`) ) 
ENGINE=InnoDB  DEFAULT CHARSET= latin1 AUTO_INCREMENT=4;
Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491093
Share on other sites

ok its a remote database.

also the code you provide work fine i wiil try to make a table to list all records from that table, based on the example some posts above

but i cant understand why when everything is fine i get a 500 error(see my previous post with code) because if name of db is wrong it gts on the echo else gives that 500 error

Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491158
Share on other sites

Where are you from? The name of mysqli_connect() contains a non-english character itself. Go to php.net and copying/past the pattern from there.

 

PS - When I'm copying/paste your script from reply #5, I'm getting even a fatal error:

<?php

ini_set('display_startup_errors',1);

ini_set('display_errors',1);

error_reporting(-1);

$db_conx = mysqli_connnect('db_address', 'db_user','db_pass', 'db_name');

// Evaluate the connection
if (mysqli_connect_errno()) {
    echo "cannot connect to database";
    echo mysqli_connect_error();
    exit();
}
else {
     echo "Successful database connection, happy coding!!!";
}

Result:

 

Fatal error: Call to undefined function mysqli_connnect() in /home/content/04/8337604/html/phpinfo.php on line 9
 

Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491170
Share on other sites

i use this witch work fine

 

$username = "myuser";

$password = "mypass";
$hostname = "myserver";

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL
";

//select a database to work with
$selected = mysql_select_db("calendar",$dbhandle)
or die("Impossivel seleccionar base de dados");



}
//close the connection
mysql_close($dbhandle);
?>

 

but i want a echo message saying Conected! but it gives me a 500 error

Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491175
Share on other sites

Can you post the entire error message? Also add getcwd()  I want know where are you before to set your database credentials: 

    <?php
     
    ini_set('display_startup_errors',1);
     
    ini_set('display_errors',1);
     
    error_reporting(-1);
     
    // current directory
    echo getcwd() . "\n";

    $db_conx = mysqli_connect('db_address', 'db_user','db_pass', 'db_name');
     
    // Evaluate the connection
    if (mysqli_connect_errno()) {
    echo "cannot connect to database";
    echo mysqli_connect_error();
    exit();
    }
    else {
    echo "Successful database connection, happy coding!!!";
    }
Link to comment
https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491180
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.