Re: Kind of a PHP Question
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Fri, 06 Feb 2009 10:37:03 -0500
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
==================
.
- Follow-Ups:
- Re: Kind of a PHP Question
- From: Alec
- Re: Kind of a PHP Question
- References:
- Kind of a PHP Question
- From: Alec
- Re: Kind of a PHP Question
- From: +mrcakey
- Re: Kind of a PHP Question
- From: Alec
- Re: Kind of a PHP Question
- From: Jerry Stuckle
- Re: Kind of a PHP Question
- From: Alec
- Kind of a PHP Question
- Prev by Date: Re: Kind of a PHP Question
- Next by Date: Re: Kind of a PHP Question
- Previous by thread: Re: Kind of a PHP Question
- Next by thread: Re: Kind of a PHP Question
- Index(es):
Relevant Pages
|