Jump to content

Need a little guidence in linking


rockers

Recommended Posts

Hey ,

Im having a right head scratching time trying to figure out how to complete my script here.

I have an idea that i want a table shown from my web server so that i have say.. a server then a set number of days mon-sun. The mon-sun days i want a drop down menu saying one of three values.. that i have got sorted.

I also have a database with server names that i can query and get a display in a table on what the values are...

what im having problems with it how i can link those two elements together...

i want each day to have a drop down section to choose one of three values.. then when all is done.. to submit this back to the database.

I can't figure out how to link these damned things together.... can someone point me to how i can find this out ??

below is my code so you can get an idea what im rambling about :P

<?php
/* set the allowed order by columns */

$default_sort = 'customer';
$allowed_order = array ('customer', 'server name','monday','tuesday','wednesday','thursday','friday','saturday','sunday');

/* if order is not set, or it is not in the allowed
* list, then set it to a default value. Otherwise,
* set it to what was passed in. */
if (!isset ($_GET['order']) ||
    !in_array ($_GET['order'], $allowed_order)) {
    $order = $default_sort;
} else {
    $order = $_GET['order'];
}

/* connect to db */
mysql_connect ('localhost','root','');
mysql_select_db ('sqltest');

/* construct and run our query */
$query = "SELECT * FROM test ORDER BY $order";
$result = mysql_query ($query);

/* make sure data was retrieved */
$numrows = mysql_num_rows($result);
if ($numrows == 0) {
    echo "No data to display!";
    exit;
}

/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo "<TABLE border=1>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column) {
    /* check if the heading is in our allowed_order
     * array. If it is, hyperlink it so that we can
     * order by this column */
    echo "<TD><b>";
    if (in_array ($heading, $allowed_order)) {
        echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>";
    } else {
        echo $heading;
    }               
    echo "</b></TD>\n";
}
echo "</TR>\n";

/* reset the $result set back to the first row and
* display the data */
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
    echo "<TR>\n";
    foreach ($row as $column) {
        echo "<TD>$column</TD>\n";
    }
    echo "</TR>\n";
}
echo "</TABLE>\n";


$query = mysql_query("SELECT * FROM cat_name");
echo "<select name=\"Result1\">";

while ($row = mysql_fetch_object($query))
{

echo "<option value=\"$row->id\">$row->Result1</option>\r\n";
echo "<option value=\"$row->id\">$row->Result2</option>\r\n";
echo "<option value=\"$row->id\">$row->Result3</option>\r\n";
}
echo "</select>";



?>

Am i going about this the right way or making this harder than it needs to be ??

Thanks for you paitience in reading this, im quite new to PHP and mixing it with Mysql is a bit much for me im afraid

[attachment deleted by admin]
Link to comment
https://forums.phpfreaks.com/topic/25831-need-a-little-guidence-in-linking/
Share on other sites

  • 2 weeks later...

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.