Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. That is way the two types of join are meant to work. A INNER JOIN B returns only rows where there is a match on the join condition in both A and B A LEFT JOIN B returns all rows from A with any matching data from B. If there is no matching B row then columns from B contain NULL
  2. If you are expecting only one row then you already fetched it with $count=odbc_fetch_array($result); By the time you get to the while() loop there are no more left to fetch.
  3. Use a for() loop, and make $page an array.
  4. Erm, if it really were egregious then you wouldn't miss it
  5. Not pretty, but it works (I think). You can use sub-elements of this solution to break down that single column into three columns in your redesigned table, viz. prestring quantity poststring Data mysql> select * from tablea; +----+-------------------------------+ | id | col_a | +----+-------------------------------+ | 1 | Lorem ipsum = 88 dolor | | 2 | De profundis = 102 clamavi | | 3 | matutina usque ad = 55 noctem | +----+-------------------------------+ Query and results: UPDATE tablea SET col_a = CONCAT ( SUBSTRING_INDEX(col_a, '=', 1) , ' = ' , SUBSTRING_INDEX(TRIM(SUBSTRING_INDEX(col_a, '=', -1)), ' ', 1) + 1500 , ' ' , SUBSTRING_INDEX(TRIM(SUBSTRING_INDEX(col_a, '=', -1)), ' ', -1) ) ; mysql> select * from tablea; +----+----------------------------------+ | id | col_a | +----+----------------------------------+ | 1 | Lorem ipsum = 1588 dolor | | 2 | De profundis = 1602 clamavi | | 3 | matutina usque ad = 1555 noctem | +----+----------------------------------+ 3 rows in set (0.00 sec)
  6. All you have shown us is a single line of incorrect code and I pointed out what is wrong with that code. You could try <option value="0" <?php if ($_POST['special'] === '0') echo 'selected'; ?> >None</option> On the basis of a single line I can not and will not comment on an application solution, as I have no idea what the significance of the "0" versus "" is in the overall context. But your proposed alternative sounds wrong.
  7. that's because zero is considered to be "empty" eg $a = 0; if (empty($a)) echo 'ok'; //--> ok
  8. Create a table of areas and another for zipcodes. In the zipcode table, include the area_id to group the zips into the areas. Create a forecast for the area. Select which zipcodes that forecast applies to and save. If it isn't all zips in the area then create another forecast and select zips. Repeat as necessary. +-------------+ +-------------+ | area | | zipcode | +-------------+ +-------------+ | area_id |------------------------+ | zip | | name | +-----------------<| area_id | +-------------+ +-------------+ | | | | | | | +-------------+ +---------------+ | | | forecast | | applies_to | | | +-------------+ +---------------+ | | | forecast_id |----------<| forecast_id | | +---<| area_id | | zip |>---------+ | date | +---------------+ | text | +-------------+
  9. I'd make a couple of changes move the WHERE condition to the JOIN condition for the answer table use a LEFT join for the txtanswer table SELECT question.*, question_options.*, answer.*,txtanswer.* FROM question LEFT JOIN question_options ON question.question_id = question_options.question_id LEFT JOIN answer ON answer.option_id = question_options.qtn_option_id AND answer.empid = 'EMP8969' LEFT JOIN txtanswer ON txtanswer.qtn_option_id= question_options.qtn_option_id And don't use *s in the SELECT, specify the required fields.
  10. It sets the value after checking if it has changed $curname = $sn; pseudocode: set curname to empty while fetch next record if name value changed if we have a current value output the data for the current name endif set curname to new name value endif process the new record endwhile
  11. Hi Newbie, You are also incapable of working out that my name in my posts is in exactly the same place as your name is in your posts. (Strange, but true.) $curname stores the current name. I then test the value of the new name against to see if it has changed, and then store the new value in $curname.
  12. Not necessarily - you just had to read it
  13. http://lmgtfy.com/?q=addthis
  14. see https://developers.google.com/maps/documentation/javascript/examples/marker-simple
  15. The values are the wrong way round. You are putting the $btcaddy into the ip_address column
  16. If you are intent on using a text file then store it as json encoded data. Take advantage of the fact that an array key must be unique and make the BTC the key. To get the current submissions and put in an array $submissions = json_decode(file_get_contents('btcs.json'), true); to add a new submission if (isset($submissions[$btc]) { // error - already exists! } else { $submissions[$btc] = [ 'username' => $username , 'ip' => $ip ]; } to save the data, reverse the first code file_put_contents('btcs.json', json_encode($submissions)); However, you really should get to grips with using a database. It has so many advantages and it's a move you'll need to make sometime.
  17. ... or add a UNIQUE key to the field to make it impossible to add the same one twice
  18. You don't even need a loop. You can check the whole array with a single statement if ($input != str_replace($myArray,'', $input) ) { echo "Contains an existing value"; }
  19. You have only the database name
  20. Using an aggregation function (SUM(), COUNT() etc) without specifying a GROUP BY column(s) will return a single row containing the aggregate for the whole selection. Values for the other non-aggregated selected columns are indeterminate (although usually from the first record in the set.
  21. looks like data is array to me $obj = (object)[ 'name' => 'my name', 'data' => [2,4,6]]; print_r($obj); /* results ******************** stdClass Object ( [name] => my name [data] => Array ( [0] => 2 [1] => 4 [2] => 6 ) ) */
  22. $obj = (object)[ 'name' => 'my name', 'data' => [2,4,6]];
  23. Translating the above to sqlsrv dialect WHERE DATEPART(yyyy, datefield) = targetyear AND DATEPART(mm, datefield) = targetmonth
  24. Easiest way is to read the results into an array and then use array_chunk() with a chunk size of 5. Output each chunk as a row.
×
×
  • 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.