hpub Posted September 13, 2014 Share Posted September 13, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/ Share on other sites More sharing options...
jcbones Posted September 13, 2014 Share Posted September 13, 2014 You can copy/paste however. Right? Post what you have tried, and tell us specifically where you need help. I promise, this will go much faster, and you will get much better replies. 1 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1490973 Share on other sites More sharing options...
hpub Posted September 13, 2014 Author Share Posted September 13, 2014 i saw this http://forums.phpfreaks.com/topic/291035-list-users/ but i got all php code has normal text when i see in browser Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1490977 Share on other sites More sharing options...
Barand Posted September 13, 2014 Share Posted September 13, 2014 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: Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1490999 Share on other sites More sharing options...
hpub Posted September 13, 2014 Author Share Posted September 13, 2014 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 connectionif (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? Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491009 Share on other sites More sharing options...
hpub Posted September 14, 2014 Author Share Posted September 14, 2014 (edited) 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 connectionmysql_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 September 14, 2014 by hpub Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491038 Share on other sites More sharing options...
jazzman1 Posted September 14, 2014 Share Posted September 14, 2014 Can you use the forum code tags next time when providing code? So, correct me if I'm wrong, but you want to use a remote database resource using your local server or ....? Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491039 Share on other sites More sharing options...
hpub Posted September 14, 2014 Author Share Posted September 14, 2014 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 MySQLCant 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 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491051 Share on other sites More sharing options...
jazzman1 Posted September 14, 2014 Share Posted September 14, 2014 (edited) 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 September 14, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491079 Share on other sites More sharing options...
hpub Posted September 14, 2014 Author Share Posted September 14, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491090 Share on other sites More sharing options...
jazzman1 Posted September 14, 2014 Share Posted September 14, 2014 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; Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491093 Share on other sites More sharing options...
hpub Posted September 15, 2014 Author Share Posted September 15, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491158 Share on other sites More sharing options...
hpub Posted September 15, 2014 Author Share Posted September 15, 2014 can you also explain how i make relationship between tables in phpmyadmin? Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491161 Share on other sites More sharing options...
jazzman1 Posted September 15, 2014 Share Posted September 15, 2014 (edited) 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 September 15, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491170 Share on other sites More sharing options...
Barand Posted September 15, 2014 Share Posted September 15, 2014 mysqli_connnect() should only have 2 n's Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491172 Share on other sites More sharing options...
jazzman1 Posted September 15, 2014 Share Posted September 15, 2014 Ha-ha-ha....good triple color master Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491174 Share on other sites More sharing options...
hpub Posted September 15, 2014 Author Share Posted September 15, 2014 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 connectionmysql_close($dbhandle);?> but i want a echo message saying Conected! but it gives me a 500 error Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491175 Share on other sites More sharing options...
jazzman1 Posted September 15, 2014 Share Posted September 15, 2014 (edited) 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 September 15, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491177 Share on other sites More sharing options...
hpub Posted September 15, 2014 Author Share Posted September 15, 2014 (edited) i tried you code with the (fix for connnection) but i get 500 error can you rpovide a code with pdo to test? Edited September 15, 2014 by hpub Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491178 Share on other sites More sharing options...
jazzman1 Posted September 15, 2014 Share Posted September 15, 2014 (edited) 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 September 15, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491180 Share on other sites More sharing options...
hpub Posted September 15, 2014 Author Share Posted September 15, 2014 where i add getcwd() Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491183 Share on other sites More sharing options...
jazzman1 Posted September 15, 2014 Share Posted September 15, 2014 (edited) Use my code of previous reply. Run the script with your database credentials and post out everything you get as outputs, including errors and warnings. Edited September 15, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491184 Share on other sites More sharing options...
hpub Posted September 15, 2014 Author Share Posted September 15, 2014 ok i try again and it connects saying sucess mesage but it you put wrong pw or dbname it doesnt not show the cannot connect to db it gives a 500 error Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491185 Share on other sites More sharing options...
jazzman1 Posted September 15, 2014 Share Posted September 15, 2014 please, show us everything you get as outputs when you ran my script from reply #20, don't tell me empty stories.. Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491186 Share on other sites More sharing options...
hpub Posted September 15, 2014 Author Share Posted September 15, 2014 i've got G:\PleskVhosts\mysite\subdomain Successful database connection, happy coding!!! Quote Link to comment https://forums.phpfreaks.com/topic/291035-list-users/#findComment-1491207 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.