Hi again guys,

I am getting information from a table that I would dearly love to format using my css styles in an external css sheet. Now I am calling the sheet in the header correctly, tested that to make sure.

Here is the code I am using. This generates the text, but not formatted according to my css style sheet.

echo "<div align=\"left\">"; 
while($row=mysql_fetch_array($result))
{ 
echo "<p class=\"index_page_big\">";
echo $row['manufacturer']." ".$row['make']." ".$row['model']." ".$row['variant'];
echo "</p>";
}
mysql_close($connect);
?>
</div>

What I would ideally like to do, is have lines 4,5,6 all one one line. But can just as well live with the three lines if just for the sake of readability! Nice to have short precise code, but then also good to be able to read what has been done easily!

Dani AI

Generated

Quick checklist and diagnosis (no extra PHP changes first): confirm the stylesheet file actually loads in the browser, then inspect the element with DevTools to see which rules match, which are overridden, and whether any inline styles or higher‑specificity rules are taking precedence. The Elements → Styles and Computed panes show matched vs. crossed‑out rules and the cascade order — use those to find why a selector isn’t applying. (developer.chrome.com)

Keep layout concerns in CSS, not in PHP: if the goal is “manufacturer make model variant” on a single line, either render them as inline elements (span/inline‑block) or make the containing element prevent wrapping with white-space: nowrap (or use a one‑row flex container). That keeps markup small and readable while letting CSS control presentation. (developer.mozilla.org)

Server‑side hygiene and maintainability: avoid legacy mysql_* functions — they were deprecated and removed in modern PHP; migrate to mysqli or PDO and use prepared statements for safety and future compatibility. Always HTML‑encode database values before output (contextual encoding for attributes vs. body) to avoid XSS — frameworks and OWASP recommend output encoding as the primary defense. (php.net)

Practical tips tied to the thread: ’ idea to reduce repetition is solid — for readability prefer joining the four fields into a single output (or a small template snippet) rather than many echo lines. After changes, reload with DevTools open and check the Network/Styles panes: if the CSS file returns 200 and the selector appears in Styles but is crossed out, it’s a specificity/cascade issue; if the rule never appears, the stylesheet path or media/type may be wrong. These steps resolve most “CSS not applied” cases. (developer.chrome.com)

Recommended Answers

All 2 Replies

Dont knowe if this helps, but i usually write my html within php with ' rather than ".
example,

echo "<li style='color:red;'>hello world</li>";

another little thing i do is use arrays to get my records, can sometimes keep coding efforts down. example,

echo "<div align='left'>";
while($row=mysql_fetch_array($result))
{
$columns = array("manufacturer", "make", "model", "variant");
foreach($columns as $cname){$$cname = $row[$cname];}
echo "<p class='index_page_big'>$manufacturer $make $model $variant</p>";
}
mysql_close($connect);

Thanks gotboots

Done and dusted now. Like your idea of

$columns = array("manufacturer", "make", "model", "variant");
foreach($columns as $cname){$$cname = $row[$cname];}

Makes life just that little bit easier.

Carter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.