Re: Kind of a PHP Question



Alec wrote:
Jerry

Many apologies as I meant to answer your comment. I did post to
www.webmasters.alt last night and am still awaiting an answer.

You may be able to help with a proper PHP question though.

I have a news page that reads the information for a specific article
id. The search for the information goes as so, and this part works

$articleid = $_GET['articleid']; ***from previous link***
$resultlogin = @mysql_query ("SELECT articleid, title, category FROM
news WHERE articleid='$articleid'");
while ($row = mysql_fetch_array($resultlogin))
{
$articleid = $row['articleid'];
$title = $row['title'];
$category = $row['category'];
$eventcategory = $category; **I want to use this string in the
next search**
}

This retrieves the article information without any problems. But I
then have an events column, where I wish to list the next five events
after todays date that relate to the article category. Hence the line
$eventcategory = $category to store the article category for later
use.

$today = date("Ymd");

$query = (“SELECT event, category, DATE_FORMAT(date, '%D %M') AS date
FROM events WHERE date>=$today AND category=$eventcategory ORDER BY
date LIMIT 3");
$result = mysql_query($query) or die ('Error in query: $query .
' .mysql_error());

if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$event = $row['event'];
$category = $row['category'];
}
}

I get the following message 'mysql_fetch_array(): supplied argument is
not a valid'

If I do the following and actually specify the content of the field
category …. WHERE date>=$today AND category=’MCAD Software’…… this
works.

This text 'MCAD Software' is identical to the category text retrieved
previously with $eventcategory = $category;

What am I doing wrong??

Many thanks

Alec

Well, among other things, you're asking a MySQL question in a PHP newsgroup.

But as far as your PHP goes, if this is the code you're actually using, I'm not sure why it would happen. mysql_query() returns either a resource or false; the or die() isn't being triggered, so mysql_query() must be returning a resource. mysql_num_rows() does not fail, which indicates $result is a resource. However, when you get to the mysql_fetch_array(), $result is no longer a resource. That shouldn't be the case.

Two other things - first of all, it's not good to use die() or put out MySQL error messages in your code. Rather, if you have an error, handle it gracefully. Your code puts out an error message which can expose some of the internals of your database handling and then terminates the script processing. This leaves a partial page on the user's screen, which looks sloppy. Rather, handle the error gracefully and complete your page processing (i.e. footers, etc.) as if the request returned no data.

Then in your development system have display_errors=on in your php.ini file, and display_errors=off in your production system. It looks much more professional.

P.S. You did get a really good answer in a.w.w.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: do professional PHP programmers use error checking in their code?
    ... Spend less time writing error checking and more time documenting your ... I'll have an error function that reports error messages ... The idea, apparently, is that the PHP interpreter writes all ... function getWeblogEntries() { ...
    (comp.lang.php)
  • Re: do professional PHP programmers use error checking in their code?
    ... I'll have an error function that reports error messages ... The idea, apparently, is that the PHP interpreter writes all ... error checking, or strict typing, then I should use a real language, ... Ruby, then I should leave errors to the interpreter, since the whole ...
    (comp.lang.php)
  • Re: Recursive delete of directory - Directory not empty error
    ... run it I get random "Directory not empty" error messages. ... I've had a similar problem with PHP creating a file that didn't actually ... script to run, do the DB lookup, build the page and all the other time- ...
    (comp.lang.php)
  • A common researcher diagnosis error: misreading error messages
    ... vulnerability diagnosis error that seems to be happening more ... Error messages are important clues, ... Vulnerability information analysts - e.g. for vulnerability databases ... PHP apps. ...
    (Bugtraq)
  • Re: STDOUT vs. php://STDOUT
    ... only hold scalars), and I certainly will not guarantee you this will ... from PHP at any time, and cheating scope is often a sign bad design. ... I think the explanation is that while resource constants work, ... A quick check here reveals that allthough fcloseis called, the stream is NOT closed, and you can still use both $f and myfile to write. ...
    (comp.lang.php)