Jump to content

MySQL_fetch_array error :S


slipperyfish

Recommended Posts

Hey! Here is my PHP code:

[code]<?php

[CONNECT INFO]

$feedbackSQL = "SELECT * FROM feedback ORDER BY time ASC LIMIT 10";
    $feedback = mysql_query($feedbackSQL) or die("Error communicating with database.");

    If ($feedback) {

        while($feedbackInfo=mysql_fetch_array($feedback)) {

            $feedbackName = $feedbackInfo[feedbackName];
            $feedbackEmail = $feedbackInfo[feedbackEmail];
            $feedback = $feedbackInfo[feedback];
            
                      print "<u>Feedback</u><br /><b>Name:</b> " .$feedbackName. " - <b>Email:</b> " .$feedbackEmail. "<br />" .$feedback. "";

        }
              

    // Display numbers

        $totalSQL = "SELECT COUNT(*) FROM feedback";
            $totalRun = mysql_query($totalSQL);
            $total = mysql_fetch_array($totalRun);

        If ($total > "10") {
            $total = abs($total);
            $pages = ($total/10);
            
            $x = 1;
            while($x<$pages){
                echo $x;
                $x++;
            }

        }    



    } else {

    print "No feedback, soz boz!";

    }

?>[/code]

Thats my work in progress .. however it, returns the first result form the db, then underneath has this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fhlinux218/n/newbiestyle.co.uk/user/htdocs/help/feedback.php on line 14

.. confused I am, here's the script's URL:

[a href=\"http://www.newbiestyle.co.uk/help/feedback.php\" target=\"_blank\"]http://www.newbiestyle.co.uk/help/feedback.php[/a]



Help much appreciated..

Link to comment
Share on other sites

You are reusing your pointer to the results. You can't do that and expect it to work.
Your code:
[code]<?php
    $feedback = mysql_query($feedbackSQL) or die("Error communicating with database.");

    If ($feedback) {

        while($feedbackInfo=mysql_fetch_array($feedback)) {

            $feedbackName = $feedbackInfo[feedbackName];
            $feedbackEmail = $feedbackInfo[feedbackEmail];
            $feedback = $feedbackInfo[feedback]; // here's the problem
?>[/code]
The fix:
[code]<?php
    $rs = mysql_query($feedbackSQL) or die('Problem with query: ' . $feedbackSQL . '<br>' . mysql_error()); // don't need long varibale names for query results. If you're going to use the "or die" clause, make the message it puts out meaningful so you can fix the error.

    If ($rs) {

        while($rw=mysql_fetch_assoc($feedback)) { // again, why the long variable name

            $feedbackName = $rw['feedbackName'];
            $feedbackEmail = $rw['feedbackEmail'];
            $feedback = $rw['feedback']; // now there is no conflict on the variable names
?>[/code]
See the comments in the above code. You will have to change the rest of your code appropriately.

Ken
Link to comment
Share on other sites

ok, iv done what you put ken.. this is my new code:

[code]<?php

$db = mysql_connect("*****", "*****", "*******") or die("Could Not Connect");
if(!$db)
    die("no db");
if(!mysql_select_db("*******",$db))
    die("No database selected.");

$feedbackSQL = "SELECT * FROM feedback";
    $rs = mysql_query($feedbackSQL) or die('Problem with query: ' . $feedbackSQL . '<br>' . mysql_error());

    If ($rs) {

        while($rw=mysql_fetch_assoc($feedback)) {

            $feedbackName = $rw['feedbackName'];
            $feedbackEmail = $rw['feedbackEmail'];
            $feedback = $rw['feedback'];
            
                      print "<u>Feedback</u><br /><b>Name:</b> " .$feedbackName. " - <b>Email:</b> " .$feedbackEmail. "<br />" .$feedback. "";

        }
              
    } else {

    print "No feedback, soz boz!";

    }

?>
[/code]

you can view this script:
[a href=\"http://www.newbiestyle.co.uk/help/feedback.php\" target=\"_blank\"]http://www.newbiestyle.co.uk/help/feedback.php[/a]

Im now getting the following error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/fhlinux218/n/newbiestyle.co.uk/user/htdocs/help/feedback.php on line 14


so confused :S

help appreciated!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.