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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:35:59+00:00 2026-06-15T15:35:59+00:00

I’m writing a function to display tables with the option of editing and deleting

  • 0

I’m writing a function to display tables with the option of editing and deleting the data. I need these tables a few times so this is why I made a function.

This is how the function is called:

listSpecific(customer, array("CustomerID", "Forename", "Surname", "Email", "Secret Q", "Secret A", "Street", "City", "Postcode", "Type"), array("customerid", "forename", "surname", "email", "secretQ", "secretA", "address_street", "address_city", "address_postcode", "member_type"));

This is the function in its entirety:

function listSpecific($DBname, $titles=array(), $values=array()){
$numValues = count($values);
$i=0;
$sql = "SELECT ";

//Construct SQL Statement
foreach ($values as $val)
{
    //Last Element of the array
    if(++$i === $numValues){
        $sql .= $val;
        $sql .= " ";
    }
    else{
        //The rest of the array elements
        $sql .= $val;
        $sql .= ", ";    
    }

}

$sql .= "FROM $DBname;";

//End of Constructing SQL Statement

// Execute Query
$result = mysql_query($sql) or die("An error has ocured: " . mysql_error() . ":" . mysql_errno());


//Construct table
$list = "<table>";
$list .= "<tr>";

//Cycle through array elements to get table headers
foreach ($titles as $title) {
    $list .= "<th>$title</th>";
}

$list .= "<th>";
$list .= "Task";
$list .= "</tr><tr>";


$numValues = count($values);
$i=0;
//Construct the rest of the table [NOT WORKING]
while ($table = mysql_fetch_array($result)) {

    $item = array();
    foreach($values as $val){
        //Last Element of the array
        if(++$i === $numValues){
            $list .= "<td>";
        $item = $table[$val];
        $list .= $item;
        $list .= "</td>"; 


        //Get the Item ID
        $firstElement = reset($table);
        $list .= "<td><a href=\"users.php?task=delete&user=$firstElement\">Delete</a></td></tr>";
        }
        else{
            //The rest of the array elements
        $list .= "<td>";
        $item = $table[$val];
        $list .= $item;
        $list .= "</td>";   
        }

    }
}

echo $list;

}

The issue is creating a delete hyperlink as I need the user ID which will be passed to the URL.

The issue is on this line:

        //Get the Item ID
        $firstElement = reset($table);
        $list .= "<td><a href=\"users.php?task=delete&user=$firstElement\">Delete</a></td></tr>";

I understand why it’s going wrong, it will go back to the very first item of the array, which is the User ID. But it needs to be unique to the row.

For example, on the first row the user ID is 57.
But on the next row 58 and have the hyperlink change.

A cheap solution to this would be to go back 11 values every time in the while loop and then continuing from where it left off. How could this be achieved?

Thank you.

  • 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-15T15:36:00+00:00Added an answer on June 15, 2026 at 3:36 pm

    If you are expecting the primary key column to always be the first element of the $values array, then you may refer to it as $values[0]. That is,

    while ($table = mysql_fetch_array($result)) {
        foreach($values as $val) {
            $list .= '<td>'.$table[$val].'</td>';
        }
        $list .= '<td><a href="users.php?task=delete&user='.$table[values[0]].'">Delete</a></td></tr>';
    }
    

    I also tidied up the loop where I thought appropriate.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.