Ray Paseur 44 Newbie Poster

This is an old question, but there is a straightforward solution You can fetch the rows from the query results set and write them to an intermediate file with PHP fputcvsv(). Almost all Excel installations automatically associate the .CSV file sufix with Excel. Just fire up Excel and open the CSV file.

That said, these old code examples need to be updated to use a more modern MySQL connection. An article here describes the process.
https://www.experts-exchange.com/articles/11177/Why-PHP-Removed-Support-for-the-MySQL-API.html

Ray Paseur 44 Newbie Poster

It would be most helpful if you can help us isolate the error. Some of the tools that can help are PHP function var_dump(), and a current list of the documents without any qualifications. For example, your post says, "I added line 23" and since the post says "Undefined variable: text1 ... on line 23" we would naturally look to line 23 for the first step of the debugging process -- but neither line 23 has any reference to $text1, so we're kind of stuck. Without accurate line numbers and a faithful representation of the exact code set, there is not much chance that you can get a good answer from the community!

A good concept for questions like this is the SSCCE (google it). Then please put together an example that follows the SSCCE guidelines. Once you do that we are almost certain to be able to help!

rproffitt commented: var_dump(), SSCCE, MCVE, +1 +15
Ray Paseur 44 Newbie Poster

First thing to test - did the query work or fail? Add var_dump($result); after line 10 in fetch.php and run that script standalone, using a known good value for $nip. Before you go much further into this application, you may want to review the OWASP Guidelines for PHP and MySQL security. It looks like someone could feed something like "1 or 1=1" to the fetch.php script, and expose the entire table.

Ray Paseur 44 Newbie Poster

The general design for this sort of thing is called "data expiration" and "garbage collection." You put a DATETIME column into the database table that gives the expiration date of the row. After your initial connection to the database, you use a DELETE query something like this (pidgin code):

DELETE FROM mytable WHERE expiration_date < NOW()

HTH, Ray

Ray Paseur 44 Newbie Poster

I don't think I can add a lot to the technology discussion, but maybe this will help put the task in perspective.
https://en.wikipedia.org/wiki/Vistaprint

VistaPrint trades under the market symbol CMPR
https://finance.yahoo.com/quote/CMPR/profile?p=CMPR

It is a multi-billion dollar company with numerous subsidiaries and international reach. The key executives make more than $8,000,000 per year, on revenues over $2,5 billion. They have 10,000+ employees. They will crush you like a cockroach if you, even accidentally, infringe their patents. Recommend you respectfully decline this one.

rproffitt commented: Thanks for adding that. I find many (newbies) disregard patent and copyright law. Using their site as a template would be a bad idea. +15
Ray Paseur 44 Newbie Poster

Hey, Michael... I published a couple of articles a few years back at Experts-Exchange. These may be helpful.

Read this first:
https://www.experts-exchange.com/articles/11271/Understanding-Client-Server-Protocols-and-Web-Applications.html

Then see the AJAX "Hello World" here:
https://www.experts-exchange.com/articles/10712/The-Hello-World-Exercise-with-jQuery-and-PHP.html

HTH, Ray

Ray Paseur 44 Newbie Poster

This sounds like the list for 2017, but not to worry - those topics will still be around in 2019. My personal list would include

  • APIs (both production and consumption),
  • Security of applications and data,
  • GDPR compliance if you haven't already done it,
  • The changed posture of Google Maps (it's a pay service now),
  • IOT implementations.
Ray Paseur 44 Newbie Poster

This is an old topic, and there are more modern solutions available today (2019). Consider using the Iterators. Good online documentation is available here: http://php.net/manual/en/class.directoryiterator.php

Ray Paseur 44 Newbie Poster

Here's an annotated code snippet. Hopefully the ideas in the comments will be useful for you.

<?php
/**
 * Demonstrate some of the basics of MySQLi
 *
 * Some useful references for PHP and MySQL(i):
 *
 * http://php.net/manual/en/mysqli.overview.php
 * http://php.net/manual/en/class.mysqli.php
 * http://php.net/manual/en/class.mysqli-stmt.php
 * http://php.net/manual/en/class.mysqli-result.php
 * http://php.net/manual/en/class.mysqli-warning.php
 *
 * http://php.net/manual/en/mysqli.construct.php
 * http://php.net/manual/en/mysqli.real-escape-string.php
 * http://php.net/manual/en/mysqli.query.php
 * http://php.net/manual/en/mysqli.errno.php
 * http://php.net/manual/en/mysqli.error.php
 * http://php.net/manual/en/mysqli.insert-id.php
 *
 * http://php.net/manual/en/mysqli-result.num-rows.php
 * http://php.net/manual/en/mysqli-result.fetch-array.php <-- DO NOT USE THIS!
 * http://php.net/manual/en/mysqli-result.fetch-object.php
 *
 * Interesting: https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
 */

/**
 * E_ALL setting will cause PHP to report Notice, Deprecated, etc.
 * You REALLY WANT those hidden errors to be revealed!  You want to display
 * the errors during your development cycle, and log the errors during your
 * deployment cycle.
 */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('log_errors', TRUE);

/**
 * You may want to use variables instead of globally defined constants.  As you get
 * to more advanced programming your work may use more than one database (or different
 * users with different DB privileges).  Sometimes you may need to make more than
 * one DB connection object.  Since you cannot reDEFINE() a constant, this might not
 * be a good long-term habit.
 */
define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', 'mypass123');
define('DBNAME', 'topgrub');

/**
 * Get used to setting your output variables to some predictable value at the top
 * of your script, function, class, method, etc.  It will save you from the confusion
 * of spaghetti code, because you will be forced to think about what the script is
 * is creating, and you …
Ray Paseur 44 Newbie Poster

Change to error_reporting(E_ALL) and PHP will tell you what is wrong. The script relies on an undefined variable, $qname and so PHP silently substitutes a null string. The resulting query string has a LIKE clause that says LIKE '%%' thus it matches everything.

Ray Paseur 44 Newbie Poster

Your instincts are spot-on. Of course it's possible, and all eCommerce sites work this way. You might want to check out the educational offerings from SitePoint. They have some great "getting started" resources for apps like this.

Ray Paseur 44 Newbie Poster

Sometimes cache can help - it reduces repetitive trips to the data base and image libraries. There are services like YSlow that can help reveal the issues. If you can give us a link to the site, we may be able to offer more specific suggestions. Also, Happy New Year 2019!

rproffitt commented: Ray, check out GTMetrix from the first reply. Yslow is there. +15