Re: mysql_fetch_array problem

From: Date: Mon, 12 Aug 2002 02:26:33 +0000
Subject: Re: mysql_fetch_array problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-112086@lists.php.net to get a copy of this message
Hi Jonni! You should consider wrapping mysql_fetch_*() functions into a personalized function which also takes care of errors - at least for debugging. Your problem is typical - your query has some problems and mysql_run_query() returns a null result, which is indeed not a valid MySQL result resource. What you should do is to run something like $result=mysql_run_query(<your SQL here>); if (!$result) { echo("<B>MySQL query error in query </B><I>".
    <your SQL here>."</I><BR />\n");
echo(mysql_error()); } and debug the SQL. Now that's tedious to write for every, and that's why I was suggesting wrapping the thing into a function - but that's obviously not mandatory as long as you can debug it, right? :-) Another idea while I'm on the topic, if you do create a wrapper, you may also consider sending yourself an e-mail if an error occurs after everything works right - that way you'll be able to track errors quickly - and impress your customers! HTH Bogdan Jonni wrote:
hi everyone! i'm new here (and new to php) and have a question. i'm trying to run a simple blogger type script but am running into a problem i can't seem to troubleshoot. first, the three items i put into the database aren't showing up on my page and then when i try to go to the archive for the month, i get the following: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/blar/public_html/inc/main_inc.php on line 11 here's a part of my code of main_inc (first line is line 11): function showPosts($result,$page) { if ($myrow = mysql_fetch_array($result)) { do { $rawdate = $myrow["postDate"]; $formdate = date("l, F j, Y", (strtotime(ereg_replace('([0-9]*)-([0-9]*)-([0-9]*)','\2/\3/\1', $rawdate)))); if ($date != $formdate) {
    $date = $formdate;
    ?>
    <!-- Formatting for date -->
    <b><?=$formdate;?></b><br>
    &nbsp;<br>
    <?
} if ($page == 1) {
    showArchivePost($myrow);
} else {
    showMainPost($myrow);
} } while ($myrow = mysql_fetch_array($result)); } } /code thank in advance for any help. :) jonni b. http://blar.org http://uglypropaganda.com


« previous php.general (#112086) next »