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
https://forums.phpfreaks.com/topic/141439-php-combo-box/#findComment-740350
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
https://forums.phpfreaks.com/topic/141439-php-combo-box/#findComment-740519
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.