alan.davies 185 What's this?

Just checked-in out of interest after a long time away. Glad to see a lot of old friends still active here. Then I came across this post. It upset me a bit. Daniweb was the sun in my very dark days. I think a lot of us gained so much from DW, but you don't always get the attagirls you deserve. I think stackoverflow pretty much killed off most of the old coding forum sites. Not your doing. I think it's a miracle that you've kept DW going. Sorry miracle sounds like it's a fluke. It's not. It's your hard work and dedication that keeps DW going. Best wishes Dani with all your challenges, Alan (diafol)

Reverend Jim commented: Sherlock S03E01 "suddenly one is aware of staring into the face of an old friend" +0
alan.davies 185 What's this?
alan.davies 185 What's this?

Sorry, bit late with reply. Laravel used to be really lightweight, easy to set up and go. It's still a great product but as it's continued to develop, so the learning curve has increased. If you're looking to develop an MVC, then it has some great positives with regard to handling middleware, authentication, automatically creating templates for controllers, views etc from the artisan command. Seeding database tables. It uses fluent and eloquent. Other lightweight frameworks exist: Laravel Lumen (https://lumen.laravel.com/); Codeigniter, Yii, CakePHP.

Nearly every comparison site puts Laravel at the top, but that does not mean its the most user-friendly. If you're new to a MVC-type set up then you may find Yii or Codeigniter easier to start with. I've used all the ones listed at some point over the last 15 years. "Horses for Courses".

alan.davies 185 What's this?

Hi P! Wondering if you'd pop over again :) Nice to hear things going well for you.
I pop in maybe once a month these days,

Cheers diafol

(I deleted my account - he was an a***hole!)

Dani commented: Yes, he was ;) +0
alan.davies 185 What's this?

May be my display, but I can't see any tags so not sure which rdbms you're using. Each flavour of sql deals with different syntax. Also need an idea of table structure and joins. Nothing much to go on.

alan.davies 185 What's this?

Why do you need to avoid aggregate functions? What data are you trying to pivot? No info supplied so it's v difficult to help you.

anand9796 commented: I just want to display boolean value in pivoted column +0
alan.davies 185 What's this?

The server will store "session cookies" and check against that. It doesn't matter if you do from accessible to limited access pages. Every page should have a

session_start();

usually at the top of the page before any other output. Then if it's a limited access page...

session_start();
if(!isset($_SESSION['login'])){
    header("http://www.example.com/home");
    exit;
}

Instead of doing thins every single time in your limited pages, I'd use an include file...

includes/limited.php

    if(!isset($_SESSION['login'])){
        header("http://www.example.com/home");
        exit;
    }

your limited pages

session_start();
require "includes/limited.php";
//rest of page
alan.davies 185 What's this?

Depends how you are storing the data. If a person has to log in then you search for the users id in the table. If it doesn't exist, add the record, if it exists, edit the record. There are queries that will do this in one go.
If you do not have a login, you could alter the table to include the session variable and treat that as the id. Obviously the session var will change between sessions. Any more info? Table structures?

alan.davies 185 What's this?
Rhemiel commented: Thanks for the reply Alan +0
alan.davies 185 What's this?

I set up my own webdev business - full stack LAMP development. Never took a paid course. You build things up incrementally over years, learning the limitations and foibles of each technology and language, while trying to keep abreast of new developments and ensuring backwards-compatibilty.
CSS and HTML are pretty static markup "languages", so they can be learned quite quickly. Yes there are little techniques and best practice regarding them, but the basics are straightforward. Advanced CSS can be understood reasonably early on, but not written. Many webdevs will use themes or front-end frameworks, so stop them having to re-invent the wheel all the time. You do not have to be a guru in every single thing - just competent and thorough.
JS is a reasonably simple programming language and has many similarities to other languages. You could, potentially make do without any JS at all, but not many sites produced these days do. Modern Ajax technology is reliant on JS and any trivial updating on a page that does not warrant a full form submission will rely on JS. You can pick up "vanilla" JS quite easily too. Be careful of some frameworks or libraries such as jQuery, Angular, React etc, as they simplify the underlying JS. You may find that helpful, but one day you may need to use "vanilla" JS or a different framework. I suggest you learn the spanner before using a ratchet.
Unless you just want a static site with next to …

rproffitt commented: You remind of the following "How do I get to Carnegie Hall?" Answer: "Practice, practice, practice." +15
alan.davies 185 What's this?

Probably best to start your own thread. A 12 year old well dead thread ain't going to attract much attention.

Seeing as you also posted this to stackoverflow: https://stackoverflow.com/questions/56817045/using-crystal-report-with-php

Let us know if you have not got a solution in case we waste our time trying to help you and you're dealing with this on another site.

alan.davies 185 What's this?

You are duplicating HTML fields instead of setting them up as an array:

<td><input type="text" value="<?php echo $row['student_id']; ?>" name="student_id" ></td>
<td><input type="text" value="<?php echo $row['fname']; ?>" name="fname" >

Try this:

 <td><input type="text" value="<?php echo $row['student_id']; ?>" name="student_id[]" ></td>
 <td><input type="text" value="<?php echo $row['fname']; ?>" name="fname[]" >

But then unfortunately, you only deal with ONE sent ID in your handling code:

if(isset($_POST['submit']) ) {
    $tempDir = 'temp/'; 
    $student_id = $_POST['student_id']; //this is a single item
    $fname =  $_POST['fname']; //single item
    $filename = getUsernameFromEmail($student_id); 
    $codeContents = 'mailto:'.$student_id.'?id='.urlencode($student_id).'&fname='.urlencode($fname); 
    QRcode::png($codeContents, $tempDir.''.$filename.'.png', QR_ECLEVEL_L, 5);
}

In order to deal with an array of values, you need to use a loop (foreach or for or while) to iterate over each one. Alternatively, perhaps you could use some snazzy array functions, but these tend to take more processing than dealing with a simple loop.

alan.davies 185 What's this?

Like previous iterations, too many hidden features. How to do this or that should be obvious eg esc for full page editor. Not that intuitive. Hate trying to get to a post from the forum listing. Every time I end up on the last poster's profile. Grrr

rproffitt commented: I get the feeling that is by design. "I want you to meet people" even if I have to push you to do that. +0
alan.davies 185 What's this?

OK for this you need to have a new table. Let's call it game_images for now. You will need a minimum of three fields: id (pk) , game_id (fk), filename.

To keep it as simple as possible we'll assume that all your game images are stored in the same folder that is stored in your php code or in other dB table.

When you create a new game. Your form should have the option of uploading images too. When you get to handle the form data in your php file, add the new game as before but crucially, get the last added id before any other operations. You can then use that id, which will be the game_id to add new records to your game_images table. Be aware if you pass multiple images, all with the same html name attribute, the resulting $_FILES array may have a different structure to which you may expect. Try a few things and come back if stuck.

alan.davies 185 What's this?
    <?php
    session_start();
    if (!isset($_SESSION["username"])) {
            header("userLogin/?notloggedin=true"); //may need to use absolute or different relative address
            exit;
    }elseif($_SESSION["user_group"] !== 'admin') {
            header("whateverPage/?notadmin=true"); //may need to use absolute or different relative address
            exit;
    }
    //carry on with showing the page if logged in and admin
    ?>
alan.davies 185 What's this?

Just wondering how DW is doing re posts. I pass by from time to time and peruse the webdev forum. Apart from code snippets from Dani, I see very little new stuff. Am I missing something? Is it just that forum that's showing old posts? Even when I turn off the filter, it seems pretty quiet.

alan.davies 185 What's this?

Then again if line 6 fails so will 7. OP needs to test for that.

That was my point. I believe Line 6 is returning 'false'. From the manual on mysqli_query:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

The OP is running a SELECT query so he/she either gets a result object or FALSE.

So I'm assuming $q is set to FALSE, and therefore cannot be a valid parameter for line 7. This is my rationale for using a conditional...

if($q = mysqli_query($con,"select * from packages")){
     while ($r = mysqli_fetch_array($q)) {
     ..etc..
     }
}else{
    echo "Failed";
}

You could also use try/catch.

alan.davies 185 What's this?

What type are your users? Causual browsers or registered users? Both? This can direct your solution.

If you have registered users, then DB storage would be the preferred method, as users can then pick up their preferences from any device as long as they're logged in.
If you have causual browsers, then you can use traditional client-side cookies (this may require a cookie warning). This won't allow your users to share settings across devices, but it will allow them to use the same settings with the same device as long as they don't delete the cookies (or while the cookies have not expired).
For the even more casual browser - you could store data in a single session, i.e. "server-side cookies" in the $_SESSION superglobal variable.

You can even use a mixture of these approaches. A trivial example...

if(isset( $login_id )){
    $settings = getPrefsFromDB( $login_id );
}elseif(isset( $_COOKIES['settings'] )){
    $settings = getPrefsFromCookies();
}else{
    $settings = getPrefsFromSession();
}

This should be placed in a simple function or method - this would be useful for Ajax calls too.

alan.davies 185 What's this?

As webmachine states send the form to one file and then send data onwards from there once everything has been validated and cleaned. If you need the data to perform a few procedures, you can do this via includes. For example...

//do validation on POST vars
if(!$validate)  header('file0.php?err=1');
include 'file1.php';
include 'file2.php';

$success = file1func($var1) & file2func($var7) ;
$qs = ($success) ? 'msg=1' : 'err=2';
header('file0.php?'. $qs) ;
exit;
alan.davies 185 What's this?

How about you repost your code as a proper code block?

alan.davies 185 What's this?

JOINS in SAP HANA, from what I've read, are pretty much standard SQL affairs...

SELECT [alias1.field1, alias1.field2, alias2.fieldA...] FROM [table1] AS [alias1] INNER JOIN [table2] AS [alias2] ON [alias1.joinfield] = [alias2.joinfield] 

BTW - don't put in the square brackets - they're just there to denote placeholders / examples!

alan.davies 185 What's this?

Retaining values across 'pages' requires storage. The usual method is session data usually stored in variables... $_SESSION['somename'].

alan.davies 185 What's this?

You can skin this particular cat in many ways. here are 2 examples, neither of which I've given much thought to - so there's probably a few better ways out there. Anyway...

<?php
$inputArray =
    [
        [
            'SupSKU',
            'MfrSKU',
            'Cost'
        ],
        [
            'A',
            '11742-4',
            47.25
        ],
        [
            'B',
            '11742-4',
            283.5
            ],
        [
            'C',
            '0904101',
            995
        ]

    ];

//Using array functions and a reduced loop
function getSupSKU( $source, $SKU )
{
    $valArray = array_filter( $source, function ($var) use ($SKU) {
        return ($var[1] == $SKU);
    }); //filter array to just contain 11742-4
    $maxCost = max( array_column( $valArray, 2 ) ); //get max cost
    foreach($valArray as $item) {
        if ($item[2] === $maxCost) return $item[0]; //return FIRST max hit
    }
    return false;
}

//Using a big loop
function getSupSKU2( $source, $SKU )
{
    $output = false;
    $maxCost = 0;
    foreach($source as $item) {
        if ($SKU === $item[1] && $item[2] > $maxCost){
            $maxCost = $item[2];
            $output = $item[0];
        }
    }
    return $output;
}

$SKU = '11742-4';

array_shift( $inputArray ); //get rid of labels

echo getSupSKU( $inputArray, $SKU );

echo getSupSKU2( $inputArray, $SKU );

//EDIT - try some PHP execution timers on different length arrays - the straight loop consistently outperformed the array function script by around a factor of 3 in simple tests.

alan.davies 185 What's this?

Ok, so you want to avoid preg. How about this...

$theString = "´´´´Hello´´´´ !!!!Really??!!!! ´´´´nice´´´´"; //string to parse
$tokens = [
  ["´´´´", "\n<pre>\n\t<code>\n","\n\t</code>\n</pre>\n"],
  ["!!!!","<b>","</b>"]
]; //[replacement text, open tags, close tags]

$pos = [];

foreach($tokens as $tk){
  $lastPos = 0;
  $xcount = 0;
  while (($lastPos = strpos($theString, $tk[0], $lastPos))!== false) {
      $len = strlen($tk[0]);
      $pos[$lastPos] = ($xcount % 2 !== 0) ? $tk[2] : $tk[1];
      $lastPos = $lastPos + $len;
      $xcount++;
  }
}
ksort($pos);
$search = array_column($tokens, 0);
$sprintString = str_replace($search, '%s', $theString);
$cleanString = htmlentities($sprintString);
$output = vsprintf($cleanString, $pos);
echo $output;

This allows htmlentities().

Demo: https://repl.it/@diafol/UnwillingGoldenDll-1

Probably can be further condensed and fiddled to get empty <p>.

bprosic commented: This is really helpful :) I will use this code. Thank you! +0
alan.davies 185 What's this?

Looks a bit complicated to me, so I'd do something like this...

    $raw_string = "´´´´Hello´´´´ !!!!Really??!!!! ´´´´nice´´´´"; //string to parse
    $tokens = [
      ["/´´´´/", "\n<pre>\n\t<code>\n","\n\t</code>\n</pre>\n"],
      ["/!!!!/","<b>","</b>"]
    ]; //[replacement text, open tags, close tags]

    $the_string = $raw_string; //could do something to it here
    foreach( $tokens as $tk ){
        $the_string = preg_replace_callback( $tk[0], function($match) use ($tk) { 
        static $toggle = 0;
        if ( $toggle )
        {
            $toggle = 0;
            return $tk[2];
        }
        $toggle = 1;
        return $tk[1];}, $the_string ); 
    }
    echo $the_string;

Initial idea from... https://stackoverflow.com/a/1072690

OK, it doesn't deal with the empty paragraph, but its a start :)

Demo: https://repl.it/@diafol/UnwillingGoldenDll

bprosic commented: Not bad, thank you. It has less code, but I try to avoid preg_replace this time :( +2
alan.davies 185 What's this?

HG has summed it up succinctly. The bit I agree with most is... "I've given up caring".

It seems very little has happened in terms of domestic policies since Breakshit was announced. Either things have been slipped in during big Breakshit news so that they fly under the radar, or the Conselfservatives have been muted. I really, really hope its the latter.

If nothing else, this whole debacle has exposed many of our politicians to be feckless, self-serving, unprincipled grandstanders. Perhaps Trump was right when he said drain the swamp. Our system seems doomed, but there again, people have short memories.

ddanbe commented: Indeed, Breakshit it is! +0
alan.davies 185 What's this?

Great some free code!
Er, was there a question?

alan.davies 185 What's this?

Quite HG.

A good place to start: google "array functions php".

alan.davies 185 What's this?

The mind boggles a bit. You can build forums and blogs but can't build a simple website? You think people will want to buy your admittedly not very good scripts? Bit confused here. You can't use theme forest etc due to strict moderation?

You can self host i suppose. Use something like WP with woocommerce. Maybe EDD (easy digital downloads). You will need a ticket tracking system and thinK v carefully about how you will support customers. Selling goods that are not fit for purpose could land you in trouble, depending on where you are trading from. Good luck.

alan.davies 185 What's this?

Tun712. This whole project sounds like a nightmare. One you should decline, in my opinion. A three month job for a highly experienced one man band is very ambitious. Also for this type of work with a custom built interactive shop, I would expect a fee in excess of £15k. If I was a serious company wanting this type of functionality, I would not be trying to recruit an inexperienced programmer. This is not a trivial site. You may find third party software that has some of this functionality, either paid-for or free, but even then the testing and implementation can take weeks

rproffitt commented: Next thing is we'll read we wrote that it would only take weeks of testing. +15
happygeek commented: Absolutely spot on. Rushed jobs done by under pressure (and inexperienced) devs also often lead to serious security vulnerabilities +16
alan.davies 185 What's this?

I hardly ever look at the homepage. There is nothing there to pull me in. It just seems like a few random threads/posts scattered around the place - oh and a pretty big horrible advert. Is that what I'm supposed to be looking at? Sorry to say, it doesn't inspire. If the only content is old posts or new posts in my field of interest - I see no point in it as I'll be tootling off to that forum anyhow.

However, I'm assuming that it is working for the new members and first time visitors? From my perspective I'd like to see what's new on DW - not just posts. But I suppose that's really difficult, if the only new things are new posts. :(

alan.davies 185 What's this?
rproffitt commented: That's it! +0
alan.davies 185 What's this?

Ok sounds like your tables may not be normalized properly - apologies if this is not your case. For example, your teams should be given a unique identifier or id (Primary Key) in their own table. Any reference to teams outside your teams table, must not be on the id field (BTW this field can be called anything you like, but id is the convention). For example, a soccer results table...

id | gamedate | team_1 | team_2 | score_1 | score_2 (where team_1 denotes the home team and team_2 denotes the away team, score_1 and score_2 , the number of goals each team scores, respectively).

1 | 2018-09-08 | 7   | 86 | 3 | 1
2 | 2018-09-08 | 1   | 9 | 1 | 1
3 | 2018-09-08 | 6   | 22 | 0 | 1
4 | 2018-09-08 | 45   | 5 | 0 | 0
5 | 2018-09-08 | 61   | 54 | 5 | 3

So implementing a filter in html, is now just a question of, for example, providing the id of the team in the <option> tag value`:

<select name="team_filter">
    <option>All</option>
    <option value="7">Cardiff City</option>
    <option value="45">Brynamman Eagles</option>
    <option value="23">Swansea City</option>
    <option value="16">Newport AFC</option>
</select>

You can produce this select field easily with a php loop with data from the DB. The ID of the team in question can be sent to the server (form or link and picked up with something like $_GET['team_filter']). This can be done via bog-standard form or Ajax; …

alan.davies 185 What's this?

I don't have your data or tables, so I can only do something off the top of my head...

I think you need a GROUP BY xxtable_namexx.user_id in order to sum properly. But you seem to allow multiple attempts, so how are you supposed to sum? Count all correct answers, regardless of previous incorrect attempts (I'm assuming this is how you want to do it)?

alan.davies 185 What's this?

You need to understand the various parts involved with the card number. Type of industry / industry ID / issuer ID / personal account + checksum or if it doesn't need to be "real", use a random number generator (12-19 digit).
I'm assuming you just need a javascript implementation of this although you tagged this as post php. No need for a round trip to the server for this.

alan.davies 185 What's this?

You gotta love MS :( from innovators to dead-weight arse-draggers. Can't they just go bust already? Heh.

alan.davies 185 What's this?

Few ways to do this. You can hide the questions and then show them with a button click. You can get questions from the server via Ajax and insert them. If it's just bog standard questions a hide and show may be best.

alan.davies 185 What's this?
ui.item.drecord.name.fname

drecord from your json is an array ([...]) - so you need an index - and I don't see fname as a property under name - so I changeed it to surname - perhaps this would work...

 ui.item.drecord[0].name.surname

From your example...

{
    "drecord": [
         {
            "name": {
               "surname": "Aaliyah"
            }

I'm assuming the snippet is the for ui.item and that it's not part of an array, in which case you'd need ui.item[0].drecord[0].name.surname

alan.davies 185 What's this?

Dunno what's happens on Edge now...

No Hamburger menu at all and horrible layout for overlapping items on toolbar and single column of articles on screen (see attachment). Chrome on same machine working fine - albeit with the truncated text in sidemenu.

//EDIT

Scrap that, not working fine - not possible to upload image to show issue (JPEG 102KB). Pah, well it all seems pretty broken to me - I'll come back in a month to see if it's working.

rproffitt commented: Ditto in image uploading. I have same issues and have fallen back to using Imgur links. Broken. +0
alan.davies 185 What's this?

There are many UDFs here and I'm assuming that they are held in the config.php file. We can't comment on these as we cannot see them. Your query() UDF, I'm assuming runs some kind of prepared statement, judging from the code on line 7:

$admin = query("SELECT * FROM admin WHERE admin_id = ?", $_SESSION["admin_id"]);

That's all well and good, but what does it return an array (single record as in a PDO fetch as opposed to a fetchAll)?
Some of your code is open to SQL injection:

$course_id = isset($_POST["course_id"]) ? $_POST["course_id"] : ''; 
$courses = query("SELECT * FROM courses WHERE course_id = '$course_id'");

So it's expecting a form post (or Ajax post request) with the course id. You need to sanitize or use a prepared statement as in your first statement.
However, all seems to work from what you say until the template page:

$course_id = isset($_GET["course_id"]) ? $_GET["course_id"] : '';
$courses = query("SELECT * FROM courses WHERE course_id = '$course_id'");
$rows = $courses[0];

Again, open to SQL injection. But you seem to be in admin mode, so let's get to the nub of it...

$course_id = isset($_GET["course_id"]) ? $_GET["course_id"] : '';

Suggests you have this in the url querystring of the form action (or the Ajax get params or url querystring). If this is missing, then the following...

$courses = query("SELECT * FROM courses WHERE course_id = '$course_id'");

will give you FALSE and therefore the $courses[0] will not exist as $courses is boolean and not …

alan.davies 185 What's this?

work desktop - whoah! Dot dot dot. I'm expecting a dash dash dash next ...

On Microsoft Edge 41.16299.15.0 and Win10Edu OS

rproffitt commented: Same here. While some may say that's a browser bug, W10 stock and Edge shows same. +0
alan.davies 185 What's this?

Am using Chrome 70.0.3538.80 on Android 8.0.0 [SM-G930F Build/R16NW] - Samsung Galaxy S7
Still not showing side menu.
Cleared cache - still no menu
Its not showing on Samsung's own Internet (browser) App either.

Very odd. My desktop shows it fine, although with the truncated text with no tooltips, so you can't make out what some forums and subforums are (mentioned in another thread of mine).

rproffitt commented: Yes, that hamburger menu is indeed broken in more ways than one. +0
alan.davies 185 What's this?

On my android device I get no dropdown menu at all from the hamburger. Chat and profile image on the titlebar work fine as does the main dw logo.

Also while creating this post. The continue button on the first screen (deciding forum and thread type) was unresponsive. As does Continue to last step button. I have to click on the progress titles at the top to go on

alan.davies 185 What's this?

So why are they all +0? Is it because it's the community forum?

alan.davies 185 What's this?

See comment above

alan.davies 185 What's this?
Bitxfunding commented: thanks for helping +0
alan.davies 185 What's this?

I see a +0 next to post comments. Thought this was supposed to be votable. Nothing happens on tapping. BTW on Android. Also when I entered a comment and then decided to edit it, the original text did not show up in the edit box. So made me think I wS posting a new additional comment. Meaning I lost it and had to enter a comment for the third time!

Also why does edit post appear as an option when I clearly don't have the right to alter somebody else's post?

alan.davies 185 What's this?

Have a look at the competition: http://wowslider.com/demos.html

alan.davies 185 What's this?

Just a reply to the sidebar comment. Latest posts from sidebar gets you the filtered list again.

alan.davies 185 What's this?

I get the feeling that I've touched a nerve here Dani. I don't want the same as before because that wasn't working and I originally left due to the site being dead in all but name, so I recognise the issue. However, I thought I'd bring the issue to your attention as it is a feature that's pissing me off - can't speak for anybody else. Everybody else in their millennial clowncar can lap it up to their hearts content, he he.

rproffitt commented: Millennial clowncar. So many occupants, scary. +1. +0