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
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
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
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

Edited by hpub
Link to comment
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
Share on other sites

I'm not clear yet. So do you want to access and retrieve some records from a remote database or local one? If the database is a remote one, when do you create your php scripts onto the server or your personal machine?  

Edited by jazzman1
Link to comment
Share on other sites

its a remote db.

what i see is that if i put a wrong name in db , for example it shows the error message, but if everything is fine it gives error 500

also when tried to create a table in phpmyadmin (see previous post) it gives me syntax error in last line

Link to comment
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
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
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
 

Edited by jazzman1
Link to comment
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
Share on other sites

No, don't use the mysql library for new development, use either mysqli or pdo. So, about the error number of 500, try to turn php error on like in my previous reply and post out the result if you get some new error(s). 

Edited by jazzman1
Link to comment
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!!!";
    }
Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.