-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
I wouldn't. There is no postcode.
-
Use a single query with JOINs, then you only need a single loop to process the results SELECT a.AreaName , r.responseDate , q.QuestionName , r.userResponse FROM Area a INNER JOIN Question q ON a.idArea = q.fkArea LEFT JOIN Responses r ON q.idQuestion = r.fkQuestion ORDER BY a.AreaName, r.reponseDate, q.QuestionName I used a LEFT JOIN on reponses in case there are questions with no responses.
-
... plus the precise error messages
-
Looks like you missed a comma before "true"
-
you could save a lot of coding by using arrays. This is just the traditional "scissors,paper,stone" version but you can extend the arrays to include your lizard and spock(???) <?php session_start(); if (!isset($_SESSION['results'])) { $_SESSION['results'] = array( 'Win' => 0, 'Draw' => 0, 'Lose' => 0 ); } $choices = array (1 => 'rock', 'paper', 'scissors'); $outcomes = array ( 'rock' => array ( 'rock' => array ('Draw', ''), 'paper' => array('Lose', 'covered by'), 'scissors' => array('Win', 'blunts') ), 'paper' => array ( 'rock' => array ('Win', 'covers'), 'paper' => array('Draw', ''), 'scissors' => array('Lose', 'cut by') ), 'scissors' => array ( 'rock' => array ('Lose', 'blunted by'), 'paper' => array('Win', 'cuts'), 'scissors' => array('Draw', '') ) ); if (isset($_GET['human'])) { $human = $choices[$_GET['human']]; $computer = $choices[rand(1,3)]; $outcome = $outcomes[$human][$computer]; $_SESSION['results'][$outcome[0]]++; } ?> <html> <head> <title>Scis-Pap-Brick</title> <style type='text/css'> table { /*border-collapse: collapse;*/ width: 400px } th { background-color: #369; color: white; } td { text-align: center; width: 33% } </style> </head> <body> <?php if (isset($_GET['human'])) { ?> <table border='0' cellspacing='1'> <tr> <th>You</th> <td> </td> <th>Computer</th> </tr> <tr> <td><?=$human?></td> <td><?=$outcome[1]?></td> <td><?=$computer?></td> </tr> <tr> <td colspan='3'> </td> </tr> <tr> <td colspan='3'><?="This time you {$outcome[0]}"?></td> </tr> <tr> <?php foreach($_SESSION['results'] as $c=>$r) echo "<th>$c</th>"; ?> </tr> <tr> <?php foreach($_SESSION['results'] as $r) echo "<td>$r</td>"; ?> </tr> </table> <?php } ?> <h3>Choose</h3> <form> <table border='0' cellspacing='1'> <tr> <?php foreach($choices as $k=>$c) echo "<th>$c</th>"; ?> </tr> <tr> <?php foreach($choices as $k=>$c) echo "<td><input type='radio' name='human' value='$k'></td>"; ?> </tr> <tr> <td colspan='3'><br><input type='submit' name='tbnSub' value='Play'></td> </tr> </table> </form> </body> </html>
-
LeJack, Will you please explain why I get the same results with these two sets of code if it can't be done $db = mysqli_connect(HOST,USERNAME,PASSWORD,DATABASE); $res = $db->query("SELECT COUNT(*) FROM votes"); list($count) = $res->fetch_row(); echo $count; // 182685 $db2 = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $res = mysqli_query($db2, "SELECT COUNT(*) FROM votes"); list($count) = mysqli_fetch_row($res); echo $count; // 182685
-
You can. function mysqli_query($conn, $sql) { return $conn->query($sql); }
-
If no room is specified, don't include a room condition in the WHERE clause
-
yes <html> <head> <title>Sample</title> <style type="text/css"> .highlight { color: #fff; background-color: #888; } </style> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".sel").change(function() { var curID = $(this).attr("id"); var chosen = $(this).val(); var curr = $(this).data('curr'); $(".sel").each(function(i,v) { if (v.id != curID) { $(v).children("option[value="+curr+"]").attr("disabled",false).removeClass("highlight"); $(v).children("option[value="+chosen+"]").attr("disabled",true).addClass("highlight"); } }) $(this).data('curr', chosen); }) $("#btnReset").click(function() { $("option").attr("disabled",false).removeClass("highlight"); this.form.reset(); }) }) </script> </head> <body> <form> <?php for ($i=0; $i<5; $i++) { echo "<select class='sel' id='sel$i' name='sel$i' data-curr='0'> <option value=''>---</option>"; for ($j=1; $j<=5; $j++) { echo "<option value='$j'>$j</option>"; } echo "</select> "; } ?> <input type='button' name='btnReset' id='btnReset' value='Reset'> </form> </body> </html>
-
not sure if you'll get it. But it is very difficult.
Barand replied to lecestan96's topic in PHP Coding Help
You don't really want to create that replace array manually every time <?php $str = isset($_GET['str']) ? $_GET['str'] : ''; $kw = isset($_GET['keyword']) ? $_GET['keyword'] : ''; $decode = isset($_GET['decode']) ? 1 : 0; $str2 = $str ? translate($str, $kw, $decode) : $str; function translate($str, $kw, $decode=0) { $str = strtoupper($str); $alpha = range('A','Z'); $karr = keyArray($kw, $alpha); $trans = $decode ? array_combine($karr, $alpha) : array_combine($alpha, $karr); return strtr($str,$trans); } function keyArray($keyword, &$alpha) { // create translation array from given keyword $kw = array_unique(str_split(strtoupper($keyword))); $diff = array_diff($alpha, $kw); return array_merge($kw, $diff); } ?> <html> <head> <title>Encoder</title> </head> <body> <form> Input text/Translation<br> <textarea name="str" rows="5" cols="50"><?=$str2?></textarea> <br> Keyword <input type="text" name="keyword" value="<?=$kw?>"> Decode <input type='checkbox' name='decode' value='1'> <br> <input type="submit" name="btnSub" value="Translate"> </form> </body> </html> -
Are you sure you posted the query that is giving that result? mysql> SELECT name -> , date_paid -> , expiry_date -> , DATEDIFF(expiry_date, date_paid) as diff -> FROM test_chidi; +------+------------+-------------+------+ | name | date_paid | expiry_date | diff | +------+------------+-------------+------+ | John | 2014-11-07 | 2014-12-01 | 24 | | Doe | 2014-11-07 | 2014-11-10 | 3 | +------+------------+-------------+------+ edit: where does next_due come from - you don't mention that in your data?
-
Then you need to put $title, $publishdate etc into form input fields, not just in table cells
- 1 reply
-
- 1
-
It still isn't right. Apparently you can still select a hidden option! Need to enable/disable them instead with .attr("disabled",false) .attr("disabled",true)
-
Do I take it that you have something like $_SESSION['Primary'] = array ( 'item1' => array ( 'color' => 'red', 'size' => 'large', 'price' => 25.00, 'qty' => 2 ), 'item2' => array ( 'color' => 'orange', 'size' => 'small', 'price' => 15.00, 'qty' => 1 ), 'item3' => array ( 'color' => 'blue', 'size' => 'medium', 'price' => 65.00, 'qty' => 1 ) ); If so then to loop through the attributes of "item2" it would be foreach ($_SESSION['Primary']['item2'] as $attr => $value) { echo "$attr : $value<br>"; } giving color : orange size : small price : 15 qty : 1
-
Thanks Psycho, I confess I haven't been using jquery for very long so I don't know if my fix is optimal, but it seems to work. I used a "data-curr" attribute to store the current value of the selects so I would know what value to put back. <?php include("db_inc.php"); // defines credentials $db = new mysqli(HOST,USERNAME,PASSWORD,'bogdaniel'); ?> <html> <head> <title>Sample</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".sel").change(function() { var curID = $(this).attr("id"); var chosen = $(this).val(); var curr = $(this).data('curr'); $(".sel").each(function(i,v) { if (v.id != curID) { $(v).children("option[value="+curr+"]").css("visibility","visible"); $(v).children("option[value="+chosen+"]").css("visibility","hidden"); } }) $(this).data('curr', chosen); }) $("#btnReset").click(function() { $("option").css("visibility","visible"); this.form.reset(); }) }) </script> </head> <body> <form> <?php for ($i=0; $i<5; $i++) { echo "<select class='sel' id='sel$i' name='sel$i' data-curr='0'> <option value=''>---</option>"; for ($j=1; $j<=5; $j++) { echo "<option value='$j'>$j</option>"; } echo "</select> "; } ?> <input type='button' name='btnReset' id='btnReset' value='Reset'> </form> </body> </html>
-
It seems IE doesn't like .hide() and .show() Changing these to .css("visibility","hidden") .css("visibility","visible") seems to work
-
You need an array for each row of your output table. In your example, the processing of each row would begin with $start = array ( '2014-10-01' => 0, '2014-10-02' => 0, '2014-10-03' => 0 ); You would build this array dynamically from your date range. You can use these array keys to create your table headings. (You copy this empty array when each item code changes ($item_array = $start;) As you process each record in your results you would add the qty into the copy of this array $item_array[$date] += $qty; When you get a change in the item code you out the array for the previous item, reset the value of the previous item (so you can test for a change again) and copy the array to start processing the new item code's records. Two things to bear in mind you don't output the array on the very first item change as the array will be empty at this point and the previous code is blank. After processing the records you still have the totals for the last item saved in the array, so output them
-
You are making life difficult for yourself. Instead of building lists from the selections and then deleting and reallocating from and to those lists, can I suggest an easier interface to make it easier to change the allocations until you are satisfied? Each radio button would be of the form <input type='radio' name='member[$playerid]' value='$teamtid'> then the processing of the form submission would simply be foreach ($_POST['member'] as $playerID => $teamID) { // save player and team allocation } Suggested form
-
That's right. That's why I was listing the output in the textarea for you, so you could see what was happening.
-
As for the GET, I was following convention. GET is for retrieving data POST is for sending data for an update The PHP returns the array array('var1'=>1, 'var2'=>2) encoded as a JSON string data = {'var1':1,'var2':2} Because the data type is specified as json it is decoded back to an array. $.each(data, function(x, y) is the jquery equivalent of PHPs foreach ($data as $x => $y)
-
Maybe $one=mysqli_connect('...... $query = mysqli_query($con, "SELECT * ..... Turn on error reporting.
-
Need help with writing a php code or data form
Barand replied to codedragon's topic in PHP Coding Help
Functions to look at are explode() count() array_reverse() Join() or implode() -
Here's pseudo code for how to do it Create empty array whose keys are your dates. Set previous item to blank Loop through the query results (checking for a change in the item code.) if item changes (ie not equal to previous item,) if prev item is not blank output prev item code and the array values into a table row endif create empty array whose keys are your dates. set previous item to current item endif Accumulate qty into the array element for the date endloop Output the row for the last item code
-
Those table look OK now, provided TransactionID is the primary key of your original table, which I'll assume is called "transaction". Don't use "." in column names, SQL will think that is database.tablename.columnname, change it to "LTS" For the check boxes I would do something like this SELECT wm.weekday_name , sw.weekday_id FROM weekdays_master wm LEFT JOIN selected_weekdays sw USING (weekday_ID) WHERE sw.transactionID = ? ORDER BY wm.weekday_id This will give you all the weekdays showing which were selected (those not selected will have NULL weekday_id +---------+-----+ | Mon | NULL| | Tue | 2 | | Wed | 3 | | Thu | 4 | | Fri | NULL| | Sat | NULL| | Sun | NULL| +---------+-----+ So now you can loop through the results, output the checkboxes and labels and set as "checked" if the id is not null