?
Solved

Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource on PHP page

Posted on 2006-05-17
3
Medium Priority
?
2,335 Views
Last Modified: 2013-12-12
I keep getting two errors on my php page when running my query.  The two errors are:

Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in interpret.php on line 64

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in interpret.php on line 68
 
I can successfully run the query directly on my database and the sql statement runs fine. Here is my code for the page.

$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);

$siteid = $_GET['siteid'];
$controller = $_GET['controller'];

$result = "select distinct c.name,c.ssid,c.number,c.batchnum, c.exename
     from marketsonjobs m INNER JOIN mcast c ON c.ssid = m.ssid
     WHERE m.controller = '$controller' AND m.market = '$siteid' AND c.display = 'yes'
     AND c.active = 'yes' GROUP BY c.name;";

if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}

// Create table from results

$number_of_fields=mysql_num_fields($result);
   
echo "<table border=1 cellspacing=0 cellpadding=0>";
$flag=0;
     while($row=mysql_fetch_array($result))
{
     if($flag==0)

     for($r=0;$r<$number_of_fields;$r++)
    echo "<th><td bgcolor=#E8E8E8><b>".mysql_field_name($result,$r)."</td></th>";
      
$flag=1;
    echo "<tr>";

     for($r=0;$r<$number_of_fields;$r++)

    echo "<td>&nbsp;".$row[$r]."</td>";
    echo "</tr>";
}
    echo "</table>";


?>

Any help would be greatly appreciated.

Wayneray
0
Comment
Question by:wayneray
3 Comments
 
LVL 20

Accepted Solution

by:
Muhammad Wasif earned 600 total points
ID: 16698161
Change
$result = "select distinct c.name,c.ssid,c.number,c.batchnum, c.exename
     from marketsonjobs m INNER JOIN mcast c ON c.ssid = m.ssid
     WHERE m.controller = '$controller' AND m.market = '$siteid' AND c.display = 'yes'
     AND c.active = 'yes' GROUP BY c.name;";

to

$query = "select distinct c.name,c.ssid,c.number,c.batchnum, c.exename
     from marketsonjobs m INNER JOIN mcast c ON c.ssid = m.ssid
     WHERE m.controller = '$controller' AND m.market = '$siteid' AND c.display = 'yes'
     AND c.active = 'yes' GROUP BY c.name;";

$result = mysql_query($query);
0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16698464
your problem was that you didn't run the query in the first place as wasif mentioned.

you may need to add a line where u select whic databse to use
$conn = mysql_select_db('databseName');


and i'd add to wasif's comment, last line in his code
$result = mysql_query($query) or die (mysql_error());
0
 

Author Comment

by:wayneray
ID: 16698767
I feel sort of stupid. I still love PHP.  Thanks a bunch.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 13 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question