Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Insert checked search results into a new table

New Here ,
Jul 13, 2009 Jul 13, 2009

I've built a search/results page in PHP that returns the names and contact information of people stored in a MySQL database. I've configured the Repeat Region so that there is a checkbox included in each result "cell." I'd like to make it so that a user can check the results he wants, press Submit, and have information from each selected result inserted into a different table as a unique record. How would I do this?

Thanks,

Gabe

TOPICS
Server side applications
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2009 Jul 13, 2009

Any ideas?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 13, 2009 Jul 13, 2009

I think you already said how to do it. Create a form with a checkbox out of your query results wrapped in a repeated region. In checkbox value of repeated region enter dynamic value of query results. Then submit form to insert record script which is located in your form "action".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2009 Jul 14, 2009

But what is the dynamic value for the checkbox? The checkbox isn't getting any values anywhere--the user checks it herself to decide whether or not the record will be inserted into a different table--and there might be 1 record, 5 records, 50 records, or anywhere in between based on whatever the search turns up. I'm not sure I understand your answer (I'm more of a designer by trade).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 14, 2009 Jul 14, 2009
the user checks it herself...

You only have women visiting your website? Supply code of your repeat region and I'll show you where you add dynamic text for checkbox value. basically it will be something like

<?php do { ?>

<input type="checkbox" name="dynamic_checkbox" value="<?php echo $recordset['value']; ?>"> <?php echo $recordset['value']; ?><br>

<?php } while ($row_recordset = mysql_fetch_assoc(recordset)); ?>

The red part is the dynamic value in the checkbox the blue part is what is displayed on the page.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2009 Jul 14, 2009

Haha, no, all genders are welcome! Here's the code for the page, and thanks for the form that the repeat region is located in:

<form action="<?php echo $editFormAction; ?>" id="form2" name="form2" method="POST">   <?php if ($totalRows_searchresults > 0) { // Show if recordset not empty ?>     <br />       <?php do { ?>         <table >         <tr>           <?php $searchresults_endRow = 0; $searchresults_columns = 3; // number of columns $searchresults_hloopRow1 = 0; // first row flag do {     if($searchresults_endRow == 0  && $searchresults_hloopRow1++ != 0) echo "<tr>";    ?>           <td><p><?php echo $row_searchresults['firstname']; ?> <?php echo $row_searchresults['lastname']; ?></p>             <p><?php echo $row_searchresults['email']; ?></p>             <p><?php echo $row_searchresults['city']; ?>, <?php echo $row_searchresults['state']; ?></p>             <p>Network Size: <?php echo $row_searchresults['networksize']; ?>+</p>             <p>Choose this Agent.               <input type="checkbox" name="choose" id="choose" />               <input name="agentemail" type="hidden" id="agentemail" value="<?php echo $row_searchresults['email']; ?>" />               <input name="agentid" type="hidden" id="agentid" value="<?php echo $row_searchresults['agentid']; ?>" />           </p></td>           <?php  $searchresults_endRow++; if($searchresults_endRow >= $searchresults_columns) {   ?>         </tr>         <?php $searchresults_endRow = 0;   } } while ($row_searchresults = mysql_fetch_assoc($searchresults)); if($searchresults_endRow != 0) { while ($searchresults_endRow < $searchresults_columns) {     echo("<td> </td>");     $searchresults_endRow++; } echo("</tr>"); }?>               </table>       <?php } while ($row_searchresults = mysql_fetch_assoc($searchresults)); ?>       <?php } // Show if recordset not empty ?>   <?php if ($totalRows_searchresults > 0) { // Show if recordset not empty ?>     <input type="submit" name="submit2" id="submit2" value="Submit" />     <?php } // Show if recordset not empty ?>     <input name="clientid" type="hidden" id="clientid" value="<?php echo $_GET['clientid']; ?>" />     <input name="campaign_id" type="hidden" id="campaign_id" value="<?php echo $_GET['campaign_id']; ?>" />   <input type="hidden" name="MM_insert" value="form2" /> </form>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 14, 2009 Jul 14, 2009

<p>Choose this Agent.

<input type="checkbox" name="choose" id="choose" value="<?php echo $row_searchresults['XXXXXX']; ?>" />

<input name="agentemail" type="hidden" id="agentemail" value="<?php echo $row_searchresults['email']; ?>" />

<input name="agentid" type="hidden" id="agentid" value="<?php echo $row_searchresults['agentid']; ?>" />

</p>

Change XXXXXX to the dynamic value you'd like for the checkbox value. You can drag values from the Bindings window to the checkbox value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2009 Jul 14, 2009

Okay, but what would that dynamic value be?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 14, 2009 Jul 14, 2009

Dude, it's your record. Insert whatever value you want from your DB table field queried through recordset. If you still don't understand then I recommend that you open Dreamweaver, hit F1 and enjoy reading. Or perhaps you missed the part earlier where I said:

You can drag values from the Bindings window to the checkbox value.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2009 Jul 14, 2009

I did what you suggested and inserted a dynamic value. I arbitrarily chose 'agentid', but it ended up producing the same results that I started with. Maybe I should try explaining what I'm trying to do a bit better: I have a search form on the page that a user can use to search one table. Each result has a checkbox next to it. The user could then hit a submit button, and only the records that he checked would be uploaded to a different table. My problem is that the check function doesn't seem to work: for some reason, no matter which box gets checked--even if no boxes are checked--the last search result gets uploaded to the second table when I hit submit. I'm not sure why that keeps happening.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 16, 2009 Jul 16, 2009

So I guess u are trying to insert multiple records in second table. What's the values u want to store in that second table? I think the the first variable(except the primary key of 2nd table) is the agentid.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2009 Jul 16, 2009

That's correct. I'd also store clientid, agentemail, and campaign_id.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 16, 2009 Jul 16, 2009

You can try check HERE and HERE. If you are looking for more, look at HERE

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2009 Jul 17, 2009
LATEST

Thanks a lot! I'll definitely take a look.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines