Jump to content

Siggles

Members
  • Posts

    95
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Siggles's Achievements

Member

Member (2/5)

0

Reputation

  1. Any ideas will this will not work... case "updateinv": foreach ($_POST['markedinv'] as $key => $val){ echo "Key: $key; Value: $val<br />\n"; $query = mysql_query("UPDATE timesheet SET marked_invoiced='1' WHERE log_id = '$val' "); } foreach ($_POST['cat'] as $key2 => $val2){ echo "Key: $key2; Value: $val2<br />\n"; $query2 = mysql_query("UPDATE timesheet SET marked_invoiced='0' WHERE log_id = '$val2' "); } but this will case "updateinv": foreach ($_POST['markedinv'] as $key => $val){ echo "Key: $key; Value: $val<br />\n"; $query = mysql_query("UPDATE timesheet SET marked_invoiced='1' WHERE log_id = '$val' "); } The echos work for both arrays so I know they exist.
  2. I changed the form to this then the processing page to this which works to tick the boxes. Yay! Now I need to work out how to untick the boxes (or make the value of marked_invoice to 0 instead of to 1)!!
  3. I have a form that is sending the following POST array to another page .. Key: markedinv10; Value: 10 Key: markedinv11; Value: 11 Key: markedinv19; Value: 19 Key: markedinv20; Value: 20 Key: x; Value: 6 Key: y; Value: 8 Key: opt; Value: updateinv I want to run a loop of UPDATE statements to a MySQL database updating the rows a field matches the value of every key in the array starting with markedinv... (the x and y are for the submit image and the opt key is for a switch statement). So for example: foreach ($_POST as $key => $val){ while ($key == markediv^){ $query = mysql_query("UPDATE timesheet SET marked_invoiced='1' WHERE log_id = '$val' "); } Can I loop an update statement first of all and if so what php can I use to check for markedinv^ and get the $val from them? many thanks for your help
  4. Hi, I am creating a directory of contacts and details for the company I work for using a mixture of PHP and MySQL. I was halfway through creating a database and adding fields such as 'fax number' when I thought, 'What if the boss asks me to add a field later down the line?' There must be some way to allow someone non compitent in web design / mysql etc to do this with an admin page on the site. It got me thinking that it would make sense to create a table in MySQL just for the fields or form fields themselves and then somehow link the data for thos fields from another table. But you would need more fields in that first table (for example), field_name = (eg, Address), field_visibility = (if it is created but you wish to hide it), field_order = (what order it is listed in the form online, name first, address second, etc). To cut to the chase, is this a simple thing to do? Does anybody have a good example where this is in use? How would I add form fields that need radio buttons or that only allow e-mail addresses or that are max 20 characters etc etc. How will I show them dynamically on the page? Any help would be greatly appreciated. Regards Siggles
  5. Out of curiosity, did you see my previous post? Sessions is not a horrible way to go, but I didn't see any reference to my code, so I wasn't sure if you saw it at all. Hi, I used a session variable with the new code. Cheers
  6. Thank you for your help. In the end I went for... $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'id'; switch ($sort) { case 'id': $order_by = ($_SESSION['$orderby'] =="predictions.id ASC" ? 'predictions.id DESC' : 'predictions.id ASC'); break; case 'un': $order_by = ($_SESSION['$orderby'] =="predictions.username ASC" ? 'predictions.username DESC' : 'predictions.username ASC'); break; } $_SESSION['$orderby'] = $order_by; Whether that is correct or the quickets way, I don't know. BUt it seems to work :-) Thanks for you help.
  7. Not sure I get you? I know that the ternary operator is like an if statement if that is what you mean. The question is, I would like the $order_by varaible to alternate between ASC and DESC. There is probably a much quicker route than using a switch statment but I started this way and am trying to get it to work. Any suggestions would be great.
  8. I have found this very handy for backgrounds but I am trying to use it on column ordering and it doesn't work. For example... $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'pid'; switch ($sort) { case 'un': $order_by = ($order_by=="predictions.username ASC" ? 'predictions.username DESC' : 'predictions.username ASC'); break; } and then.. SELECT...... FROM ..... fixtures.id ORDER BY $order_by and finally <td width="27%"><a href="admin.php?sort=un"><u>Username</u></a></td> Is it to do with me refreshing the page? Maybe I need a global or session variable?
  9. This is fixed now. Thanks for looking. Turns out the function is fine but I was using php empty function somewhere else and 0 counted as empty.
  10. Hi, I run a prediction league. At the heart of the prediction league is a script that runs some calculations on the result of the game and the score predicted by the user. For the last 2 games it has worked well. At the weekend a game drew 0-0 and now it has given everyone the score 0. Here is the code for the calculation script... I hope the variables used speak for themselves.. What can be going wrong here? Thanks. <? function calc_score($score_home, $prediction_home, $score_away, $prediction_away) { global $sum; global $correctresult; global $totaldiff; if ($score_home==$prediction_home && $score_away==$prediction_away) {//correctly predicted score - Rule 1 $sum+=25; } elseif ($score_home==$score_away && $prediction_home==$prediction_away) { //both draw so 10 points - Rule 2 $sum+=10; $correctresult=10; //used for correct result total in league table } elseif ($score_home>$score_away && $prediction_home > $prediction_away) { //both win so 10 points - Rule 2 $sum+=10; $correctresult=10; } elseif ($score_home<$score_away && $prediction_home < $prediction_away) { //both lose so 10 points - Rule 2 $sum+=10; $correctresult=10; } else { $correctresult=0; } $totalresult = $score_home + $score_away; //works out total goals of game $totalpredict = $prediction_home + $prediction_away; //works out total goals of prediction //works out difference between total goals for result and for prediction if ($totalresult > $totalpredict) { $totaldiff = $totalresult - $totalpredict; $sum-=$totaldiff; } elseif ($totalpredict > $totalresult) { $totaldiff = $totalpredict - $totalresult; $sum-=$totaldiff; } $totaldiff = -$totaldiff; //totaldiff is added to dbase and used in league table for goal accuracy } ?>
  11. then i still dont understand why it doesn't echo to the screen. Here is snippets of the full code. if (eregi('^[0-9]$', $presultmfc) && eregi('^[0-9]$', $presultother)) { mysql_query("INSERT INTO predictions (datecreated, username, id, resultmfc, resultother, score, lasteditedby) VALUES ('$datecreated', '$pusername', '$pid', '$presultmfc', '$presultother', '$pscore', '$adminlgd')"); $formsubtext='Enter a number between 0 and 9'; } else { $formsubtext='Prediction Submitted'; } then later in the code... <tr> <td colspan="4" align="left" class="style6" style="padding: 2px">Enter the User's Prediction below...</td> </tr> <?php if (isset($formsubtext)) { echo "<tr><td>"; echo $formsubtext; echo "</td></tr>"; } ?> <tr>
  12. Basically, someone submits a form to the same page, then a switch statement at the top of the page proccesses the POST variables and the result of that populates the text varaible with a message. I wanted to use something like isset so that I can add html in if it is set and not, if it isn't.
  13. Further up my code a variable is filled with a string. Eg, $text = 'thanks'; Later on i the code I write.. if (isset($text)) { echo $text; } Have I got the wrong understanding of how isset works? If I just put echo $text it works but I wanted to use isset to broaden what I am doing.
  14. I have inherited a dbase where the columns are as follows.. Day Date Month Year Time Sat 9 August 2008 15:00 I'd like to easily sort this dbase and ORDER BY the date for example. Is there an easy way to convert this data into one single entity, such as a timestamp. Thanks
×
×
  • 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.