Jump to content

Php combo box


Phpnewbie23

Recommended Posts

<?php

// connect to database.

$sql = "SELECT k, v FROM table";

if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    echo "<select>";
    while ($row = mysql_fetch_assoc($result)) {
      echo "<option value='{$row['v']}'>{$row['k']}</option>";
    }
    echo "</select>";
  }
}

?>

Link to comment
Share on other sites

Thanks thorpe

 

I understand your code but dont have a clue where to put it in mine?

 

The issue i am having is my data is pulled from a a database using a ODBC connector. and has all the data is pulled out of INCREMENTAL_BACKUP_REPORT on refresh which i have to admit with help has taken me a while.

 

What i would like to do now is have a combo box and populate it with my clients names and then pull all the other data out of the database. When the user selects that clients name here i below is my code so far.

 

$conn=odbc_connect('VembuDSN','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM INCREMENTAL_BACKUP_REPORT";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQLITE CONNECTION");}
  
  
echo "<table width=60% height=3% cellspacing='1' cellpadding='2' border='1'>";
echo "<tr>";
echo "<th align=center><small>Client</small</th>";
echo "<th align=center><small>Backup Name</small></th>";
echo "<th align=center><small>Start Time</small></th>";
echo "<th align=center><small>End Time</small></th>";
echo "<th align=center><small>Skipped Files</small></th>";
echo "<th align=center><small>Files Added</small></th>";
echo "<th align=center><small>Files Deleted</small></th>";
echo "<th align=center><small>Files Modified</small></th>";
echo "<th align=center><small>Orignal File Size</small></th>";
echo "<th align=center><small>Disk Space Used</small></th>";
echo "<th align=center><small>Bandwidth Used</small></th>";
echo "<th align=center><small>Backup Status</small></th>";
echo "</tr>";



   while (odbc_fetch_row($rs))

{
  $client=odbc_result($rs,"CLIENT_NAME");
   $backupname=odbc_result($rs,"BACKUP_NAME");
   $start_time=odbc_result($rs,"BACKUP_START_TIME");
   $end_time=odbc_result($rs,"BACKUP_END_TIME");
   $skipfiles=odbc_result($rs,"NO_OF_FILES_SKIPPED");
   $filesadded=odbc_result($rs,"NO_OF_FILES_ADDED");
   $filedeleted=odbc_result($rs,"NO_OF_FILES_DELETED");
   $filemodified=odbc_result($rs,"NO_OF_FILES_MODIFIED");
   $fileoriginal=odbc_result($rs,"ORIGINAL_FILE_SIZE");
   $diskspace=odbc_result($rs,"DISK_SPACE_USED");
   $bandwidth=odbc_result($rs,"BANDWIDTH_USED");
   $remarks=odbc_result($rs,"REMARKS");

echo "<tr>";
echo "<td align=center><small>$client</small></td>","\n";
echo "<td align=center><small>$backupname</small></td>","\n";
echo "<td align=center><small>" . date("l d/m/Y H:i:s", $start_time) . "</small></td>","\n";
echo "<td align=center><small>" . date("l d/m/Y H:i:s", $end_time) . "</small></td>","\n";
echo "<td align=center><small>$skipfiles</small></td>","\n";
echo "<td align=center><small>$filesadded</small></td>","\n";
echo "<td align=center><small>$filedeleted</small></td>","\n";
echo "<td align=center><small>$filemodified</small></td>","\n";
echo "<td align=center><small>$fileoriginal</small></td>","\n";
echo "<td align=center><small>$diskspace</small></td>","\n";
echo "<td align=center><small>$bandwidth</small></td>","\n";
if ($remarks=="Success"){
echo "<td align=center><small><font color='green'><b>$remarks</b></font></small></td>"; 
}else { 
echo "<td align=center><small><font color='Red'><b>$remarks</b></font></small></td>"; 
}

echo "</tr>";
}
echo "</table>";


odbc_close($conn);
?>

 

Also how would you get rid of the border number ie 1 to go to 0 then have different colors for different rows like

 

White

Grey

White

Grey

 

and so on i am sorry for asking so much questions and stupids one as well but i am new to PHP but would like to use it alot

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.