Trying to make a short to do list.

show item to do-->click who you are

$who and $item sends to top to show that item no longer there, but the rest are

<?
echo "Here is the list of things that need to be done!";
echo "<form>";
	while($row3 = mysql_fetch_array($result6))
	  { 
	  //where and item
	  echo "<b> Where:</b> &nbsp;" . $row3['where'] . "&nbsp; Item: &nbsp;" . $row3['item'] . "</td>&nbsp;<input type='hidden' name='submitteddone' id='submitteddone' value=\"{$row3['item']}\"><input type='checkbox' name='itemchecked' id='itemchecked' value=\"{$row3['item']}\">";
	 
          echo "</br>";
	  }while($row4 = mysql_fetch_array($result5))
  { 
	// Show who is clocked in
	echo "<span ><span style=\"padding-left:4px;\"\"><input type=\"submit\" class=\"person-in\" name=\"persondid\" id=\"persondid\" value=\"{$row4['person']}\" />";
   }


	echo "</form>";
?>

I can get the second 'while' to show up. Much less get the second to show up beside the item shown.

Example:

Where: Garage Item: Sweep it dude! [Mom] [Dad] [Son]
Where: Kitchen Item: Mop it dude! [Mom] [Dad] [Son]
Where: Garage Item: Clean it dude! [Mom] [Dad] [Son]

Recommended Answers

All 8 Replies


I can get the second 'while' to show up. Much less get the second to show up beside the item shown.

scratch that: I "can not" get the second array to show.

Is there a better route to go?

---------

In the code above I used 'checkbox' to at least have the person check which they did.

The scenario I mention was having a submit button per person per item

----------

either is fine. Knowing the way to do both would be better.

Member Avatar for jmichae3

- you should be using <?php instead of <?
- bad code indenting on those whiles (actually all around)
- use mysql_fetch_assoc instead of mysql_fetch_array
- single quotes within array within double quotes string have not worked well for me (seems this technique's just fine, seems to work for you). I typically move the row variable code expansion out of the string. example:

value=\".$row3['item']."\">

- you have 2 double-quotes in your html on line 14.
- b and /b tags are deprecated as of HTML 5. use strong and /strong instead. replace i with em if you have any html which uses it.
- big difference between can and can't. I think you meant can't at the bottom.


you really should be putting your queries close to your fetches to maintain some semblance of readability.

ok...hey thanks for the critique! I love it!

ok so here are the changes

-changed the intro php
-worked on my indention (yes messy but not sure if this is better for reading)
-changed to assoc
-replaced with your value example
-removed the double quote on the second "while"
- replaced the deprecated bold, and...

What is i for em? I have seen 'em' as a measurement in CSS.

Added:
-Pagetitle (to show sticky form)
-DB update stript
-and fetch

<?php
$pagetitle = "Checklist";

$con= //Database Credentials 

//Updating Item on list with, Who did it, and Now Completed
if(isset($_POST['submitteddone']))
{
   $person = $_POST['person'];
   $item = $_POST['item'];
mysql_select_db("checklistdb", $con);
mysql_query("UPDATE checklist SET person = '$person' AND completed = '1'
WHERE item = '$submitteddone'"); 
}

$result5 = mysql_query("SELECT * FROM person WHERE ready= '1'");
$result6 = mysql_query("SELECT * FROM checklist WHERE active='1' AND completed='0' ");

 echo "Here is the list of things that need to be done!";
 echo "<form action=\"checklist.php\">";
 while($row3 = mysql_fetch_assoc($result6))
   { 
    //where and item
    echo "<strong> Where:</strong> &nbsp;" . $row3['where'] . "&nbsp; <strong>Item:</strong> &nbsp;" . $row3['item'] . "</td>&nbsp;<input type='hidden' name='submitteddone' id='submitteddone' value=\"{$row3['item']}\"><input type='checkbox' name='itemchecked' id='itemchecked' value=\".$row3['item']."\">";
 
    echo "</br>";
   }while($row4 = mysql_fetch_assoc($result5))
      { 
	// Show who is clocked in
	echo "<span ><span style=\"padding-left:4px;\"><input type=\"submit\" class=\"person-in\" name=\"persondid\" id=\"persondid\" value=\".$row4['person']."\">";
      }
 
 
    echo "</form>";
?>

ok got it!

In php you can't retrieve the same fetch twice, from the server.

maybe not from 1 single query, but since they are different queries, it should work fine right?
Maybe your SQL code is empty, or the database has an error.
Try executing your SQL code in any database manager (phpmyadmin, access, whatever)

also, rule 24 and 26 are both echoes, might as wel combine them :)

Member Avatar for jmichae3

ok got it!

In php you can't retrieve the same fetch twice, from the server.

to be more precise, with databases in general you can't retrieve the same row twice without re-querying. it's made to do one line at a time. If you need to process a given row twice, you need to handle that by generating more redundancy from a single fetch.

If you want categorized select tags with optiongroups, then try this:

echo "<select name='blah'>\n";
$result_dropdown = mysql_query("
SELECT optn_value, optn_text, is_optgroup
FROM optn 
ORDER BY optn_text ASC", $link) or die("ERROR 1");
while ($row=mysql_fetch_assoc($result_dropdown)) {
    if ($row['is_optgroup']) {
        echo "    <optgroup label='".$row['optn_text']."'>\n";
    } else {
        echo "     <option value='".$row['optn_value']."'>".$row['optn_text']."</option>\n";
    }
}
mysql_free_result($result_dropdown);
<select name="aselectbox">
   <optgroup label="Color Laser Printers">
    <option value="okiC9650">Okidata C9650</option>
    <option value="okiC830">Okidata C830</option>
    <option value="okiC711">Okidata C711</option>
    <option value="okiC610">Okidata C610</option>
    <option value="okiC6150">Okidata C6150</option>
    <option value="okiC530dn">Okidata C530dn</option>
    <option value="okiC330dn">Okidata C330dn</option>
    <option value="okiC3600n">Okidata C3600n</option>
   </optgroup>
   <optgroup label="Mono Laser Printers">
    <option value="okiB930">Okidata B930</option>
    <option value="okiB6500">Okidata B6500</option>
    <option value="okiB6300SFS">Okidata B6300 Series SFS</option>
    <option value="okiB6300">Okidata B6300</option>
    <option value="okiB6250">Okidata B6250</option>
   </optgroup>
   <optgroup label="Mono LED Printers">
    <option value="okiB4600">Okidata B4600</option>
    <option value="okiOL810e">Okidata OL-810e</option>
    <option value="okiOL410e">Okidata OL-410e</option>
   </optgroup>
   <optgroup label="Inkjet Office All-in-Ones">
    <option value="hp8500wireless">HP 8500 Wireless</option>
    <option value="hp6500wireless">HP 6500 Wireless</option>
    <option value="kodak6150">Kodak ESP 6150 All In One</option>
    <option value="kodak9250">Kodak ESP 9250 All In One</option>
   </optgroup>
  </select>
Member Avatar for jmichae3

if you need two queries in sequence, do 2 queries!

Member Avatar for jmichae3

I just realized my optgroup code need MAJOR REWORK. it should be 2 nested selects due to the fact that the optgroups have a close tag that should be generated. sorry about that.

<?php
echo "<select name='blah'>\n";
$result_og = mysql_query("
SELECT og_text
FROM og
ORDER BY og ASC", $link) or die("ERROR 1");
while ($rowog=mysql_fetch_assoc($result_dropdown)) {
    echo "    <optgroup label='".$rowog['og_text']."'>\n";
    $result_optn = mysql_query("
    SELECT optn_value, optn_text
    FROM optn
    ORDER BY optn_text ASC", $link) or die("ERROR 2");
    while ($rowoptn = mysql_fetch_assoc($result_optn)) {
        echo "        <option value='".$row['optn_value']."'>".$row['optn_text']."</option>\n";
    }
    echo "    </optgroup>\n";
    mysql_free_result($result_optn);
}
mysql_free_result($result_dropdown);
echo "</select>\n";
?>

the table structure is one table (optn for option) dependent upon another (og for optgroup).

create table og (
id int autoincrement not null,
og_text varchar(100) not null,
PRIMARY KEY(id),
)
create table optn (
id int autoincrement not null,
optn_text varchar(100) not null,
optn_value varchar(100) not null,
PRIMARY KEY(id),
)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.