|
Posted by Erwin Moller on 11/22/05 11:25
Wendy Hoovens wrote:
> Erwin Moller schreef:
<snip>
>>
>> That doesn't make sense.
>> The $result contains a complex structured array, called a 'resource',
>> that might contain all the rows if the query was succesfull, besides
>> possible other stuff. You cannot just echo it.
>>
>> Try this instead:
>> <pre>
>> <? print_r($result); ?>
>> </pre>
>>
>> Now you get a dump of the $result.
>>
>> If you want to use the $result to display things that your query
>> returned, loop over the resultset.
>> Read on here on how and what and many examples too:
>> http://nl3.php.net/manual/en/function.mysql-query.php
>
>
> Thank you for your feedback ERwin! I've been reading about the
> mysql_fetch possibilities but it seems I'm still missing out on
> somethinbg. I know that without the mysql_fetch I can only echo a
> Resource id #x But how does it translate correctly to the actual valuess?
The resourceID is just that. You shouldn't try to use it directly, like in
echo.
>
> <?
> $SQL = "SELECT loaction, COUNT(type) FROM bib WHERE ";
should be 'location' instead of 'loaction' of course. :-)
That is excactly where the echo $SQL can help you.
Just copy the SQL and try to execute it straigth against the database, and
you will get the errors, or results.
By far the easieast way to debug. :-)
> $SQL.= "type='magazine' AND ";
> $SQL.= "datum='$start' AND ";
> $SQL.= "datum<='$eind' GROUP BY location";
> echo $SQL;
> $result=mysql_query($SQL);
> while ($row = mysql_fetch_assoc($result)) {
> echo $row['location'];
> echo $row['type'];
> }
> ?>
>
Well, look at the query:
It starts with SELECT location, COUNT(type)....
So the columns you get back will have names like:
- location
- COUNT(type)
So you should use the names when retrieving information from the row, like
this:
echo $row["location"];
I would also advise you to give 'COUNT(type)' an alias to make things
clearer.
Like:
SELECT location, COUNT(type) as numbersOfTypeFound FROM...etcetc
then retrieve it with the aliasname you just made up, like:
echo $row["numbersOfTypeFound"];
Good luck Wendy.
Regards,
Erwin Moller
> Kind regards,
>
> Wendy
Navigation:
[Reply to this message]
|