Jump to content

display DB records


adzie

Recommended Posts

hi guys, I'm slowly getting used to basic coding but some things are still eluding me, thanks for all your help.

 

I have this script to display information from my database which I wish to eventually turn into a form, the problem I am encountering at present is that only the option boxes on the first row reflect the DB. all fields which are just simple display show correctly but the two end columns do not update past the first row.

 

any thoughts?

 

 

<?php

$title="Status Report";

$title2=$Title."<center>Stats</center></font></u>";

 

$msg = $Body."<center>";

 

{

        $sq2l="UPDATE car SET reg='".$_POST[reg]."', type='".$_POST['type']."', mods='".$_POST['mods']."', group='".$_POST['group']."', mark='".$_POST['mark']."', status='".$_POST['status']."', active=".$_POST['active']."', allocation=".$_POST['allocation']."', nextserv=".$_POST['nextserv']."'  where ac_id='".$_POST['id']."'";

        if(mysql_query($sql2,$conn))

{

$msg.=$Body."Database updated successfully<br><a href=index.php?page=management&managementpage=users&use=view>Click here edit another user</a><br>

<br><a href=admin.php>".$Body."Admin page</font></u></b></a><br>

<a href=index.php>".$Body."Home</font></u></b></a><br>";

}

 

 

$sql="select * from car where group=3 order by mods ASC";

$query = mysql_query($sql);

$msg .= "<table border=1 align=center><tr><td><strong>Allocation</strong></td><td><strong>mods</strong></td><td><strong>Reg</strong></td><td><strong>Type</strong></td><td><strong>Mark</strong></td><td><strong>Hours</strong></td><td><strong>Status</strong></td><td><strong>Next Service</strong></td></tr>";

while($row = mysql_fetch_row($query))

 

{

$query_hours = "SELECT sec_to_time(sum(time_to_sec(t2.duration))) AS duration_sum FROM car t1, car_reports t2 WHERE t1.reg=\"".$row[5]."\" AND t1.reg=t2.car";

 

$result_hours = mysql_query($query_hours);   

  if (mysql_numrows($result_hours) > 0)

{

$time = mysql_result($result_hours,0,"duration_sum");

}

{

if($row['10'] == 0)

{

  $UnServiceable = "selected";  

      }

      elseif($row['10'] == 1)

{

  $Serviceable = "selected";

  }

    if($row['12'] == 0)

{

  $Minor = "selected";  

      }

      elseif($row['12'] == 1)

{

  $Major = "selected";  

      }

          elseif($row['12'] == 2)

{

  $Minorstar = "selected";  

      }

 

$msg .= "<tr align=center><td><input type=\"text\" name=\"allocation\" value=\"".$row['11']."\"></td><td><strong>".$row['6']."</strong></td><td>".$row['5']."</td><td>".$row['1']."</td><td>".$row['2']."</td><td>".$time."</td>

<td><select name=\"".$row['10']."\"><option value=0 ".$UnServiceable.">UnServiceable</option><option value=1 ".$Serviceable.">Serviceable</option></select>

<td><select name=\"".$row['12']."\"><option value=0 ".$Minor.">Minor</option><option value=1 ".$Major.">Major</option><option value=2 ".$Minorstar.">Minor Star</option></select></tr>";  

 

 

}

 

}      

 

 

$msg.="</table>";

 

 

 

}

?>

 

Link to comment
Share on other sites

You have a lot of unnecessary stuff in there, but I think I understand the question. You basically display a table from a database, except rows 10 and 12 are displayed as drop down lists, where the field value is the name of the drop down. And only the first row working.

 

By "not working," I'm assuming you mean that the proper options are not being selected in the drop downs.

 

It's your chunk of if else "selected" stuff I'm skeptical of. Try trouble shooting it with various debug methods, like after

 

          elseif($row['12'] == 2){

                  $Minorstar = "selected";                 

            }

 

Put an end-all else statement

 

          else {

                  $major = "selected";                 

            }

 

So if all the broken drop downs all go to select "Major", you know the problem is that they aren't picking up on any of the if else stuff.

 

Maybe put the numbers in quotes -

 

          elseif($row['12'] == "2"){

                  $Minorstar = "selected";                 

            }

Link to comment
Share on other sites

insert line

$UnServiceable = $Serviceable = $Minor = $Major = $Minorstar = "";

before line

if($row['10'] == 0)
               {
                  $UnServiceable = "selected";                  
            }
            elseif...

   

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.