Jump to content

bluefrog

Members
  • Content Count

    36
  • Joined

  • Last visited

Community Reputation

0 Neutral

About bluefrog

  • Rank
    Member

Profile Information

  • Gender
    Not Telling
  1. Was just wondering actually, would it be easier to replace the draw number? The code above will place draw number 1 for example, but all the code really does is output 1 or 2, is it possible to replace the number 1 or 2 with a string?
  2. Thank you for the reply Each ball is stored individually, I'm not really sure past that, I don;t work with databases at all normally. Here is the entire code: $select = mysqli_query($connection, "SELECT * FROM lotto where date = (select max(date) from lotto) ORDER BY draw_nr"); $rows = array(); while($row = $select->fetch_array()) $rows[] = $row; ?> <style> table { border-collapse: collapse; text-align: center; } </style> <h1><center>Results for <?php echo isset($rows[0]) ? date('l jS F', strtotime($rows[0]['date'])) : ""; ?> 49s Lotto</center></h1> <p>Draws are updated around 1pm and 6pm GMT. As requested by so many of you, the draw will now be shown in the order the balls were drawn. If you want the balls in numerical order, look to the right, or if using a mobile device, scroll right to the bottom.</p> <p> </p> <div class="draw-container"> <div> <div class="balls-heading"> <strong>Results</strong> </div> <div class="booster-heading"> <strong>Booster</strong> </div> </div> <div class="clr"></div> <div> <?php $color_mapping=array('0'=>'BLUE','1'=>'GREEN','2'=>'RED','3'=>'ORANGE','4'=>'YELLOW','5'=>'BROWN','6'=>'VIOLET', '7'=>'BLUE'); for($i = 0; $i < count($rows); $i++) { $res = explode(",", $rows[$i]['result']); $rRows = array(); echo "<p style='float:left;' class='drawnumber'>(Draw number ".$rows[$i]["draw_nr"].")</p><p> </p>"; for($j = 0; $j < count($res); $j++) echo "<img class='ball' src='http://www.mysite.co.uk/images/fortyninesballs/".$res[$j].".gif'>"; echo "<td><img class='ball booster img-responsive' src='http://www.mysite.co.uk/images/fortyninesballs/".$rows[$i]["booster_ball"].".gif'></td><p style='clear:both;'></p>"; } ?> </div> </div>
  3. Hi all, thank you for taking time to browse my thread. I have had some code written for me a while back which fetches either 1 or 2 rows from a database depending on if there are one or two rows based on the date. What it does is simply keep track of lotto results for each of the 2 daily draws along with the booster ball. Now, here's what I'm trying to do. Each row should really have it's own header such as Lunchtime or Teatime based on the draw number fetched from the database. I'm struggling a little. I understand how the code works and that I should have some kind of if/else (I think) in there, but I can't understand where or how to place it. Here is the current code <?php $color_mapping=array('0'=>'BLUE','1'=>'GREEN','2'=>'RED','3'=>'ORANGE','4'=>'YELLOW','5'=>'BROWN','6'=>'VIOLET', '7'=>'BLUE'); for($i = 0; $i < count($rows); $i++) { $res = explode(",", $rows[$i]['result']); $rRows = array(); //echo "<tr><td><p style='float:left;'>".$rows[$i]["draw_nr"].".</p></td>"; for($j = 0; $j < count($res); $j++) echo "<img class='ball' src='http://www.number49s.co.uk/images/fortyninesballs/".$res[$j].".gif'>"; echo "<td><img class='ball booster img-responsive' src='http://www.number49s.co.uk/images/fortyninesballs/".$rows[$i]["booster_ball"].".gif'></td><p style='clear:both;'></p>"; } From what I understand it fetches the results, turns them into an array and pulls each ball separately, from the rows and then appends the booster ball result for the current row. I'm thinking that it should have an if statement around $rRows array which reads if there is only a single row (based on draw number and date) and if it is outputs the code for the single row, then the else statement outputs the code for both. With a different header for each row I know I look like an idiot to you guys (and gals) who know this stuff inside out, but I am trying to learn although sadly this is WAY out of my ability at the moment. Any help as to where to place the if statement and how to get the results based on row number would be very gratefully accepted, but please don't be rude, I know I'm asking a lot, and I also know I know very little compared to the rest of you, but it doesn't give you warrant to be nasty. Thank you in advance to anybody who may be able to help me get this working, it's been driving me nuts for over 3 hours now
  4. That is what I'm trying to achieve, generate a number based on three others. Or do you mean the 'purpose' of the code. Oh you've edited your post to a "." Guess this makes no sense to people reading it now lol
  5. The array is 6 numbers, I want to take the highest three numbers and generate a fourth number based on the highest number (one less). However if the highest number is 48 and the next highest is 47, then the generated number should be 49, but no higher. If the two numbers were 48 and 49 then the number should be lower, so in this case 47 (one less than the next lowest. Works on numbers 1-49. This is for a lottery website I am setting up (hopefully). Does that make sense? It does in my head lol
  6. I am trying to write what should be a short piece of code to generate a 4th number based on three. There is an array with 6 numbers in it, the code needs to take the last three (numerical order) and generate a fourth based on some rules: if last number (array [5]) = the same as array[4] and array[5] is less than 49 then array[5] = array[5] +1 if last number (array [5]) = the same as array[4] and array[5] is equal to 49 then array[5] = array[4] -1 IF array[3] is more than 2 less than array[4] eg: Number 1,2,44,45,47,48 By these rules the new number can be 49, as although number number 5[4] would be the same as the generated number ([5]-1) it is less than 49 so can be number 6[5] +1 instead. Number 1,2,44,45,46,48 By these rules the generated number can be 47, as number 5[4] is more than two away from the last number [5] Number 1,2,44,45,48,49 By these rules the generated number would be 47, as the last number [5] is 49 and the second last [4] is the next number in reverse sequence, so cannot go higher than 49 and can't use the next number down, so uses the next number [4] -1 Here is what I've cobbled together - no laughing please I'm new: <?php //$lunch = explode(",",$lt_results); $lunch = array("1","1","1","44","47","48"); sort($lunch); echo '<br>'; echo $lunch[3]; echo ' - '.$lunch[4]; echo ' - '.$lunch[5]; $last = --$lunch[5]; echo '<br>Last = '.$last; if ($last == $lunch[4]){ echo "<br>Ball 5 & pick are the same"; if ($lunch[5]<"49"){ $last = $lunch[5]; echo $last; } } else { echo "a is smaller than b"; } ?>
  7. @ginerjim lol, I intend to, I find php a most versatile language, however I guess by the time I've learned it something will have replaced it lol. I was really looking to see if I had selected the correct function (?). @psycho thanks. Because I'm still wet behind the ears so to speak, I was having trouble deciding between the two, they both seemed to do the same job which is why I posted, a clarification really. But sound advice, thanks
  8. Thank you Barand, exactly the info I was looking for. @jinerjm, yes I have but was more than a little confused by some of the examples - remember I don't code php, I am very very new.
  9. Hi, I have a group of numbers like this: 1 - 2 - 3 - 4 I want to break that single variable apart and enter the number only into an array, then print out each number as needed (as entered into the array). Trouble is I have literally no idea where to even begin, and little knowledge of php, probably less than basic. I am assuming I will need something like preg or explode? Any brief examples would be very much appreciated, also, if I wanted to list these from lowest to highest is that much or a task? Many thanks in advance
  10. Ah I got it. Is there a shorter version than this: function ball_callback($atts,$content,$tag){ //collect values, combining passed in values and defaults $values = shortcode_atts(array( 'num' => 'other' ),$atts); //based on input determine what to return $output = ''; if($values['num'] == '1'){ $output = 'output for 1'; } else if($values['num'] == '2'){ $output = 'output for 2'; } else if($values['num'] == '3'){ $output = 'output for 3'; } else{ $output = ' '; } return $output; } add_shortcode('ball','ball_callback');
  11. Actually that only returns the 'else' statement ;/
  12. No I understand how to create and use a shortcode, I've done a few, I'm struggling with the function element. Barand suggests a good solution, however I'm a little confused as to how to correctly write the number from the shortcode to the function. Would something like this work: function ball_number($atts,$content,$tag){ $values = shortcode_atts(array( 'ball' => ' ' ),$atts); $output = ''; if($values['ball'] == '1'){ $output = 'image code for ball number 1'; } else if($values['ball'] == '2'){ $output = 'image code for ball number 2'; } else if($values['ball'] == '3'){ $output = 'image code for ball number 3'; } else{ $output = ' '; } return $output; } add_shortcode('ball','ball_number'); Thanks for all of your input so far, it's appreciated
  13. Sorry you'll have to bare with me, I'm not great with php as I said. How do I get the number into a variable? The number will literally just be written into a shortcode (which will be the same for each number) with the only difference being the number in the shortcode: [myshortcode num=40] [myshortcode num=13] [myshortcode num=6] for example. Thanks in advance
  14. I have no idea how to properly describe this topic as I'm fairly new to php, but here is a description of what I am trying to do: This is firstly for a wordpress functions file Ok what I am trying to achieve is have a small piece of code (in this case a wordpress shortcode) read a number in plain text: e.g. [myshortcode num=43] And replace the shortcode input (43) with an image named the same (43.jpg (http://www.mysite/path/43.jpg")) This is for a lottery style site where I want to put my picks for the day so I have 49 numbers in total. And each number is currently a full line of html code - I really need to make input faster lol. I have tried 'if and' I have tried 'if or' but I'm struggling. Anybody know how to take that and turn into a function? I know how to get it into wordpress and make it a shortcode, I just need help with the actual function side of things, my code was incredibly long and didnt work lol Thank you all in advance
×
×
  • 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.