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 7764925
In Process

The Archive Base Latest Questions

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

I am new to PHP and trying to learn it by creating a database

  • 0

I am new to PHP and trying to learn it by creating a database of all my jobs (I’m a freelance designer). I have created the code below to generate a table to display all jobs where the description contains logo which works fine and generates several rows….

<?php
$logojobs = mysql_query("SELECT *  FROM hlgd_projects WHERE description LIKE '%logo%'", $connection);
?>

<a href="index.php?report=logo">View logo jobs</a>

<?php
if ($report == 'logo') {         
echo "<h1>Logo jobs</h1>";
echo "<table id='report'>
    <tr>
     <th></th>
     <th>Status</th>
     <th>Lead</th>
     <th>Start</th>
     <th colspan='2'>Codes</th>
     <th>Client</th>
     <th>Description</th>
     <th>Fee</th>
     <th>Contact</th>
     <th colspan='2'>Invoice</th>
     <th>Paid</th>
    </tr>";
 while ($logojob = mysql_fetch_array($logojobs)) { 
    echo "<tr>
        <td class='id'>" . $logojob['id'] . "</td>
        <td>" . $logojob['status_id'] . "</td>
        <td>" . $logojob['lead_id'] . "</td>
        <td>" . $logojob['date_start'] . "</td>
        <td>" . $logojob['code_lead'] . "</td>
        <td>" . $logojob['code_hlgd'] . "</td>
        <td>" . $logojob['client'] . "</td>
        <td>" . $logojob['description'] . "</td>
        <td>&pound;" . $logojob['fee'] . "</td>
        <td>" . $logojob['contact'] . "</td>
        <td>" . $logojob['invoice'] . "</td>
    <td>" . $logojob['date_inv'] . "</td>
        <td>" . $logojob['date_paid'] . "</td>      
    </tr>";             
 }  
 echo "</table>";        
}
?>

However I would like to be able to generate reports for lots of different things and so would like to create a function to generate the table and pass the relevant arguments each time. I’ve done this as follows but it only generates the first row so I presume it’s ignoring the while? Can anyone tell me where I’m going wrong or how to better put the code above into a function?

<?php
function report_bytype($title,$job_set,$job_name) {
  $reporthead = "<h1>$title</h1>
    <table id='report'>
    <tr>
     <th></th>
     <th>Status</th>
     <th>Lead</th>
     <th>Start</th>
     <th colspan='2'>Codes</th>
     <th>Client</th>
     <th>Description</th>
     <th>Fee</th>
     <th>Contact</th>
     <th colspan='2'>Invoice</th>
     <th>Paid</th>
    </tr>";
  while ($job_name = mysql_fetch_array($job_set)) { 
    $reportrows = "
        <tr>
        <td class='id'>" . $job_name['id'] . "</td>
        <td>" . $job_name['status_id'] . "</td>
        <td>" . $job_name['lead_id'] . "</td>
        <td>" . $job_name['date_start'] . "</td>
        <td>" . $job_name['code_lead'] . "</td>
        <td>" . $job_name['code_hlgd'] . "</td>
        <td>" . $job_name['client'] . "</td>
        <td>" . $job_name['description'] . "</td>
        <td>&pound;" . $job_name['fee'] . "</td>
        <td>" . $job_name['contact'] . "</td>
        <td>" . $job_name['invoice'] . "</td>
        <td>" . $job_name['date_inv'] . "</td>
        <td>" . $job_name['date_paid'] . "</td>     
    </tr>";             
  }                             
  $reportfoot = "</table>"; 
  $reporttable = $reporthead . $reportrows . $reportfoot;
  echo $reporttable;
  return $reporttable; 
}
?>

<?php
if($report == 'logo') {
report_bytype("logo",$logojobs,$logojob);
}
if($report == 'stationery') {
report_bytype("stationery",$stationeryjobs,$stationeryjob);
}
?>

Many thanks in advance,
Helen

  • 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-01T15:02:52+00:00Added an answer on June 1, 2026 at 3:02 pm

    The problem is this line:

    while ($job_name = mysql_fetch_array($job_set)) { 
        $reportrows = "lots of html"
    }
    

    Every time this loops $reportrows is set to the html for that row only.

    Use $reportrows .= "some html"; instead which will add each row to $reportrows rather than replace $reportrows with that row.

    Edit: Replacing += with .=.

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

Sidebar

Related Questions

i'm quite new to php and trying to learn. I have 2 similiar classes.
I'm very new to PHP so far and have been trying to learn it.
I'm trying to learn how to use oop in php. I'm also fairly new
I am new to PHP and trying to get the following code to work:
I'm new to PHP and trying to get my head around security. I have
I'm trying to learn object oriented programming more clearer by creating a database class
I'm new to PHP and i was trying to learn mod rewrite to rewrite
I have been trying to learn about classes in PHP and part of my
I'm pretty new to PHP and i'm trying to learn namespacing to a reasonable
I am trying to learn PHP with codeigniter, had have come across a problem.

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.