/    Sign up×
Community /Pin to ProfileBookmark

How’s my code? A loop question

Hi, I’ve been using this huge code for years to create list pages… with alternating cell backgrounds for multiple entries. I know i’m not calling the data properly in this sample, but the meat is really in the script anyways.

What are your thoughts, is there something lighter than this to count entries, and display them in a list?

[code=php]$sql = “SELECT COUNT(*) FROM it_issues WHERE Issue_Closed = ‘0’”;
$numrecord = mysql_query($sql);
$numrecords = mysql_fetch_array($numrecord);

$intRecsPerPage=100;
if($_POST[“intpage”]==””)
{
$intpage=1;
}
$sql = “SELECT * FROM it_issues WHERE Issue_Closed = ‘0’ ORDER BY Issue_LastEdit DESC LIMIT “.(($intpage-1)*$intRecsPerPage).”, “.$intRecsPerPage;
$result = mysql_query($sql) or die (mysql_error());

$totalpages = intval(($numrecords[0])/$intRecsPerPage);
if(intval($numrecords[0]/$intRecsPerPage) != ($numrecords[0]/$intRecsPerPage))
{
$totalpages = $totalpages + 1;
}

for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
{
if($x/2 != intval($x/2))
{
$bgcolor = “#ffffff”;
}
else
{
$bgcolor = “#F7F7F7”;
}
if($x >= $numrecords[0])
{
break;
}
$issueresults = mysql_fetch_array($result);
//BEGIN LOOP
<tr><td bgcolor=$bgcolor>sample</td></tr>
//END LOOP
}[/code]

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsDec 12.2006 — bgcolor is depreciated, use class or style instead, example:[code=php]<?php
// should be done via GET not POST
$pg = (isset($_GET['intpage'])) ? intval($_GET['intpage']) : 1;
$ppg = 100;

$result = @mysql_query("SELECT * FROM it_issues WHERE Issue_Closed = '0' ORDER BY Issue_LastEdit DESC LIMIT " .(($pg - 1) * $ppg). ", " .$ppg);

if(!$result || !@mysql_num_rows($result))
{
echo mysql_error();
}
else
{
$total = @mysql_result(@mysql_query("SELECT COUNT(*) FROM it_issues WHERE Issue_Closed = '0'"), 0);
$i = 0;

while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
{
// set row class
$class = 'row' . ($i++ % 2); // ex. row0 or row1
// ...
}
@mysql_free_result($result);

// pagination
if($total > $ppg)
{
$nav = array();

for($i = 1; $i <= ceil($total_rows / $ppg); $i++)
{
$nav[] = ($pg == $i) ? '<b>' .$i. '</b>' : '<a href="' ./* url */. '">' .$i. '</a>';
}
echo implode(' | ', $nav);
}
}
?>[/code]
Copy linkTweet thisAlerts:
@netbuddyDec 12.2006 — bgcolor is a html tag reference and as far as I am awar it is still current, all classes and css do is manipulate these tags settings.
Copy linkTweet thisAlerts:
@ShrineDesignsDec 12.2006 — bgcolor is a html tag reference and as far as I am awar it is still current, all classes and css do is manipulate these tags settings.[/QUOTE]bgcolor is an attribute, and has been depreciated since HTML 4.01 (all of the stylizing elements/attributes in the HTML standard were removed in favor of CSS), CSS is for stylizing HTML/XML syntax
Copy linkTweet thisAlerts:
@netbuddyDec 14.2006 — Fine if you ****************, real world here and it doesnt work like that, people use what works for them, bgcolor works for me, it can be easily manipulated in javascript, so why should I listen to some compliancy standards jerk say to me I cannot use something because CSS can do it in justifaction for his or her paper shufffeling job.

eff off comes to mind. Give me one reason why I should use CSS when javascript can do it just as well? and has been here longer than CSS?
Copy linkTweet thisAlerts:
@ShrineDesignsDec 14.2006 — CSS was specifically developed for stylizing syntax, the old html styling is not nearly as feature rich as CSS. when was this an argument between CSS and JavaScript? i'll add that JavaScript is for dynamic client-side content, and to compare CSS to JavaScript, JavaScript still fails, if you use it in place of CSS and vice versa.
Copy linkTweet thisAlerts:
@Stephen_PhilbinDec 14.2006 — eff off comes to mind. Give me one reason why I should use CSS when javascript can do it just as well? and has been here longer than CSS?[/QUOTE]


Because a few lines of CSS is always going to be preferable. Javascript would be a bad idea because there's a very real chance it won't even work for some people and it would also be a rather pointless way of going about it.

I'll also take the opportunity to remind you that abusive behaviour towards other members of the forum will not be tolerated. Thankyou.
Copy linkTweet thisAlerts:
@KorDec 14.2006 — I guess all of you are right and none of you is entirely right at the same time.

  • 1. CSS vs. HTML attributes

    This is a separate problem. CSS is better indeed. By using a CSS class, written in an external file, the developer can easily change, during the developing process, an attribute all over the site's pages from within a single code line.


  • An example: Almost all the time the client wants a lighter/darker/deeper.... and so on, bgcolor or another font family, size, weight... It would be a madness to replace all these in all the pages, all the time the client changes his mind (and he does that [I]very[/I] often, believe me ? ). Yes, the modern editors can replace HTML attributes in all the pages from a single command, but if you mistype, you need to start it from the beginning. Or you need to change only some of the values for some of the elements... Not an easy job with HTML alone...

    And CSS is able to to everything HTML attributes can do, but the reverse is not valuable. CSS is able to set the presentation more accurate than classical HTML attributes and it has a lot of extra attributes in order to do that.

  • 2. CSS vs. javascript

    This is nonsense. There is not such a war. CSS and javascript have different meanings, they do different things, and they were build in order to achieve different tasks. CSS and javascript are rather complementary languages, not foes languages.


  • HTML was meant to [I]set[/I] the [B]content[/B]. CSS was meant to [i]set[/i] the [B]presentation[/B]. Javascript was meant to [I]change dynamically[/I] both the content and the presentation.

    It is true that sometime one of the languages is able to do some of the other language's tasks, but it is a wise practice to let each language to do its own job.
    Copy linkTweet thisAlerts:
    @netbuddyDec 14.2006 — Point I am trying to make is that in the real world you would use what is easiest, if you have a single page for example, what is the point in having CSS to deal with attributes, using HTML tags and in-line CSS if you cant obtain the desired result easily.

    Javascript over CSS gives more control and scripting options where as CSS is static, which limits the options, use of CSS to set attributesand use Javascript to manipulate them as needed, fine.

    I guess that its a case of "What floats ya boat", I have a particular view on these "Standards", just becuse someone with a broom stuck somewhere says we cant use something because it is "Depreciated" can go to the broom closet and deal with themselves because its falling on deaf ears here. Its nice to know these things but you have a choice, always have and the vendors of the browsers wont drop support for these tags becaus it would ruffle too many feathers and it would kill the largest part of the internet off because those pages tend to be resources that are stiuffed full of "Depreciated" tags... like in academic websites, journals and resources written at the dawn of the internet.

    Does that make my position more clear, I dont mean to be rude but these jerks need to get a reality check once in a while or get a real job.
    Copy linkTweet thisAlerts:
    @KorDec 15.2006 — Dear Madam/Sir,

    First, whichever might be your beliefs and your arguments, I guess you should try to expose them with a little bit more temper. There is no use to perform a near-abusive language.

    Now, your arguments look quite thin to me.

    Point I am trying to make is that in the real world you would use what is easiest, if you have a single page for example, what is the point in having CSS to deal with attributes, using HTML tags and in-line CSS if you cant obtain the desired result easily.
    [/quote]

    Would I have been a Buddhist, I should say that the road to a goal is more important than the goal itself. A professional does its job no matter if it is a single web page or a thousand. A plane should be built carefully, no matter it's an Airbus 800 or a small Cessna.

    have a particular view on these "Standards", just because someone with a broom stuck somewhere says we cant use something because it is "Depreciated"
    [/quote]

    "Someone with a broom" are exactly, among others, the representatives of the browsers' vendors. The W3C has men from MS, Mozilla, Gecko, Opera, Safari..... Behind what you think is an arbitrary game, lays a strong reason, the wish for a separation content / presentation. And the aim wishes to be (even the results are far from being perfect at this momemnt, but at least it looks to be a good start) a desire for improving the coder's work and to unify the languages, in order to achieve a common standard.

    If you don't understand at least what is going on, our discussion has no relevance...
    Copy linkTweet thisAlerts:
    @Sid3335Dec 15.2006 — 
    bgcolor is depreciated, use class or style instead
    [/QUOTE]

    sorry, i see this all the time, also my colleagues say depreciated. (along with line-ux, and sequel, bah!)

    Depreciated

    Depreciation is a term used in accounting, economics and finance with reference to the fact that assets with finite lives lose value over time. (There is also a separate use in international finance to refer to a reduction in the exchange rate of a currency - see devaluation).

    Deprecated

    In computer software standards and documentation, deprecation is the gradual phasing-out of a software or programming language feature.

    sorry to be pedantic. (you hate me now don't you?)
    Copy linkTweet thisAlerts:
    @pcthugDec 15.2006 — Ok, this thread is going nowhere.

    Debating the World Wide Web Consortium's set standards is far from relevant to the original question and thread at hand. Discussion may continue elsewhere, although bigotry will not be tolerated and should cease and desist.

    Sorry $var, if your original question has not yet been successfully answered, I'd suggest creating a new thread.

    [B]Thread Closed.[/B]
    ×

    Success!

    Help @_var spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...