Another mysql_fetch_array() error....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aza^
Forum Newbie
Posts: 3
Joined: Wed Jan 01, 2003 4:18 am
Location: Nottingham UK

Another mysql_fetch_array() error....

Post by Aza^ »

I am getting an error on line 24 in the following code, click the link and you wll see all the code but in formatted PEAR standard, and line numbers. The error is displayed at the top of the page.

The url is here: http://nopaste.php-q.net/2633

Just incase your peeping eyes done see the error message it is;
Source: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\forum 2\functions.php on line 24
I previosly asked someone about this problem and he said to add an extra '=' on line 24 to make it '==' I gave it a shot, and it put it in a continues loop and made the site extremely slow also giving the error. He also insisted i used an extra '$' with the varibles, doubling the dollar, but i just got another error. Please help, i will be most greatfull and appreciate your expertise.

Edit: It seems that i have just got passed, this error becuase i had no connection to the database, so the following code must be wrong?

Code: Select all

<?php
    function mysqlconnect() 
    { 
    global $link; 
    $link = mysql_connect($serv , $user , $pass); 
    if ( ! $link ) 
    die ( "Couldn't connect to MySQL" ); 
    mysql_select_db( $data , $link ); 
    }  
?>
I have my displaying tabeles, but nothing is being drawn from the database/tables.
I would then include this page with functions, in my main page then just type mysqlconnect(); but this did not work for an unknown reason. I decided to connect normally i got no error message but no displaying data.
Thanks...
Aza........
?>
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

make sure:
table name, spellings, cAsE are correct.

also make sure your connecting to right db :?
try :

Code: Select all

<?php
function viewtopics() { 
$query = mysql_query("SELECT * FROM `topics` ORDER BY `Topic_ID`") or die ("mysql said: ".mysql_error()); 
    while ($topic = mysql_fetch_array($query)) { 
    echo(" 
    <table width="75%" border="1" cellpadding="0" cellspacing="1" bordercolor="#000000"> 
    <tr bgcolor="#666666" border="1"> 
    <td height="23" bordercolor="#666666"><div align="center"><strong>.:Topic:.</strong></div></td> 
    <td bordercolor="#666666"><div align="center"><strong>.:Started By:.</strong></div></td> 
    <td bordercolor="#666666"><div align="center"><strong>.ate:.</strong></div></td> 
      </tr> 
      <tr bordercolor="#999999" bgcolor="#999999"> 
    <td><div align="center">$topic['Topic']</div></td> 
    <td><div align="center">$topic['Username']</div></td> 
    <td><div align="center">$topic['Date']</div></td> 
    </tr> 
    </table>"); } } 

?>
it will tell you why it is haveing a problem.
Post Reply