texmansru47 Posted September 17, 2010 Share Posted September 17, 2010 Hey everyone. I am creating a website so my family can select from the list of present my daugther has asked for. I have them logging in, and that works. I have the table data set and the search and table display works. But I would like to display the list (as in the code below) but with a checkbox in the first column (add a column). From that the authenticated user can click on the item they have purchased and that selection will be moved to another table (called purchased). I have that code. The only thing I cannot figure out is to present the data in list form with a checkbox (like you would see on an order form). Here is the display code (there is no error checking at this point): <head><LINK REL="SHORTCUT ICON" HREF="cmwschl.ico"></head> <body bgcolor="#C0C0C0"> <font face="Arial" color="#000080">Books from the Selected Series</font> </h1> <hr font color="Navy" font size="3"> <center> <table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000"> <tr> <td width="170" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Number</center></font></b></center></td> <td width="140" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Group</center></font></b></center></td> <td width="100" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Title</center></font></b></center></td> </tr> <?php $con = mysql_connect("localhost","twilson","R00tb33r!") or die('Connection: ' . mysql_error());; mysql_select_db("CMWWeb", $con) or die('Database: ' . mysql_error()); ?> <? $group = $_POST['bookgrp']; //if ($Prod <> 0) { $sql = "SELECT * FROM `OpenBooks` WHERE `bookgrp`= '$group'"; $results = mysql_query($sql); if ($results) { //this will check if the query failed or not if (mysql_num_rows($results) > 0) { //this will check if results were returned while($copy = mysql_fetch_array($results)) { $variable1=$copy['booknum']; $variable2=$copy['bookgrp']; $variable3=$copy['booktitle']; //table layout for results print ("<tr>"); print ("<td><center>$variable1</center></td>"); print ("<td><center>$variable2</center></td>"); print ("<td><left>$variable3</left></td>"); print ("</tr>"); } } else { echo "No results returned"; } } else { echo "Query error: ".mysql_error(); } mysql_close($con); ?> </table> </center> Link to comment https://forums.phpfreaks.com/topic/213623-how-to-retrieve-data-from-a-table-so-that-data-can-be-selected/ Share on other sites More sharing options...
Mod-Jay Posted September 17, 2010 Share Posted September 17, 2010 Dont Think You can do that with php.. except with a button i have fixed up the code for you though <?php //if ($Prod <> 0) { $sql = mysql_suery ("SELECT * FROM OpenBooks WHERE bookgrp='{$_POST['bookgrp']}'") or die(mysql_error()); $results = mysql_query($sql); if ($results) { //this will check if the query failed or not if (mysql_num_rows($results) > 0) { //this will check if results were returned while($copy = mysql_fetch_array($results)) { $variable1=$copy['booknum']; $variable2=$copy['bookgrp']; $variable3=$copy['booktitle']; //table layout for results print ("<tr>"); print ("<td><center>$variable1</center></td>"); print ("<td><center>$variable2</center></td>"); print ("<td><left>$variable3</left></td>"); print ("</tr>"); } } else { echo "No results returned"; } } else { echo "Query error: ".mysql_error(); } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/213623-how-to-retrieve-data-from-a-table-so-that-data-can-be-selected/#findComment-1111903 Share on other sites More sharing options...
roopurt18 Posted September 17, 2010 Share Posted September 17, 2010 If I understand, then you're trying to create a drop-down list where each item is a checkbox followed by a label. These controls are often supported in languages like Java or Microsoft's Visual XYZ. However this is a web page that displays HTML; therefore you're limited to what you can make in HTML. However if you want to get fancy you can create your own control using a combination of HTML, JavaScript, CSS, and DOM manipulation. It'll take many hours in and of itself and is rightfully its own project. Or you can see if such a control is implemented in one of the popular JavaScript frameworks such as YUI, jquery, mootools, dojo, etc. Once you do this, the page will only work correctly if the user has JavaScript enabled. Link to comment https://forums.phpfreaks.com/topic/213623-how-to-retrieve-data-from-a-table-so-that-data-can-be-selected/#findComment-1111982 Share on other sites More sharing options...
texmansru47 Posted September 17, 2010 Author Share Posted September 17, 2010 Ok... This is sounding like not the route to go. How about this... Make the list generated from the table be HTML where the user can select and then from there I can create code to do the manipulation of the data from there? I have read somewhere that you can list the data with HTML links... but I need to research that. Cheers, Link to comment https://forums.phpfreaks.com/topic/213623-how-to-retrieve-data-from-a-table-so-that-data-can-be-selected/#findComment-1112067 Share on other sites More sharing options...
Mod-Jay Posted September 18, 2010 Share Posted September 18, 2010 I can Make up A code For You to work with if you want Link to comment https://forums.phpfreaks.com/topic/213623-how-to-retrieve-data-from-a-table-so-that-data-can-be-selected/#findComment-1112442 Share on other sites More sharing options...
diocyria Posted September 18, 2010 Share Posted September 18, 2010 Unless I am mistaken on what you are trying to do, simply surround all of your SQL output (in other words the HTML table element) with a form element. Then the first column of the table for each row pulled (since each one is in the "not-yet-purchased" list), add a first column to the output that states something like <input type="checkbox" name="id" value="<?php echo $returnedRow['id']; ?>" /> Then when the user clicks the button at the bottom of the "form", all values supplied as 'id' in the form submission query should simply be grabbed and moved to the new table. If you need a more detailed example, just let me know. Link to comment https://forums.phpfreaks.com/topic/213623-how-to-retrieve-data-from-a-table-so-that-data-can-be-selected/#findComment-1112449 Share on other sites More sharing options...
texmansru47 Posted September 20, 2010 Author Share Posted September 20, 2010 diocyria - I do beleive that is what I desire. I just need some way to have the user select a value that was generated from a pre-existing table and from that the selected data can be used for adding to another table. On the example code would that create a checkbox that could be added in a IF THEN Loop? Link to comment https://forums.phpfreaks.com/topic/213623-how-to-retrieve-data-from-a-table-so-that-data-can-be-selected/#findComment-1113281 Share on other sites More sharing options...
texmansru47 Posted September 25, 2010 Author Share Posted September 25, 2010 diocyria, I think a need a more detailed example. the form I have is being generated from a table search. //if ($Prod <> 0) { $sql = "SELECT * FROM `OpenBooks` WHERE `bookgrp`= '$group'"; $results = mysql_query($sql); if ($results) { //this will check if the query failed or not if (mysql_num_rows($results) > 0) { //this will check if results were returned while($copy = mysql_fetch_array($results)) { $variable1=$copy['booknum']; $variable2=$copy['bookgrp']; $variable3=$copy['booktitle']; //table layout for results print ("<tr>"); print ("<td><center>$variable1</center></td>"); print ("<td><center>$variable2</center></td>"); print ("<td><left>$variable3</left></td>"); print ("</tr>"); } } else { echo "No results returned"; } } else { echo "Query error: ".mysql_error(); } mysql_close($con); ?> Any ideas how to implement a selection check box in this format? Link to comment https://forums.phpfreaks.com/topic/213623-how-to-retrieve-data-from-a-table-so-that-data-can-be-selected/#findComment-1115372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.