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

  • Home
  • SEARCH
  • 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 8580557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:51:26+00:00 2026-06-11T20:51:26+00:00

The code is: <?php // my query if (isset($_GET[‘ssiptype’])) { if (($_GET[‘ssiptype’]) == ‘gma’){

  • 0

The code is:

<?php

// my query

if (isset($_GET['ssiptype']))
{
    if (($_GET['ssiptype']) == 'gma'){
        $query = "SELECT location, year, serviceArea, noOfBenificiaries, stat, fundingSrc, projCost 
            FROM swipdd
            WHERE fundingSrc LIKE 'GMA-Rice%' AND ssiptype = 'SWIP'" ;
    }
    elseif (($_GET['ssiptype']) == 'am'){
        $query = "SELECT location, year, serviceArea, noOfBenificiaries, stat, fundingSrc, projCost 
            FROM swipdd
            WHERE fundingSrc LIKE 'AM-Rice%' AND ssiptype = 'SWIP'" ;
    }
    elseif (($_GET['ssiptype']) == 'hvcccred'){
        $query = "SELECT location, year, serviceArea, noOfBenificiaries, stat, fundingSrc, projCost 
            FROM swipdd
            WHERE fundingSrc LIKE 'HVCC RED%' AND ssiptype = 'SWIP'" ;
    }
    elseif (($_GET['ssiptype']) == 'hvcc'){
        $query = "SELECT location, year, serviceArea, noOfBenificiaries, stat, fundingSrc, projCost 
            FROM swipdd
            WHERE fundingSrc LIKE 'HVCC%' AND ssiptype = 'SWIP'" ;
    }
    else{}
}
// output

if (isset($query))
{
  $result = mysql_query($query) or die(mysql_error()); 

  echo "<table border='1' cellpadding='3'>";
  echo "<tr> 
            <td bgcolor=\"#DFE8EC\">LOCATION</td>
            <td bgcolor=\"#DFE8EC\">YEAR</td>
            <td bgcolor=\"#DFE8EC\">STATUS</td>
        </tr>";
  while($row = mysql_fetch_array( $result )) {

  $final_result = array_unique($row);

    echo "<tr>";
    echo '<td>' . $row['location'] . '</td>';
    echo '<td>' . $row['year'] . '</td>';
    echo '<td>' . $row['stat'] . '</td>';
    echo "</tr>"; 
  } 
  echo "</table>";
}
?>

My desired output is as follows:

//dummy data
LOCATION    YEAR   STATUS
---------------------------
park         1999   ok
----------------------------
sea          2000   fine
----------------------------

I’m getting this output:

LOCATION    YEAR   STATUS
----------------------------
park         1999   ok
----------------------------
sea          2000   fine
----------------------------
park         1999   ok
----------------------------
sea          2000   fine
----------------------------
park         1999   ok
----------------------------
sea          2000   fine
----------------------------

It is repeating twice. What is wrong in my code? Please, any help will be appreciated.

Thanks a lot.

  • 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-11T20:51:27+00:00Added an answer on June 11, 2026 at 8:51 pm
    1. only select the columns you need.
    2. In order to not get multiple entires you need som kind of additional qualifier. Im going to assume you want the most recent year to display so what we can do is use GROUP BY to select distinct locations, and ORDER BY to get the most recent year to display
    3. The code is ugly… you keep repeating the same SQL when you can jsut replace the part that changes.

    So putting it all together

    <?php 
    
    $fundingSrcs = array(
      'gma' => 'GMA-Rice%',
      /* repeat for your other options */
    );
    $sql = "SELECT location, year, stat 
           FROM swipdd
           WHERE fundingSrc LIKE %s AND ssiptype = 'SWIP'
           ORDER BY year DESC
           GROUP BY location";
    
    $result = false; // initialize as a default of false
    
    if(isset($_GET['ssiptype']) {
       $ssitype = $_GET['ssiptype'];
       if(isset($fundingSrcs[$ssitype]) {
    
          // substitute the db quoted string for the %s
          $query = sprintf($sql, mysql_real_escape_string($fundingSrcs[$ssitype]));
          $result = mysql_query($query) or die(mysql_error());
       }
    }
    ?>
    
    <?php if($result && mysql_num_rows($result)): ?>
      <table border='1' cellpadding='3'>
        <thead>
          <tr>
            <th bgcolor="#DFE8EC">LOCATION</th>
            <th bgcolor="#DFE8EC">YEAR</th>
            <th bgcolor="#DFE8EC">STATUS</th>
          </tr>
        </thead>
        <tbody>
        <?php while ($row = mysql_fetch_array($result)): ?>
          <tr>
            <td><?php echo $row['location'] ?></td>
            <td><?php echo $row['year'] ?></td>
            <td><?php echo $row['stat'] ?></td>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    <?php else if($err = mysql_error()): ?>
      <p>There was an error executing this request.</p>
    <?php else: ?>
      <p>No matching entries found</p>
    <?php endif; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this PHP code to highlight the Query on search results. if (isset($_REQUEST['k'])){
I have a PHP code, that will run a Select query to check if
Here's a php code if(isset($_GET['id'])) { //do something } else { redirect('index.php'); //redirect is
Heres my code <?php session_start(); include('config.php'); if(isset($_GET['search_word'])) { // echo $_GET['search_word'] . '<br />';
So I have this code: <?php if (!isset($_GET['email']) && !isset($_GET['key'])) { echo 'NOT ALLOWED
I'm getting a syntax error on this PHP code: <snip> $last = (isset($_GET['last']) &&
This is my php code <?php if(isset($_GET['name'])) { $var = $_GET['name']; $newvar =str_replace (
I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should
i have the following piece of code in php: define('QUERY', $some_query_string); if(empty(QUERY) || mb_strlen(QUERY)
I am using php code to query to a database and the results will

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.