Jump to content

Recommended Posts

Ok so here is the problem. the list box is so small and cant display the names inside it. It drops down, but everything is white or blank. How ever it does drop down approx appropriate length for amount of entries inside. How do I make this box wider? any help?

 

Thank you in advance.

 

  <table width="87%" border="0">
    <tr>
      <td width="34%">Job Name:</td>
      <td width="60%"><?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("time_sheets") or die(mysql_error());

$result = @mysql_query("SELECT jobs FROM jobs");

print "<select name=\"Select a Job\">\n";
while ($row = mysql_fetch_assoc($result))
{
$jobs = $row['jobs'];
print "<option value=$jobs>\n";
}
print "</select>\n";
print "</p>\n";

?></td>
      <td width="6%"> </td>
    </tr>
  </table>

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/
Share on other sites

The code looks pretty good. I'm no expert, just trying to help, but you have

 

select jobs from jobs.

 

try select jobs FROM time_sheets.jobs

 

and get rid of the whole line: mysql_select_db

 

I'm assuming you have a column named jobs in a table named jobs in a database named time_sheets, right?

 

Are there not any entries showing up at all, or are they there, but you can't see them off to the right?

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1001054
Share on other sites

Are there not any entries showing up at all, or are they there, but you can't see them off to the right?

 

I assume they are there. there is enough room for about 2 digits. That is how wide the list box is. Maybe 4 digits. It has 4 slots that highlight when you mouse over them, but doesnt seem to be wide enough to show the data inside it. there are currently 4 entries in the data base.

 

 

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1001062
Share on other sites

Ok, but if there is enough for 2-4 digits, you would at least see a letter or two, right? If it is just white space, then it's a problem with the query or the database. If you can see any letters in there, then it's something else. Do you have a screen shot or a place to go look at the page?

 

Also, if you're working live, view the page source and see if you see the list of jobs there.

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1001075
Share on other sites

Ok, but if there is enough for 2-4 digits, you would at least see a letter or two, right? If it is just white space, then it's a problem with the query or the database. If you can see any letters in there, then it's something else. Do you have a screen shot or a place to go look at the page?

 

Also, if you're working live, view the page source and see if you see the list of jobs there.

 

 

ok here is the page source

 

Admin Area<p><a href=logout.php>Logout</a> 

<form action="insert.php" method="post">
  <p align="left"> </p>
<table width="87%" border="0">
    <tr>
      <td width="34%">Date: </td>
      <td width="60%"><input type="text" name="date" /></td>
      <td width="6%"> </td>
    </tr>

  </table>
  <table width="87%" border="0">
    <tr>
      <td width="34%">Firstname: </td>
      <td width="60%"><input type="text" name="firstname" /></td>
      <td width="6%"> </td>
    </tr>
  </table>

  <table width="87%" border="0">
    <tr>
      <td width="34%">Lastname: </td>
      <td width="60%"><input type="text" name="lastname" /></td>
      <td width="6%"> </td>
    </tr>
  </table>
  <table width="87%" border="0">

    <tr>
      <td width="34%">Job Name:</td>
      <td width="60%"><select name="Select a Job">
<option value=Center Point>
<option value=Emory Hillel>
<option value=warner robins maintnance bldg>
<option value=Warner Robins Post Office>
<option value=warner Robins Smith Center>
</select>
</p>
</td>
      <td width="6%"> </td>

    </tr>
  </table>
  <table width="87%" border="0">
    <tr>
      <td width="34%">Time In:</td>
      <td width="60%"><input type="text" name="timein" /></td>
      <td width="6%"> </td>
    </tr>

    <tr>
      <td>Time Out:</td>
      <td><input type="text" name="timeout" /></td>
      <td> </td>
    </tr>
    <tr>
      <td>Lunch:</td>
      <td><input type="text" name="lunch" /></td>

      <td> </td>
    </tr>
    <tr>
      <td>Total Hours:</td>
      <td><input type="text" name="totalhours" /></td>
      <td> </td>
    </tr>
  </table>

  <table width="87%" border="0">
    <tr>
      <td width="7%"> </td>
      <td width="7%"> </td>
      <td width="7%"> </td>
      <td width="13%"> </td>
      <td width="38%"><input type="submit" /></td>
      <td width="7%"> </td>
      <td width="7%"> </td>

      <td width="7%"> </td>
      <td width="7%"> </td>
    </tr>
  </table>

</form>

Download as <a href='xls.php'>.xls </a>file!<b><center>Database Output</center></b><br><br><b>0000-00-00 James McKay</b><br>warner robins 05:00:00 - 09:00:00 Lunch (-0.00)<br>Total hours for 0000-00-00 = 4.00<hr><br><b>2010-01-23 James McKay</b><br>warner robins 05:00:00 - 09:00:00 Lunch (-0.00)<br>Total hours for 2010-01-23 = 4.00<hr><br><b>2010-01-24 James McKay</b><br>center point 09:00:00 - 08:00:00 Lunch (-0.00)<br>Total hours for 2010-01-24 = 11.00<hr><br><b>2010-01-24 James McKay</b><br>center point 09:00:00 - 08:00:00 Lunch (-0.00)<br>Total hours for 2010-01-24 = 11.00<hr><br><b>2010-01-24 James McKay</b><br>center point 09:00:00 - 08:00:00 Lunch (-0.00)<br>Total hours for 2010-01-24 = 11.00<hr><br><b>2010-01-24 James McKay</b><br>center point 09:00:00 - 08:00:00 Lunch (-0.00)<br>Total hours for 2010-01-24 = 11.00<hr><br><b>2010-01-24 James McKay</b><br>center point 09:00:00 - 08:00:00 Lunch (-0.00)<br>Total hours for 2010-01-24 = 11.00<hr><br>

 

 

 

near the middle it show the 5 option values. hillel, center point warner robins...

 

here is a screen shot also

 

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1001078
Share on other sites

Aha, ok. I see what's going on here.  You have a value, but not a name. Sorry I missed it the first time.

 

What are the columns in your table?  Do you have a job id, job name, etc?

 

What it needs to look like is something like this:

 

print "<option value=$jobs[id]>$jobs[name]</option>\n";

 

that way, the value of the selector is the job id, and what shows on the form is the job name.  In addition, your select box name shouldn't have any spaces; so it should be like:

 

print "<select name=\"JobName\">\n";

 

When you put "select a job", you probably meant for that to be the first item they see in the drop down, which would mean it would be like this:

 

print "<select name=\"JobName\">\n";
print "<option selected value="Select a Job">Select a Job</option>\n";

 

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1001102
Share on other sites

Aha, ok. I see what's going on here.  You have a value, but not a name. Sorry I missed it the first time.

 

What are the columns in your table?  Do you have a job id, job name, etc?

 

What it needs to look like is something like this:

 

print "<option value=$jobs[id]>$jobs[name]</option>\n";

 

that way, the value of the selector is the job id, and what shows on the form is the job name.  In addition, your select box name shouldn't have any spaces; so it should be like:

 

print "<select name=\"JobName\">\n";

 

When you put "select a job", you probably meant for that to be the first item they see in the drop down, which would mean it would be like this:

 

print "<select name=\"JobName\">\n";
print "<option selected value="Select a Job">Select a Job</option>\n";

 

i only have 1 column in my table called jobs.

 

so now I have this

 

print "<option value=$jobs[jobs]>$jobs[jobs]</option>\n";

 

and now it shows only the first letter of each job name

 

but now my code looks like

 

  <table width="87%" border="0">
    <tr>
      <td width="34%">Job Name:</td>
      <td width="60%"><?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("time_sheets") or die(mysql_error());

$result = @mysql_query("SELECT jobs FROM jobs");

print "<select name=\"JobName\">\n";
print "<option selected value=\"Select a Job\">  Select  A  Job  </option>\n";
while ($row = mysql_fetch_assoc($result))
{
$jobs = $row['jobs'];
print "<option value=$jobs[jobs]>$jobs[jobs]</option>\n";
}
print "</select>\n";
print "</p>\n";

?></td>
      <td width="6%"> </td>
    </tr>
  </table>

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1001105
Share on other sites

What I would do is to add an extra field to your jobs table and call it JobID, and make it a primary, auto_increment field. If you have phpMyAdmin, you can do this. You'll want these criteria:

 

Field Name: jobID

Type: INT

Length: 5

Not Null

Extra: auto_increment

 

then make that field the primary/index field

 

This way, your jobs will have an id and a name. You shouldn't have to alter how you add jobs to the database, an auto_increment index field should do it automatically.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1001112
Share on other sites

What I would do is to add an extra field to your jobs table and call it JobID, and make it a primary, auto_increment field. If you have phpMyAdmin, you can do this. You'll want these criteria:

 

Field Name: jobID

Type: INT

Length: 5

Not Null

Extra: auto_increment

 

then make that field the primary/index field

 

This way, your jobs will have an id and a name. You shouldn't have to alter how you add jobs to the database, an auto_increment index field should do it automatically.

 

Ok, so I have tried everything you said I think and still nothing different. Am I doing something wrong... or what am I doing wrong?

 

<td width="60%"><?php

mysql_connect("localhost", "root", "") or die(mysql_error());

$result = @mysql_query("SELECT jobs FROM time_sheets.jobs");

print "<select name=\"Jobs\">\n";
print "<option selected value=\"Select a Job\">Select A Job</option>\n";
while ($row = mysql_fetch_assoc($result))
{
$jobs = $row['jobs'];
print "<option value=$jobs[iD]>$jobs[jobs]</option>\n";
}
print "</select>\n";
print "</p>\n";

?></td>

 

I even called my table and db like you said just so you know I am trying. lol  I hope that is worth something for your help. I really do appreciate it. I feel that we are close in getting this solved. I have also added another ss from phpmyadmin. Are my tables set up correctly?

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1001602
Share on other sites

It might be that the existing jobs you had in the database don't have an id yet. It may apply only to new jobs. Look at the table and see if there is an id on those. If not, you can always add it for now and see (1, 2, 3).

 

And then modify my code above to look like this:

 

<td width="60%"><?php

mysql_connect("localhost", "root", "") or die(mysql_error());

$result = @mysql_query("SELECT jobID,jobs FROM time_sheets.jobs");

print "<select name=\"Jobs\">\n";
print "<option selected value=\"Select a Job\">Select A Job</option>\n";
while ($row = mysql_fetch_assoc($result))
   {
   $jobs = $row['jobs'];
   print "<option value=$jobs[jobID]>$jobs[jobs]</option>\n";
   }
print "</select>\n";
print "</p>\n";

?></td>

Link to comment
https://forums.phpfreaks.com/topic/189677-php-list-box/#findComment-1002476
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.