Note that there are some explanatory texts on larger screens.

plurals
  1. POAttempting to change the colour for alternative lines in a table using CSS for a PHP script
    primarykey
    data
    text
    <p>Attempting to change the colour for alternative lines in a table using CSS for a PHP script. I have got the colour but the lines are repeating in my script. Is there anyway around this?</p> <p>The PHP Script:</p> <pre><code>&lt;?php ini_set('display_errors',1); error_reporting(E_ALL); //print_r(PDO::getAvailableDrivers()); $config['db'] = array( //This is the config array with the database details 'host' =&gt; 'localhost', 'username' =&gt; 'root', 'password' =&gt; '', 'dbname' =&gt; 'website' ); //echo '&lt;table, th, td {border: 2px solid black; border-collapse="collapse";} &gt;'; echo '&lt;table id="customers"}&gt;'; echo '&lt;link rel="stylesheet" type="text/css" href="style.css"&gt;'; echo '&lt;th&gt; one &lt;/th&gt;'; echo '&lt;th&gt; two &lt;/th&gt;'; echo '&lt;th&gt; three &lt;/th&gt;'; echo '&lt;th&gt; four &lt;/th&gt;'; $db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']); //Instanciate an PDO Object $query = $db-&gt;query("SELECT `articles`.`title`, `articles`.`hello`, `articles`.`id`, `articles`.`name` FROM `articles` WHERE `articles`.`title` &gt; 1 LIMIT 5");//running a query from the database while ($row = $query-&gt;fetch(PDO::FETCH_ASSOC)){ echo '&lt;tr&gt;'; echo '&lt;td&gt;'; echo $row["title"]; echo '&lt;/td&gt;'; echo '&lt;td&gt;'; echo $row["hello"]; echo '&lt;/td&gt;'; echo '&lt;td&gt;'; echo $row["id"]; echo '&lt;/td&gt;'; echo '&lt;td&gt;'; echo $row["name"]; echo '&lt;/td&gt;'; echo '&lt;/tr&gt;'; echo '&lt;tr class="alt"&gt;'; echo '&lt;td&gt;'; echo $row["title"]; echo '&lt;/td&gt;'; echo '&lt;td&gt;'; echo $row["hello"]; echo '&lt;/td&gt;'; echo '&lt;td&gt;'; echo $row["id"]; echo '&lt;/td&gt;'; echo '&lt;td&gt;'; echo $row["name"]; echo '&lt;/td&gt;'; echo '&lt;/tr&gt;'; //print_r($query); //printing a query }; echo '&lt;/table&gt;'; echo '&lt;p&gt; Returned ', $query-&gt;rowCount(), ' results due to limit set&lt;/p&gt;'; //$query = $db-&gt;query("SELECT `title` FROM `articles`");//running a query from the database //$query = $db-&gt;query("SELECT * FROM articles"); //print_r($query); //printing a query //$stmt = $db-&gt;prepare($sql); //$stmt-&gt;execute(); //$results = $stmt-&gt;fetchAll(); /* $query = $db-&gt;query("SELECT `id` FROM `articles`");//running a query from the database while ($row = $query-&gt;fetch(PDO::FETCH_ASSOC)){ echo $row['title'], '&lt;br&gt;'; echo $row['id'], '&lt;br&gt;'; } } */ </code></pre> <p>The CSS Script:</p> <pre><code>#customers { font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; width:100%; border-collapse:collapse; } #customers td, #customers th { font-size:1.2em; border:1px solid #98bf21; padding:3px 7px 2px 7px; } #customers th { font-size:1.4em; text-align:left; padding-top:5px; padding-bottom:4px; background-color:#A7C942; color:#fff; } #customers tr.alt td { color:#000; background-color:#EAF2D3; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload