Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7714115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:02:50+00:00 2026-06-01T02:02:50+00:00

How can i display variable only once in the table. <?php $sql = mysql_query(SELECT

  • 0

How can i display variable only once in the table.

<?php
$sql = mysql_query("SELECT * FROM babydata");
while ($row = mysql_fetch_array($sql)) {
    for ($i = 1; $i <= 72; $i++) {
        if ($i == $weeknumber) {
            echo "<tr><td width='40'>Week $i</td>";
            echo "<td width='500' >" . count($row[$menucompare]) . "</td></tr>";
        }
    }
}
?>

this code display like this:

--------------
week4 |  1
-------------
week4 |  1
-------------

But i want to display weeknumber only once and count($row[$menucompare]) will be counted 2 in week 4 . not 1 and 1 .

Like this:

--------------
week4 | 2
---------------
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:02:51+00:00Added an answer on June 1, 2026 at 2:02 am

    Seems like you want to output the amount of tuples in babydata for a certain week. You can just filter out any tuples which dont belohnt to the $weeknumber in your query.

    // TODO: Assert, that $weeknumber is an integer, to not be prune to SQL injection.
    $weeknumber = (int)(($currentdate - $birthday) / (7 * 24 * 60 * 60)) + 1;
    
    // Select the amount of tuples in babydata for the desired $weeknumber.
    $result = mysql_query("SELECT count(*) FROM babydata ".
        "WHERE week = $weeknumber");
    
    // There is only one tuple with one column that contains the amount as number. 
    $row = mysql_fetch_row($result);
    
    // Output the week and the amount of data.
    echo "<tr><td width='40'>Week $weeknumber</td>" ;
    echo "<td width='500' >".$row[0]."</td></tr>";
    

    No need for loops.

    To output all weeks and their respective amount of data:

    // Select the amount of tuples in babydata for all weeks.
    $result = mysql_query("SELECT week, count(*) FROM babydata ".
        "GROUP BY week");
    
    // For all weeks:
    while ($row = mysql_fetch_row($result))
    {
        // Output the week and the amount of data.
        echo "<tr><td width='40'>Week ".$row[0]."</td>" ;
        echo "<td width='500' >".$row[1]."</td></tr>";
    }
    

    This assumes that you have a column week in your table babydata that contains just a number. This outputs only weeks, that have at least one tuple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a variable using System.Windows.Media.Color. I can display the Hex value from
I have a table view where cells can display a variable amount of information.
How can I populate and display the $errors variable only after the form is
I can display a simple Visual Basic inputbox from a PowerShell script like this:
How do you use a php variable (array) inside a mysql select statement? I
How i can display all applications icons and name which are installed in device
how i can display Name - LastName with ViewBag? <h2> @{ViewBag.Name;} - @{ViewBag.LastName;} </h2>
In Visual Studio you can display the Call hierarchy of a single function. What
Possible Duplicate: Is there a tool that can display a SVN repository visually (
Examotion has a player that can display the image for svg files as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.