Re: [PHP4BETA] Syntax error?
| From: | David Robley | Date: | Mon, 17 Apr 2000 07:43:45 +0000 |
| Subject: | Re: [PHP4BETA] Syntax error? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-13619@lists.php.net to get a copy of this message | ||
Can you tell Outhouse to wrap lines around 72 chars, please?
On 17 Apr, Bradley wrote:
> I'm hoping this is a case of a simple syntax error and someone can
> clear this up fairly quickly. If more info is needed, please let me
> know. I'm sure I'm missing something fairly basic here, and if so,
> please straighten me out.
>
> I'm using this bit of code to do a simple query based on a couple of
> variables:
>
> "
> $db = mysql_connect("***server****", "****username****",
> "****password****");
>
> mysql_select_db("gu_mgmt",$db);
>
> if ($subcats == "All") {
>
> $result = mysql_query("SELECT * FROM $catty",$db);
> } else {
>
> $result = mysql_query("SELECT * FROM $catty WHERE SubCategory =
> '$subcats' order by DateAcquired",$db);
>
> The first bit of the "if" works just fine, but the second bit seems to
> return an empty result. I get no errors whatsoever, I just don't get
> any info on the page. Does it have something to do with the way I've
> used the variable to represent the table name? I'm terribly confused.
It's near home time so its not so easy to discern any problems with the
code. However, what might be worth a try is building the whole query as
a variable like
$query = "SELECT * FROM $catty WHERE SubCategory = '$subcats' order by
DateAcquired"
then you can echo the variable and see exactly what you are passing to
mysql. And if needed you could try the query in the monitor - or via
phpMyAdmin or however you can pass raw sql - and see what gives. Course,
as a bonus, the problem might go away by using this method :-)
>
> This script worked FINE when I was only passing the "subcats"
> variable. It didn't break until I tried throwing in the "catty"
> variable. I had the name of the table hardcoded before, but now I want
> to dynamically use the same script to check a few different tables in
> the same db.
>
> Thanks in advance for any and all help.
>
> Bradley
Cheers
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA