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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:33:24+00:00 2026-06-17T10:33:24+00:00

I’m having a bunch of features table in MySQL DB in my PHP project.

  • 0

I’m having a bunch of features table in MySQL DB in my PHP project. I’m fetching through php and creating a table with textboxes named by column name and id of record in photos table using code:

functions.php Code:

function m_html_editPhotos($id) {
$result = "<table class=\"tabelka\" id=\"tbl_photos\"><thead><tr><th>Miniaturka</th><th>Duże zdjęcie</th></tr></thead><tbody>";
$mysqli = m_db_Init();
$qry = "SELECT ID, Img_Min, Img_Nrm FROM tbl_Zdjecie WHERE ID_Grzyb = ?";
if($stmt = $mysqli -> prepare($qry)) {
          $stmt -> bind_param("i", $id);
          mysqli_stmt_bind_result($stmt, $img_id, $img_min, $img_nrm);
          $stmt->execute();
          $i =0;
          while (mysqli_stmt_fetch($stmt)) {
              $i = $i+1;
              $result .= "<tr><td><!--<label>Link do miniaturki:<label>--><input type=\"text\" class=\"required\" name=\"photo[$i][min]\" value=$img_min></td><td><!--<label>Link do zdjęcia pełnego rozmiaru:</label>--><input type=\"text\" class=\"required\" name=\"photo[$i][nrm]\" value=$img_nrm></td><td style=\"display:none;\"><input type=\"text\" name=\"photo[$i][id]\" value=$img_id /></td></tr>";
          }
          $stmt -> close();      
}
mysqli_close($mysqli);
$result .= "</tbody></table><div class=\"link\" onclick=\"AddPhotoEditRow();\">Dodaj kolejne zdjęcie</div>";
return $result;
}

Now what I’d like is to edit photos table iterating through each row of generated as above table with textboxes for thumbnail_url (img_min) and full size link (img_nrm)
Additionally I’d like to add new ones to the table from dynamically created rows by function AddPhotoEditRow();

functions.js Code:

function AddPhotoEditRow(){
 $('#tbl_photos > tbody:last').append('<tr><td><input type="text" name="photo[0][min]"></td><td><input type="text" name="photo[0][nrm]"></td><td style=\"display:none;\"><input type=\"text\" name=\"photo[0][id]\" value=\"0\" /></td></tr>');
}

edit.php Code:

include 'functions.php';
if(isset($_POST["change"])) m_db_updateAllFeatures($_GET["id"]);
if (m_db_isAdmin("")){
if (!isset($_GET["id"]) || !is_numeric($_GET["id"]))
    header("Location: ../index.php");
else {
if (isset($_POST["Nazwa_PL"]))
    m_db_UpdateName("PL", $_GET["id"],$_POST["Nazwa_PL"]);
if (isset($_POST["Nazwa_Lac"]))
    m_db_UpdateName("Lac", $_GET["id"],$_POST["Nazwa_Lac"]);
render_edit_body();
    }
}

I’d like to iterate somehow through photos links and update existing records by parsing textbox names passed through $_POST, additionally would be good to insert new photo links (that with id=0). I’m setting new rows’ id to 0 because I need to distinguish if I’m inserting to table, or updating, right? I’ve assumed that all 0-indexed fields should be added, rest of them should be inserted. I might have my conception wrong, if there is a better way to do full functionality to that table “control” then I’m very open to suggestions.

  • 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-17T10:33:26+00:00Added an answer on June 17, 2026 at 10:33 am

    You’ve got the basics, except

    $('#tbl_photo snip snip name="photo[0][min]"> snip snip snip
                                        ^---
    

    the 0 should not be hardcoded. You’re telling php to create an array of ‘photo’ values in the $_POST array, but then you force the index keys to be 0 for all entries, causing later ones to overwrite earlier ones.

    Keep a count in Javascript as to how many of these fields you’ve inserted, and use that count to increment the index key, e.g.

    $('#tbl_photo snip snip name="photo[' + i + '][min]"> snip snip snip
    

    instead, where i is the field count. Then it’s a simple matter of:

    foreach($_POST['photo'] as $i => $photo) {
        echo $photo['min'];
    }
    

    to get that min value for each photo field.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.