broj1 356 Humble servant Featured Poster

The problem is in lines 7 and 8 of the html file. You are missing '=' sign when assigning name attributes to input elements. This is the correct code:

value one: <input type="text" name="val1" size=10 /><br />
value two: <input type="text" name="val2" size=10 /><br />
broj1 356 Humble servant Featured Poster

I do not know whether this is the cause for your trouble but there are two issues:
1. you start a table row within a list item (<li>) and end it outside the list item; html tags should be nested appropriately
2. putting a table (even if properly nested) within a list item might be valid but a bad idea (unless this is really really what you intended); things might get complicated to maintain so you have to have a good reason to do it

broj1 356 Humble servant Featured Poster

I use PEAR Pager class:

http://pear.php.net/package/Pager/

with help of the Pager_Wrapper class for paginating data read from a database:

http://www.alberton.info/pear_pager_tutorial_database_results.html

Maybe a bit old stuff but it works great. At least you can have look at the code.

broj1 356 Humble servant Featured Poster

Sorry to come back so late I am pretty busy finishing up a project at work. At the moment I can hardly take time to chat on skype on this subject or to spend too much time (i.e. to set up a database and prepare a code for you). Will try to help with bits and pieces as much as possible.

broj1 356 Humble servant Featured Poster

First, you have to give name to the select element on line 210 (i.e. cities).

Pokazi statistiku za <select name="cities">

Where do you want to display the statistics? Is it on the same page? If yes then you have to save all the values that user has already filled in, otherwise they can get very anoyed seeing the empty form (the form will empty on submission).

Basicaly the principle is that when you check for form submission with f($_POST['doSubmit'] == 'Submit') you can check whether $_POST exists (userhas selected a city). If it exists you can fire the query and store the result in a string which will be displayed somewhere on the page. Add the following code to your if block on line 6:

foreach($_POST as $key => $value) {
    $data[$key] = filter($value);
}

// check if any value was posted for cities
if(isset($data['cities'])) {

    // query for getting statistics from anketa table
    $query_c = "SELECT * FROM anketa WHERE location='" . $data['cities'];

    // execute the query
    $res = mysql_query($query_c,$link) or die("Error:" . mysql_error());

    // store the result of your query in the $row array
    $stat = mysql_fetch_assoc($res);

    // string for displaying statitics
    $stat_string = '<ul>';

    // $stat array now contains all the fields from anketa table (whatever they are)
    // you can now loop through them using foreach and store them in a string
    foreach($stat as $field => $data) {

        $stat_string .= "<li>$field: $data</li>";
    }

    $stat_string .= "</ul>";
}

Now you can display the string somewhere on …

broj1 356 Humble servant Featured Poster

So you want to select a city at the end of the form and see the statistics for that city (please note: on english version the select element for cities at the end is missing)? Do you want to see results on the same page or on different page (your action attribute of the form is currently set to the index.php)? It would be easier if you post some PHP code here.

broj1 356 Humble servant Featured Poster

I have prepared a modified code based on the link sent by pritaeas. Note I used a test array since I did not bother to set up a database.

<?php

    // test array
    $test_array = array();
    for($j = 1; $j <= 103; $j++) {
    
        $test_array[$j]["code"] = "CODE-$j";
        $test_array[$j]["name"] = "NAME-$j";
    }

    // counter for cells
    $i = 1;

    // begin a table
    echo '<table border="1">' . "\n";

    foreach($test_array as $row)
    // while($row = mysql_fetch_array($retd)) 
    { 
        $code = $row["code"];
        $name = $row["name"];

        // for 1st, 6th, 11th etc record insert a tag for a new row
        if (($i == 1) or (($i - 1) % 5) == 0) {
        
            echo '<tr>' . "\n";
        }

        // insert a cell
        echo("<td width=150 align=center>");
        echo ("<a href=../item?scode=$code><img src=pictures/$code.gif border=0 alt=Item $name</a>");
        echo ("<br><a href=../item?scode=$code><span class=fs13>$name</span></a>");
        echo("</td>");

        // for 5th, 10th, 15th etc record insert a tag for end of the row
        if ((($i) % 5) == 0) {
        
            echo '</tr>';
        }
        
        // increment $i
        $i++;
    }

    // if there are no records left and the row has not yet been filled, fill it
    // with empty cells
    while(($i - 1) % 5 != 0) {
    
        // insert a blank cell
        echo '<td>&nbsp;</td>';
        
        // increment $i
        $i++;
        
        // for 5th, 10th, 15th etc record insert a tag for end of the row
        if (($i - 1) % 5 == 0) {
        
            echo '</tr>';
        }
    }

    // end the table
    echo '</table>';
?>
broj1 356 Humble servant Featured Poster

The closing curly bracket } on line 28 should actually be just after line 24 (at the end of the function dbQuery). These things are quite easy to spot if you use indentation and editor with syntax highlighting.

<?php
session_start();

function __autoload($name) {
    require $name . '.php';
}
function dbInit(){
    if(isset($GLOBALS['db']))return $GLOBALS['db'];
        global $DBVARS;
    $db=new PDO('mysql:host='.$DBVARS['hostname']
            .';dbname='.$DBVARS['db_name'],
        $DBVARS['username'],
        $DBVARS['password']
    );
    $db->query('SET NAMES utf8');
    $db->num_queries=0;
    $GLOBALS['db']=$db;
    return $db;
}
function dbQuery($query){
    $db=dbInit();
    $q=$db->query($query);
    $db->num_queries++;
    return $q;
}
function dbRow($query) {
    $q = dbQuery($query);
    return $q->fetch (PDO::FETCH_ASSOC);
}

define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/');
require SCRIPTBASE . '.private/config.php';
if(!defined('CONFIG_FILE'))
    define('CONFIG_FILE',SCRIPTBASE.'.private/config.php');
set_include_path(SCRIPTBASE.'ww.php_classes'
    .PATH_SEPARATOR.get_include_path());  
?>
broj1 356 Humble servant Featured Poster

This is how I would do it.

<html>
<head></head>
<body>

<?php

// initialize value for the position
$pos = '';

// initialize string for content
$content = '';

// check if there is a value for position select in the $_GET
// and position is integer and within expected range (a bit of security)
// (this means that the form was submited by onchange event)
if(isset($_GET['position']) and is_numeric($_GET['position']) and 
         $_GET['position'] > 0 and $_GET['position'] <= 4) {

    // store position in a variable
    $pos = $_GET['position'];

    // a query to change the database (whatever it is)
    $qry = "UPDATE positions SET position=$pos WHERE ...";
    
    // execute the query
    // ...
    
    // DEBUG:
    // display the query to see whether it is OK
    echo "<p><pre>$qry</pre></p>";
}

// array holding the option values and texts
$option_arr = array('1' => 'First',
                    '2' => 'Second',
                    '3' => 'Third',
                    '4' => 'No Display...');

// start a string holding the form
// set action to itself
$form = '<form method="GET" action="#">';

// add select element
$form .= '<select name="position" onchange="this.form.submit();">';

// add options
foreach($option_arr as $value => $text) {

    // start the option tag
    $form .= '<option value="' . $value . '"';

    // if a submited value equals $value then add seleted attribute to the option
    if($value == $pos) {
    
        $form .= ' selected="selected"';
    }
    
    // add the text and end the option tag 
    $form .= ">$text</option>";
}

// end the select tag and the form tag
$form .= '</select></form>';

// display the form
echo $form; …
Martin C++ commented: Good post, cleared some things out +2
broj1 356 Humble servant Featured Poster

Following code works for me. I simulated reading from a database with an array and foreach loop, so replace that with a while loop iterating through a real recordset.

<html>
<head>
<style type="text/css">
    .left-box {float: left; width: 200px;height: 200px; border: 1px solid blue;background-color: green; padding:2px;}
    .right-box {margin-left:210px; margin-bottom:2px; width: 200px; height: 200px; border:1px solid blue; background-color: yellow; padding:2px;}
    .data {margin: 2px; border:1px solid green; background-color: grey;}
</style>
</head>
<body>
<?php

    // data that simulates data read from database
    $recordset = array(
    
        array(
            'image' => 'Image 1',
            'data1' => 'Data 1-1',
            'data2' => 'Data 1-2',
            'data3' => 'Data 1-3'),

        array(
            'image' => 'Image 2',
            'data1' => 'Data 2-1',
            'data2' => 'Data 2-2',
            'data3' => 'Data 2-3'),

        array(
            'image' => 'Image 3',
            'data1' => 'Data 3-1',
            'data2' => 'Data 3-2',
            'data3' => 'Data 3-3')
    );

    $tbl  = '';

    // here you would loop throu your recordset
    foreach($recordset as $row) {
    
        // left box - the image
        $tbl .= '<div class="left-box">' . $row['image'] . '</div>';
        
        // right box
        $tbl .= '<div class="right-box">';
        
        // the data in three separate divs
        $tbl .= '<div class="data">' . $row['data1'] . '</div>';
        $tbl .= '<div class="data">' . $row['data2'] . '</div>';
        $tbl .= '<div class="data">' . $row['data3'] . '</div>';
        
        $tbl .= '</div>'; // end of right box   
    }

    echo $tbl;

?>
</body>
</html>

Please note that although this works (firefox on Fedora) the css code can be improved and made suitable for all browsers. A job for css gurus.

broj1 356 Humble servant Featured Poster

Well, you can do it in two ways. The old fashioned way is using a table to position pictures and data. Say you have two columns and each cell in column 1 has rowspan attribute set to 3 (or whatever the number of data cells is).

$tbl  = '<table border="1"><tr>';

while(rows_exist_in_result_set) {

    $tbl .= '<tr><td rowspan="3">PICTURE HERE</td><td>DATA</td></tr>';
    $tbl .= '<tr><td>DATA</td></tr><tr><td>DATA</td></tr>';
}

$tbl .= '</table>';

Modern way is using divs and css positioning. I am not that good at that but I will give it a try. Someone might give you better css code. First the PHP code (or HTML):

while(rows_exist_in_result_set) {

    $tbl  = '<div class="left-box">PICTURE HERE</div>';
    $tbl .= '<div class="right-box">';
    $tbl .= '<div class="data">DATA</div>';
    $tbl .= '<div class="data">DATA</div>';
    $tbl .= '<div class="data">DATA</div>';
    $tbl .= '</div>'; // end of right-box div
}

echo $tbl;

and then the css code that will position these divs correctly. Colors and borders are here to help you visually. This is just a conceptual example, the CSS code could be written better. Ask also on the HTML and CSS forum about good examples of positioning.

/* CSS code */
.left-box {float: left; width: 200px;height: 200px; border: 1px solid blue;background-color: green; padding:2px;}
.right-box {margin-left:210px; margin-bottom:2px; width: 200px; height: 200px; border:1px solid blue; background-color: yellow; padding:2px;}
.data {margin: 2px; border:1px solid green; background-color: grey;}

If you do it with tables it is simpler but people might say that tables are only meant to represent tabular data (but you can always claim that the stuff you are displaying is …

evilguyme commented: i love you!! thanks!! +3
broj1 356 Humble servant Featured Poster

I have been using OOP approach with PHP fo a couple of years now developing an app that runs mainly on intranet and occasionaly on internet. My opininon is that OOP approach makes code much more maintainable and reusable (extendable). However you need some practice to be able to design your class hierarchy in a way that these claims hold true. My classes in the beginning were not easy to change without breaking the app. But from my own errors I slowly learnt how to do it (and am still learning :-). There are downsides with OOP such as (apparently) more work for a server to interpret the scripts but it never had noticeable impact on my app (using decent server). As pritaeas said frameworks heavily use OOP approach, I guess due to easier maintainability and reusability of the code.

broj1 356 Humble servant Featured Poster

Recursion seems to be the best choice.

function getTotal($val) {

    if($val == 1) {
        
        return 1;
        
    } else {
    
        return $val * getTotal($val - 1);
    }
}

echo 'TOTAL: ' . getTotal(9);

Works for values 1 and higher. Credits to http://www.codewalkers.com/c/a/Miscellaneous/Recursion-in-PHP/1/

broj1 356 Humble servant Featured Poster

Dear wenothat,

I would be happy to help you but I think your problem is very complex. I do not have enough time to load an application form the above link (72 scripts) and try to find where you adapted it and what went wrong within this process. If you ask me, it is not a good idea at all to use the such complex code which you do not understand since you can create a lot of risky situations for yourself, your customer, your employer or your provider. My advice is: learn PHP to a level that you understand the working of the application you want to develop/customize and when you have concrete problems ask people on forum (this or others) to help. This is also what the rules of this forum (and most others) say.

This advice is not because I do not want to help but because it is better for you.

broj1 356 Humble servant Featured Poster

It might be hard to mix PHP code with HTML with this style of programming. You will be more or less limited to generate all HTML code with PHP I guess. Is that what you really want? And what is the role of the line 3 above (initialization of StdClass)? Are the functions methods of the class?

broj1 356 Humble servant Featured Poster

Man, you must be in love with the if clause. It seems that you have one curly bracket missing at the end between lines 168 and 179. Your code is very complex and hard to follow but my IDE shows that what is marked as:

}//end foreach

is really end of if block starting on line 45. If I insert a curly bracket at the end, all the brackets are in pairs but I do not know whether the code is what you intended.

broj1 356 Humble servant Featured Poster

You need:
1. an editor that helps PHP development. PHP Eclipse (http://www.phpeclipse.com/g) and Netbeans (http://netbeans.org/) are probably most wide spread but for a beginner maybe a little overwhelming. Notepad++ (Windows) and Kwrite, gedit (Linux) are simpler and still powerfull ones.
2. a PHP and mysql enabled web server (can be on your machine or at your ISP). If on your machine try LAMP on Linux (see your distribusion package management) or XAMP (http://www.apachefriends.org/en/xampp.html) on Windows) that both contain Apache web server, Mysql database and PHP support.
3. good book to learn (I used PHP5 and MySQL Bible)
4. links: http://www.w3schools.com/php/, www.php.net, daniweb.com :-)

broj1 356 Humble servant Featured Poster

One way of doing it:

$brush_price = 5;
$counter = 10;

// row for quantities with heading in first cell
$qtyRow = '<tr><th>Quantity</th>';

// row for prices with heading in first cell
$priceRow = '<tr><th>Price</th>';

// add cells to each row
while ( $counter <= 100 ) {

    $qtyRow .= "<td>$counter</td>";

    $priceRow .= "<td>" . ($brush_price * $counter) . "</td>";

    $counter = $counter + 10;
}

// end of the rows
$qtyRow .= '</tr>';
$priceRow .= '</tr>';

// echo the table
echo "<table border=\"1\" align=\"center\">";
echo $qtyRow;
echo $priceRow;
echo "</table>";
broj1 356 Humble servant Featured Poster

Just to help you a little bit here is the code for easier debugging:

<?php
$query = "SELECT * FROM tbl_users WHERE ex_date between now() and adddate(now(), INTERVAL 7 DAY) ORDER BY user_id ASC";
$result = mysql_query($query);

$num = mysql_numrows($result);

/* DEBUG CODE*/
echo "<p>Number of rows: $num</p>";
/* END DEBUG CODE*/

$i = 0;

while ($i < $num)
{
    $id = mysql_result($result,$i,"user_id");
    $email = mysql_result($result,$i,"login_email");
    $loginname = mysql_result($result,$i,"loginname");
    $ex_date = mysql_result($result,$i,"ex_date");
    $ex_date = date("d-m-Y", strtotime($ex_date) );

    //send email

    $to = "$email";

    $subject = "Expriy Notice";

    $from = "Admin";

    $msg = "Hello $loginname,<BR><BR>";
    $msg .= "Your Account will expire in 7 days. Your Expiry Date is $ex_date<br /><br />";
    $msg .= "Regards: <br /><br />Admin";
    $msg .= "Admin";

    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
    $headers .= "From: Admin\r\nReply-To:sammy@gmail.com" . "\r\n";

    /* DEBUG CODE*/
    echo "<p>Variable i: $i<br />";
    echo "Email: $to<br />";
    echo "Subject: $subject<br />";
    echo "Message: $msg<br />";
    echo "Mail code: mail($to,$subject,$msg,$headers)</p>";
    /* END DEBUG CODE*/

    // Temporarily commented out
    // $mailsend = mail($to,$subject,$msg,$headers);

    // Temporarily commented out
    // echo $mailsend ? "Email was sent :-)." : " Email sending failed.";

    $i++;
}
?>

It might help if you post what gets displayed in your browser.

broj1 356 Humble servant Featured Poster

Apart from slight size increase you will get some redundancy since area code is stored in two fields (not a problem if area codes do not change, but you never know - from this perspective the tbl_id is better candidate for a foreign key) Your destination number could be without the area code, only the local phone number but I doubt you can change this now. You can add a foreign key with an UPDATE query so number of records should not be a problem if there arent too many area codes. You can prepare a php script to run the query.

broj1 356 Humble servant Featured Poster

If you add an area code as a foreign key to billing table then this query might help you:

SELECT `date`,`destination`,`callsec`,`tbl_cost`,`callsec`*`tbl_cost` AS price FROM `fees` RIGHT JOIN billing ON `tbl_code`=`tbl_code_fk`

Note that table names are omitted from the query for simplicity. Also a field name for date is maybe not a good idea since it is mysql function name and can cause errors.

broj1 356 Humble servant Featured Poster

I have prepared an example of login page which displays a form with inputs for username and password and compares submited values with records in database. If match is found the user is redirected to another page, if not error message is displayed. This example is heavy commented. Hope it helps people who need this kind of script.

Please suggest improvements.

broj1 356 Humble servant Featured Poster

I am not sure if I understood the question but if you do not want to get the green $clubName parsed and replaced with it's value either escape the $ like \$clubName or put the whole string in single quotes and xml attributes in double quotes like:

$new_xml = '<?xml version="1.0"?>-<params>-<param><key>$clubName</key><textValue>' .$club_name;
broj1 356 Humble servant Featured Poster

I am afraid you can't. CSV is as far as I know a text file and can not contain formatting. You should save your data in excel or ods or pdf (or similar) to use formatting.