Jump to content

How to retrieve data from a table so that data can be selected


texmansru47

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.