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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:37:38+00:00 2026-06-07T17:37:38+00:00

I have a table of items, and when the user selects an item i

  • 0

I have a table of items, and when the user selects an item i want to set that id to a php variable so when it hits the button “Ok” i associate that item with the user. He can only choose one item at a time. I have tried some php / ajax tutorials and it didn’t seem to work.

Here are the codes:

<table id="tableItens" style="border:1px solid #000000;" cellpadding="0" cellspacing="0">
<tbody>
    <?php foreach($produtoList as $produto) {
        if ($columnCounter == 0) { ?>
            <tr style="background-color:#FFFFFF;">
        <?php    
        } 
    ?>              
            <td id="<?php echo $produto['id'] ?>" width=160px; height="110" onclick="<?php echo 'selectRow(' . $produto['id'] . ');' ?>" style="text-align: center; border:1px solid #000000;border-bottom:0;"><?php echo'<img align="center" width="150" height="100" src="/resources/images/' . $produto['nome_imagem'] . '"></img>' ?></td>
            <?php $columnCounter++; ?>                  
        <?php if ($columnCounter == 3) { 
            $columnCounter = 0; ?>
            </tr>
        <?php } ?>      
    <?php } ?>
</tbody>

<script type="text/javascript">
function selectRow(id) {
  var table = document.getElementById("tableItens");
  document.getElementById(id).style.backgroundColor = 'red';

  $.ajax
  ({
      type: "POST",
      url: "vote.php",
      data: id,
      cache: false,
      success: function(data)
      {

        alert("ok");
      }
 });    
}
</script>

Do i have to include a ajax file or something? Maybe a jquery reference?

I’m using a var_dump($_POST) at the beginning of the page and doesn’t show anything. I’m sending the value to the same page im in.

  • 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-07T17:37:41+00:00Added an answer on June 7, 2026 at 5:37 pm

    You haven’t set the data of you ajax request correctly.
    Refer to http://api.jquery.com/jQuery.ajax/

    data: Data to be sent to the server…Object must be Key/Value pairs

    NOTE: it can also be a String, but you have to format it properly

    try

     data: {uid : id},
    

    and of course, you have to include a reference to jQuery, you are using jQuery

    To test stuff like this out I suggest using the JS console that usually comes with most modern browsers. You can change POST to GET and see what kind of URLs are generated.

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

Sidebar

Related Questions

I have a following table using MVC that shows number of items the user
I have a table with user items. Each user may have several types of
I have a table of items, user should be able to choose some of
I have 3 tables: items , purchases , and collaborators . A user can
I have a table of items. item has id, score 1, score 2. I
Each of my user's have a set number of slots for storage. They can
I have 2 tables: users and items. Each item has a user#. So, if
i have a table view that when the user taps on one of the
I have one table, assume that there are 2 users, user A and user
I have a master-child tables. User can add/remove childs after selecting the master item/entity.

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.