Jump to content

[SOLVED] mysql_fetch_assoc(): supplied argument ERror


dubfoundry

Recommended Posts

I'm working with a simple straight forward code and keep getting this error message

 

 

mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

 

here is the code

 

$query = "SELECT * FROM tbl_gallery g, tbl_subgallery s WHERE s.gal_id=g.gal_id ORDER BY s.gal_id";

$result = mysql_query($query);

 

while($row = mysql_fetch_assoc($result))

{

  echo '<pre>' . print_r($row, true) .' </pre>';

}

 

 

the query works fine in php admin but i keep getting this message...

 

 

thanx for your help

 

Link to comment
Share on other sites

This error usually means your query is failing. To find out why change this line

$result = mysql_query($query);

to

$result = mysql_query($query) or die(mysql_error());

 

What is the error?

 

 

OK it said no database selected ..i forgot that line...its now working thank fellows..

 

hey if i have any other problem with it ill let you know.... appreciate it.

Link to comment
Share on other sites

ok it works but just with one problem it only out puts a single row under each category it doesnt do the rest...here is the final code i have...i cant figure out why it would only print one row...

 

mysql_select_db($database, $makeconnection);

$query = "SELECT * FROM tbl_gallery g, tbl_subgallery s WHERE s.gal_id=g.gal_id ORDER BY s.gal_id";

$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_assoc($result);

$prev_section  = null;

$sectionHeading = false;

 

//echo '<table border="1" cellpadding="5" cellspacing="2">';

 

 

do{

    if($prev_section != $row['gal_name'])

    {

        $prev_section  = $row['gal_name'];

        $sectionHeading = false;

    }

 

    if(!$sectionHeading)

    {

        echo '<h1>' . $row['gal_name'] . '</h1>';

 

        $sectionHeading = true;

    }

    else

    {

        echo  $row['subgal_name'].'<p> </p';

    }

}while($row = mysql_fetch_assoc($result));

}

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.