broj1 356 Humble servant Featured Poster

Sory I am a bit tigt on time at the moment (trying to meet the deadline). I changed the function to two functions - one that draws the menu and one that draws the submenu below:

// function to draw menu (top and left)
function draw_menu($script, $items, $div_id) {

    // start the list for the menu
    $menu = "<ul>";

    // loop through the array with menus and submenus
    foreach($items as $url => $val) {

        $text = $val['text'];

        if($script == $url) {

            // if the item in the array is the current page, highlight it
            $menu .= '<li><a style="font-color:#eb0089" href="#nogo">*** '. $text . ' ***</a></li>';

        } else {

            // else display it as usual link
            $menu .= '<li><a href="' . $url . '">' . $text . '</a></li>';
        }
    }

    // end the list 
    $menu .= '</ul>';

    return $menu;
}

// function to draw submenu below the main menu on left side
function draw_sub_menu($script, $items) {

    // find the correct submenu items to draw
    foreach($items as $url => $val) {

        // if the current page is on the top level (index.php, book.php...)
        if($script == $url) {

            if(isset($val['submenu']) && !empty($val['submenu'])) {

                $submenu = draw_menu($script, $val['submenu']);

                return $submenu;

            } else {

                return '';
            }
        }

        // if the current page is not on the top level, examine each submenu entry
        if(isset($val['submenu']) && !empty($val['submenu'])) {

            if($script == $val['submenu']['url']) {

                $submenu = draw_menu($script, $val['submenu']);

                return $submenu;
            }
        }
    }

    // if no submenus were drawn return empty string
    return '';
}

To use tese functions …

broj1 356 Humble servant Featured Poster

The array and function above are not useful for any situation so when you change requirements (like you did) the array and/or the function have to be adapted to suit the requirements.

broj1 356 Humble servant Featured Poster

No, I don't think new thread is neccessary. I was away for a couple of days that's why a silence form me :-);

So if I get it right you want the same behaviour as before only that the submenus of a selectem menu appear below the main menus on the left side. I think the php code is something similar to the above snippets only that that the PHP generates divs as well and you then position the divs using CSS.

echo "<div id='submenus'>";

    // the code for submenus

echo "</div>";

I am pretty rusty as far as CSS is concerned so I hope you will manage that part yourself or some more skilled folks will add their posts (or maybe you as in a Web design forum here on DW).

broj1 356 Humble servant Featured Poster

Please explain a bit more. Do you mean to open submenus for all the menu entries by clicking on Selected projects? Is Selected projects page also a homepage?

broj1 356 Humble servant Featured Poster

Hard to say. You have a <section id="content"> but no #content in CSS but I doubt this is a problem. Try if you see the left menu without the CSS (comment out the link to the css style). If you can see the menu (as an ordinary bulletted list) than there is something in your CSS and try to tweak it. If nothing else helps post the whole scripts for menus, index and all CSS files.

broj1 356 Humble servant Featured Poster

In the index.php (and other pages like book.php...) the code should be sligtly different from above. The name of the current script should be read only once and on the very top of the script:

<?php
// the name of the current script
$script_name = end(explode('/',$_SERVER["SCRIPT_NAME"]));
?>

<!--this menu appears on the left and it is a vertical menu-->
<section id="left">
<?php
// include the menus
include('includes/left.php');
?>
</section>

<section id="content">
 <!--this menu appears on the top and it is an horizontal menu-->
 <!--top-->
<?php
// include the menus
include('includes/menu.php');
?>

But that really does not affect the functionality. The problem might be in your CSS where you style the sections. So maybe your left section is styled so it is not visible. Can you post the styles for #left and #content (and check whether you use correct IDs for the menu sections - the #content doesn't seem like a menu name). I can see both the menus OK (since I do not use any CSS).

broj1 356 Humble servant Featured Poster

Can you see it OK on my site? Copy the code exactly, make sure there are no errors. Also check your style definitions. You can post or PM your code that does not work so I can have a look.

broj1 356 Humble servant Featured Poster

I can see it. I copied the scripts to www.punkelj.si/DW/index.php. See for yourself (only Book design and index page actually work, the highlighted menu is marked with ***).

broj1 356 Humble servant Featured Poster

Here is my suggestion that uses some ideas from above:

Inthe include files for menus only have a structure for each menu (top and left) stored in a multidimensional array. Then create another file that holds the function to draw the menu (and possibly your other functions). Call a function that draw the menu from each included file. The array that holds the menu structure is slightly changed to include submenus. The function is recursive so it traverses the array and draws submenus if they exist.

The top menu script:

<?php

// include functions
include_once('includes/functions.php');

// array to hold top menu
$top_menu_items = array(

    'index.php' => array('text' => 'Home'),
    'about.php' => array('text' => 'About'),
    'news.php' => array('text' => 'News'),
    'contact.php' => array('text' => 'Contact'),
);

// call the function that draws the menu
echo draw_menu($script_name, $top_menu_items);
?>

The left menu script withsome entries having sumbenus (the logos entry has no sumbenu):

<?php

// include functions
include_once('includes/functions.php');

// array to hold left menu and submenu items
$left_menu_items = array(

    'book.php' => array(
        'text'    => 'Book Design',
        'submenu' => array('book1.php' => array('text' => 'Book submenu 1'),
                           'book2.php' => array('text' => 'Book submenu 2'),
                           'book3.php' => array('text' => 'Book submenu 3')
                       )
                   ),

    'identityDesign.php' => array(
        'text'    => 'Identity Design',
        'submenu' => array('identityDesign1.php' =>  array('text' => 'Identity design submenu 1'),
                           'identityDesign2.php' =>  array('text' => 'Identity design submenu 2')
                       )
                   ),

    'logos.php' =>  array(
        'text'    => 'Logos'),

    'packaging.php' =>  array(
        'text'    => 'Packaging',
        'submenu' => array('packaging1.php' =>  array('text' => 'Packaging submenu 1'),
                           'packaging2.php' …
broj1 356 Humble servant Featured Poster

Seems like $row['teacher_id'] and $row['comment'] haven't got a value. Insert the following after the line 19:

if(!isset($row['teacher_id']) or empty($row['teacher_id']) or !isset($row['comment']) or empty($row['comment'])) {
    die('<pre>' . print_r($row, 1) . '</pre>');
}

and post the output.

(the code above will check if any of the suspicious values do not exist and will display the array with values of $row variable at that time in preformated html).

broj1 356 Humble servant Featured Poster

You are welcome. If this ends this discussion please mark it as solved.

broj1 356 Humble servant Featured Poster

It works here. It is probably the css statement for font color which should be color and not font-color (which is an old html equivalent).

$l_menu .= '<li><a style="color:#eb0089" href="#nogo">'. $text . ' </a></li>';
broj1 356 Humble servant Featured Poster

This is how I would do it:

Each page can be identified by its script name so you do not need a name for it, just put a scriptname into variable first (this is not necessary for the menu pages):

$script_name = end(explode('/',$_SERVER["SCRIPT_NAME"]));

Then include the menus. The menus have using an associative array that holds scriptnames and texts that should be displayed. This improves scalability, since you just change the arrays. See the code below and se more info in comments.

Top menu:

<?php

// array of pages for the top menu
$top_menu_items = array(

    'index.php' => 'Home',
    'about.php' => 'About',
    'news.php' => 'News',
    'contact.php' => 'Contact',
);

// start the html string for menu
$t_menu = ' <ul id="list-nav">';

// add all the ittems from the $top_menu_items array
foreach($top_menu_items as $url => $text) {

    if($script_name == $url) {

        // if the item in the array is the current page, highlight it
        $t_menu .= '<li><a style="font-weight:bold" href="#nogo">'. $text . '</a></li>';

    } else {

        // else display it as usual link
        $t_menu .= '<li><a href="' . $url . '">' . $text . '</a></li>';
    }
}

$t_menu .= '</ul>';

echo $t_menu;
?>

Left menu (very similar):

<?php

// array of pages for the left menu
$left_menu_items = array(

    'book.php' => 'Book Design',
    'identityDesign.php' => 'Identity Design',
    'logos.php' => 'Logos',
    'packaging.php' => 'Packaging',
    'index.php' => 'Selected Projects',
);

// start the html string for menu
$l_menu = ' <ul>';

// add all the ittems from the $top_menu_items array
foreach($left_menu_items as …
broj1 356 Humble servant Featured Poster

I am just guessing while waiting for your reply :-)

I think that included menu scripts should not have constant definitions at all since they are not needed. Each page that links point to should have a variable $this_page set to its page name on the beginning of the script (before including menus) e.g.:

$this_page='BookDesign';

Then you include the menus and use the variable in the switch:

switch ($this_page) {
case 'BookDesign':
    $menuitem1 = '<a style="font-color:#eb0089" href="#nogo">Book Design</a>';
    break;
case 'IdentityDesign':
    $menuitem2 = '<a style="font-color:#eb0089" href="#nogo">Identity Design</a>';
    break;
...

PHP will not complain since the variable can have any value at any time (unlike constant).

broj1 356 Humble servant Featured Poster

I do not exacly understand what you want to achieve. Can you describe please.

broj1 356 Humble servant Featured Poster

Also you probably meant:

define('THIS_PAGE', $pagename);

since $pagename probably comes from user's choice. I think using constans here is not appropriate since you are actualy testing for a value of a variable.

broj1 356 Humble servant Featured Poster

Define is used for defining constants and constans once defined can not be changed (by another define). You can always test if the constant has already been defined:

if(!defined('THIS_PAGE')) {define('THIS_PAGE', 'pagename')}
broj1 356 Humble servant Featured Poster

It is OK. And typos happen all the time :-).

If the problem is solved please mark the thread as solved. Happy coding.

broj1 356 Humble servant Featured Poster

Yes there are errors:

  1. remove all ... from the code. They are there for your code to insert if needed.
  2. On line 25 the $ is missing (my typo)
  3. On line 26 the $ is missing (my typo)
  4. On line 44 the $ is missing (my typo)

Sory for the typos. Here is the correct code (I hope):

<?php
//$qg=$_GET["q"];
$name="Ramana Sethi";
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("testdb", $con);
$sql="SELECT * FROM peoplegrid WHERE Employee ='$name'"; //'".$q."'";
$result = mysql_query($sql);
//provided by Daniweb.Bojoe Recko
$rows_array = array();
// index for row numbers
$row_no = 0;
// firs store all data in a multidimensional array
while($row = mysql_fetch_array($result))
{
    $rows_array[$row_no] =$row;
    $row_no++;
}

// display the table rows
foreach(rows_array as $row) {
    echo "<tr>";
    echo "<td>" . $row['Firstname'] . "</td>";
    echo "<td>" . $row['Function'] . "</td>";
    echo "<td>" . $row['City'] . "</td>";
    echo "<td>" . $row['Rank'] . "</td>";
    echo "</tr>";
}

echo "</table>";
// address the cell (Rank in row 4 if exist)
$myRank = $rows_array[3]['Rank'];
echo $myRank;
mysql_close($con);
?> 
broj1 356 Humble servant Featured Poster

You can store the rows in question in an array (could impact performance if the fieldset is large).

$rows_array = array();
// index for row numbers
$row_no = 0;

// firs store all data in a multidimensional array
while($row = mysql_fetch_array($result))
{
    $rows_array[row_no] =$row;
    row_no++;
}

...

// display the table rows
foreach(rows_array as $row) {

    echo "<tr>";
    echo "<td>" . $row['Firstname'] . "</td>";
    echo "<td>" . $row['Function'] . "</td>";
    echo "<td>" . $row['City'] . "</td>";
    echo "<td>" . $row['Rank'] . "</td>";
    ...
    echo "</tr>";
}

...

// address the cell (Rank in row 4)

$myRank = rows_array[3]['Rank'];

But as I said it would be preferrable if you had another column for row numbers in your database table which would be the primary key and would help you updating particular fields. That field would replace the $row_no variable.

Just a note: spreadsheet table and database table are not exactly the same though the concept is similar.

broj1 356 Humble servant Featured Poster

More user friendly solution would be to offer movie IDs in a drop down list (html select element). In that case user can not select an invalid ID and they also do not have to remember all IDs (you can display movie names in the select element). Of course if there are too many IDs (say hundreds) this option would not be appropriate.

broj1 356 Humble servant Featured Poster

To access fields of a row use associative index that mysql_fetch_array function returns:

echo $row['Firstname']." - ".$row['Rank'];

To address particular rows (using SELECT, UPDATE or DELETE queries) you have to use WHERE condition(s) that return just one row. In your case it would be a good thing to have another unique field for each row (e.g. id) which would be also a primary key. It enables you to address particular row and also improves performance.

broj1 356 Humble servant Featured Poster

Have you tried to count the actual records that the query returns as I suggested in my next post? Or have you tried to test the query in phpmyadmin?

broj1 356 Humble servant Featured Poster

Or put a counter within a while loop and see how many rows you get (you might use PDO's number of rows function):

public function headLoad()
{

    // debug ceounter
    $i = 0;

    $cxn = $this->connection()->prepare("SELECT scriptCode FROM head_scrips WHERE active = '0'");
    $cxn->execute();
    $cxn->setFetchMode(PDO::FETCH_ASSOC);
    print "<script>";
    while($row = $cxn->fetch())
    {
        print $row['scriptCode'];

        // increase the counter
        $i++;
    }
    print "</script>";

    // print the counter
    echo "Number of rows: $i";
}
broj1 356 Humble servant Featured Poster

Just a dumb question: if you want to get active scripts why is the condition WHERE active = '0'? Shouldn't it be WHERE active != '0'?

broj1 356 Humble servant Featured Poster

From the error message one could conclude that the query returns 0 rows and therefore 1st row (index 0) can not be accessed. Please test the query with the actual parameters by inserting this code right after line 14:

die("SELECT `logs_id` FROM `school_logs` WHERE `school_user` = '$school_user' AND `school_id` = '$school_id'");

Copy the output into phpmyadmin or mysql client and see if the query returns any rows. Maybe the WHERE condition returns no rows.

broj1 356 Humble servant Featured Poster

Sory for jumping in, I just have too much time right now :-). You can not use a function within double quoted string (you can use variables though). Do a concatenation:

$sql = "INSERT INTO `db` (profile image) VALUES " . mysql_real_escape_string($grav_url) . " WHERE id='{$_SESSION['sessid']}'";

This should work provided that the {$_SESSION['sessid']} exists and has expected vaslue.

broj1 356 Humble servant Featured Poster

You are welcome. If you have no more questions regarding this problem, please mark the thread as solved, otherwise we are welcome to leave it open and ask at your own pace. Happy coding.

broj1 356 Humble servant Featured Poster

OK so you want to drag the rows of displayed html table. This is a Javascript job. Have you checked the link pritaeas sent in above post? I think this is the answer for you (have a look at the code in the browser - you will find the css and javascript you need).

confstu commented: thanks once again, i will see pritaeas link and try it +0
broj1 356 Humble servant Featured Poster

I use PEAR now and then. Mostly I use MDB2 package for abstraction of access to a database which I thimk is a pretty good collection of code and (hopefully) enable you to switch to another supported database without much changes to your code. Another package I use is Pager which is excellent for pagging database results. Periodically there might be some issues with packages not following tightly the changes in PHP.

broj1 356 Humble servant Featured Poster

mysql_fetch_array returns a row of the table in a form of an array. You actually are processing row by row already in the code:

while($row = mysql_fetch_array($result))

Within the above while loop you can do anything with the row or the fields of the row.

Can you please explain more in detail what you want to achieve (I hope I did not missunderstand your question).

broj1 356 Humble servant Featured Poster

Just my guess since I am not using Ubuntu but Fedora. I think scripts and web pages should be in a directory that is defined in a webserver configuration (in Fedora and some other distros the config file is /etc/httpd/conf/httpd.conf and the web pages are in /var/www/html). The directories and files should be owned by either a webserver user (apache in Fedora) or just the normal user that created them. The directories on my webserver have permissions rwxr-xr-x and the files are rw-r--r-- and everything works OK. So check your Apache config file and the permissions.

broj1 356 Humble servant Featured Poster

In the php file first check whether the form was submitted:

<?php
// assumming you use method=post
if(isset($_POST['submit'])) {

    // do the insert

    // display thankyou message

    // end the script
    die();
}

// if the form was not submitted, display it
// ...
?>

<form action="#" method="post">
...
broj1 356 Humble servant Featured Poster

Many developers (including myself) use Eclipse (http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliossr2). Maybe a bit complicted to install and configure but powerful. Quite many also use Netbeans (http://netbeans.org/). I use it now and then at home and find it very good also.

Many text editors also provide syntax checking like Notepad++, KWrite, gedit (both Linux) etc. All the software I mentioned is free.

LastMitch commented: Thanks for the link & suggestion! +2
broj1 356 Humble servant Featured Poster

The following is my suggestion (maybe not perfect but works):

// first check if the form was submitted
if(isset($_POST['submit'])) {

    // initialize the array that will hold potential error messages
    $errors = array();

    // initialize variables (for filling-in fields in case of errors)
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];

    // if the form was submitted do the validation, assign variables and prepare
    // potential error messages

    // Filter Email
    // you can also use the function from the saadi06 post above
    if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {

        $errors[] = 'E-mail is not valid';
    }

    // Filter name
    if(!filter_var($name, FILTER_DEFAULT)) {

        $errors[] = 'Name is not valid';
    }

    // Filter Phone (I doubt this is an appropriate filter for phone numbers)
    // you better make up a function for checking phone numbers in your country
    if(!filter_var($phone, FILTER_DEFAULT)) {

        $errors[] = 'Phone is not valid';
    }

    // comment text 
    $comment = $_POST['comment'];

    // if there were no errors (the errors array is empty) send the mail,
    // display the successful message and stop the script
    if(empty($errors)) {

        $from = 'From: Form Submission';
        $to = 'email@gmail/yahoo/etc.com';
        $subject = 'Form Has Been Submitted - FRONT PAGE';
        $body = " Form is Submitted by $name\n E-Mail: $email\n Phone: $phone\n Comments:\n $comment";

        // mail($to, $subject, $body, $from);

        die('<p>Message Sent Successfully!</p>');
    }
}

// start the form, method is post, action is # (same page)
echo '<form method="post" action="#">';

// add the input element for name
echo 'Name: <input type="text" name="name" value="' . $name . '" /><br …
broj1 356 Humble servant Featured Poster

And be aware of the difference between || and or (and also && and and ) since they are essentially the same but do get evaluated in different order. See also the following thread: http://www.daniweb.com/web-development/php/threads/424547/-vs-and#post1814451

broj1 356 Humble servant Featured Poster

No problem, my friend. And please do not call me a guru since I am far far from that :-). You will soon get practice too.

If you find the answers helpful you can always vote (up arrow on the right side). If you think the post is really bad you can also downvote it (down arrow on the right side).

If this wrapps up this topic you can mark is as solved. If another problems arise just start a new topic.

broj1 356 Humble servant Featured Poster

This is the principle:

for($row=1;$row<=20; $row++){
    echo "<tr>\n";
    for($col=1;$col<=20; $col++) {
        $x=rand($min,$max);
        $random_array[$row][$col] = $x;

        if($x % 2 == 0) {

            $char = '*';
        } else {

            $char = '%';
        }

        echo"<td>$char</td>\n";
        // add value to the $temp_array
        $temp_array[] = $x;
    }
    echo "</tr>";
}
broj1 356 Humble servant Featured Poster

how do I make every even/odd number have for example: all evens are blue... and odds are red?

Do you mean every even/odd number or even/odd row in a table?

In both cases you use css style and apply it to table cells or rows. Here is the example for even/odd numbers:

// define the css styles
$style_even = {color: blue;};
$style_odd = {color: red;};

for($row=1;$row<=20; $row++){

    echo "<tr>\n";

    for($col=1;$col<=20; $col++) {

        $x=rand($min,$max);
        $random_array[$row][$col] = $x;

        // define style depending on whether the number is even or odd
        if($x % 2 == 0) {

            $style = $style_even;

        } else {

            $style = $style_odd;
        }

        // add style to the cell
        echo "<td style='$style'>$x</td>\n";

        // add value to the $temp_array
        $temp_array[] = $x;
    }

    echo "</tr>";
}
broj1 356 Humble servant Featured Poster

I'll be as good as you in maybe about a 2-3 years!

I'm not such an expert, it is just a practice and experience. If you do programming on regular basis you will get that in less than one year :-)

But I came up with a question, is there other ways in sorting a loop or maybe a better way and a way I shouldn't do it?

When it comes to sorting, there are basically two approaches:

  1. Save the data you want to sort in an array (like I did above) and sort the array with one of many array sort functions. There are plenty functions to use that sort by keys, do natural sort, case insensitive sort, multidimensional sort, reverse sort etc. See http://php.net/manual/en/array.sorting.php

  2. If you draw your data from a database then you can sort in your query using ORDER BY statement such as $query = "SELECT name, joindate FROM members ORDER BY name".

broj1 356 Humble servant Featured Poster

The following code should roughly do it:

// add the first div
echo '<div id="shelf" class="Magenta_div">';

// initialize the counter for the current table row
$current_row = 1;

while($row = mysqli_fetch_row($res)) {

    // echo the image data from  the db table row
    echo "...";

    // check if the current row count is divisible by 4
    // if yes end the div and add another div
    if($current_row % 4 == 0) {

        echo '</div>';
        echo '<div id="shelf" class="Magenta_div">';
    }

    // increase the current row
    $current_row++;
}

// add the last div
echo '</div>';

The only thing is that in the last div you can have 0 images but you can check the number of rows returned and if it is divisible by 4 do not echo the last <div> </div> pair of tags.

broj1 356 Humble servant Featured Poster

OK, I've done a bit of juggling and came up with the code below. Please note since you create a two-dimensional array you have to copy it to a one-dimensional temporary array so you can use the sort php function which works on one-dimensional arrays. See the comments in the code. I have renamed the variables you used but you can change them. Hope this is what you intended to get help with. If not then give more explanation.

<?php

$x=0;
$min=900;
$max=2000;

// initialize array of random values
$random_array = array();

// initialize temporary array for sorting
$temp_array = array();

// start html table for random values
echo "<table border=\"1\">";

// create $random_array with random numbers, display html table rows and
// store each value in onedimensional $temp_array for sorting
for($row=1;$row<=20; $row++){

    echo "<tr>\n";

    for($col=1;$col<=20; $col++) {

        $x=rand($min,$max);
        $random_array[$row][$col] = $x;

        echo"<td>$x</td>\n"; 

        // add value to the $temp_array
        $temp_array[] = $x;
    }

    echo "</tr>";
}

// end the html table
echo "</table>";

// sort the $temp_array (sort works on onedimensional arrays)
sort($temp_array);

// start a table for sorted values
echo "<table border=\"1\">";

// initialize counter that will be the $temp_array's key
$key = 0;

// display html table rows of sorted values
for($row=1;$row<=20; $row++){

    echo "<tr>\n";

    for($col=1;$col<=20; $col++) {

        echo"<td>{$temp_array[$key]}</td>\n";

        // increase the key
        $key++; 
    }

    echo "</tr>";

}

// end the html table of sorted values
echo "</table>";

?>
broj1 356 Humble servant Featured Poster

In the above code the variables $table and $y are undefined. What is the purpose of those?

Also you should not put the </table> tag within the foreach loop (see line 23). I am still looking at your code so more follows.

broj1 356 Humble servant Featured Poster

You are welcome and come back if you need more help. If you decide it is OK mark the thread as solved.

broj1 356 Humble servant Featured Poster

Give your select element a name that is an array (like bookshelf[]). Upon submision your post array will contain an array with selected values.

<form action='library.php' method='post'>
<select name='bookshelf[]' multiple='true'>
<option value="alice_s_wonderland">Alice's wonderland</option>
<option value="secret_seven">Secret Seven</option>
<option value="jonathan_livingston_sagull">Jonathan Livingston Seagull</option>
</select>
<input type="submit" name="submit" value="Submit books" />
</form>

And the library.php

<?php
// check if the form is submitted, the bookself array exists and is not empty
if(isset($_POST['submit']) && isset($_POST['bookshelf']) && !empty($_POST['bookshelf'])) {

    // $_POST['bookshelf'] is an array of selected options, process it the way you like
    // i.e. you can loop through it with foreach
    // I will implode it into a comma separated string and display it
    echo implode(', ', $_POST['bookshelf']);

} else {

    echo 'No titles were selected. Go back and select at least one title.';
}
?>
broj1 356 Humble servant Featured Poster

One quick solution would be to produce csv file using fputcsv() function (see http://php.net/manual/en/function.fputcsv.php).

Another option is to read the data from the db table, create a html table and send appropriate headers to the browser that sees the table as an excel file:

<?php

    // connect to the db and query the data from the table usual way
    // ...

    // begin the html table
    $labels = '<table>';

    // loop through the db result and add rows
    while($row = mysqli_fetch_assoc($result)) {

        $labels .= "<tr><td>{{$row['field1']}</td>";
        $labels .= "<td>{{$row['field2']}</td>";
        $labels .= "<td>{{$row['field3']}</td>"</tr>;
    }

    // end the html table
    $labels .= '</table>';

    // send the headers (make sure no content has been sent before)
    // I found those on the web and must confess that haven't studied each one of
    // them but they work fine for me
    header("Pragma: no-cache");
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-type: application/x-msdownload");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Disposition: attachment;filename=bia_values_1_8.xls ");
    header("Content-Transfer-Encoding: binary ");

    // echo the table with label data
    // the browser should open/download it as an excel file
    echo $labels;
?>
broj1 356 Humble servant Featured Poster

I use TCPDF for stufflike this. The following is adaption of example from tcpdf.org. Download the library, link to it and check it out. It is not perfect, you can fine tune it.

<?php

// some test data; you will read it from the database
$TEST_LABEL_DATA = array(

    array(
        'title' => 'Mr',
        'fullName' => 'Bean',
        'address' => '10 Bean st.',
        'zipCode' => '10000',
        'city' => 'London'),

    array(
        'title' => 'Ms',
        'fullName' => 'Piggy',
        'address' => '20 Muppet st.',
        'zipCode' => '10001',
        'city' => 'New York'),

    array(
        'title' => 'Herr',
        'fullName' => 'Vladimir Putin',
        'address' => '1 Weapon st.',
        'zipCode' => '1000',
        'city' => 'Moscow'),

    array(
        'title' => 'Mr',
        'fullName' => 'Bean',
        'address' => '10 Bean st.',
        'zipCode' => '10000',
        'city' => 'London'),

    array(
        'title' => 'Ms',
        'fullName' => 'Piggy',
        'address' => '20 Muppet st.',
        'zipCode' => '10001',
        'city' => 'New York'),

    array(
        'title' => 'Herr',
        'fullName' => 'Vladimir Putin',
        'address' => '1 Weapon st.',
        'zipCode' => '1000',
        'city' => 'Moscow'),
);

// make sure the path is correct
require_once('tcpdf.php');

// set page
$page_orientation = 'P';
$page_units = 'mm';
$page_format = 'A4';

// set top and left margin
$top_margin = 8;
$left_margin = 0;

// initialize object
$pdf = new TCPDF($page_orientation, $page_units, $page_format, true, 'UTF-8');

// set margins
$pdf->SetMargins(0, 0, -1, true);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set font
$pdf->SetFont('times', '', 10);

// add a page
$pdf->AddPage();

// set cell padding
$pdf->setCellPadding(1);

// set cell margins
$pdf->setCellMargins(0, 0, 0, 0);

// set label dimensions (see the Avery label specification) …
broj1 356 Humble servant Featured Poster

Ocnsider that the user types in a URL abc.php or send it by email to someone else. I these cases $_POST would not contain any values and the script would display an error message. That is why you check with isset() and handle error yourself. The more complete code would be:

if(isset($_POST['agree'])) {

    if($_POST['agree'] == 'yes') {

        // code for YES here

    } elseif($_POST['agree'] == 'no') {

    // code for NO here

    } else

    // $_POST is set but does not contain value Yer or No
    // error message "Please select Yes or No"
    // (or redirect back to the form)

} else {

    // $_POST is not set
    // error message "Please select Yes or No"
    // (or redirect back to the form)
}
broj1 356 Humble servant Featured Poster

You are missing value attributes for each radio button. The chosen value (only one) will get carried over to the abc.php page through $_POST global array. Note that you are also missing a submit button to submit the form. On abc.php start with checking if $_POST['agree'] is set which means the form has been submitted, and then process it.

<form action='abc.php' method='post'>
<label>YES</label>
<input type='radio' name='agree' value='yes' />
<label>NO</label>
<input type='radio' name='agree' value='no' />
<input type='submit' name='submit' value='Submit' />    
</form>

Then on abc.php

if(isset($_POST['agree'])) {

    if($_POST['agree'] == 'yes') {

        // code for YES here


    } elseif($_POST['agree'] == 'no') {

        // code for NO here

    }
}
broj1 356 Humble servant Featured Poster

No problem, you owe me nothing :-). I have helped for shear pleasure and I always learn something from that, too.

Just a hint: to remember selections store selected calendars in the $_SESSION array. Seehttp://www.w3schools.com/php/php_sessions.asp. If you have troubles, come back.