Hi again,
No, I'm afraid not :queasy:
Apart from that, here ...
while($r=mysql_fetch_array($result))
{
$field=$r['$field'];
}
... you're using the variable $field for two different things inside the function. And putting single-quotes around the key value renders it as the string $field, not the contents of $field.
It's better to do 'defensive' coding, especially with larger projects. There's so many little things that can go wrong. So, for example, to be clear that I want an array of return values, I declare the array ($retval) before I start using it.
I know PHP can allow non-rigorous coding, so for a lot of server-setups, leaving out the declaration wouldn't cause a problem, but I always assume that my target server has error reporting turned on to maximum.
You can do this for all scripts in the php.ini file, or for a particular script by putting...
error_reporting(E_ALL);
... at the top of the page.
Try the following to see what the <pre></pre> tags allow you to do...
<p>Hello world.
Even though I have typed a line-break (by pressing return), this sentence is on the same line as 'Hello world'.</p>
<pre>Hello world.
Here I get the line-break.</pre>
I always use print_r() to display arrays ... try the code without the <pre> tags to see why I use them with it!!
Have a look here for a proper explanation.
A couple of tips ...
1) Don't cut your code down to the bare minimum, at least to start with.
2) Try and get used to indenting your code. There are different methods, rules, styles etc. so choose a way that suits you. Have a look here or google 'php tutorial code organization' for a host of info.
3) Don't embed variables in strings. I know PHP allows it and loads of tutorials do it, but it's a pain in the a** to debug. Just cut in and out of strings with the dot-operator. Like ...
$sql = "
SELECT *
FROM ".$table."
WHERE ".$qualifier." LIKE '1'
ORDER BY company_name
";
(indented as well, naturally using the SQL syntax to guide me).
Come back if you still don't understand anything.
Paul 🙂