Jump to content

mysql_fetch_array(): supplied argument is not a valid MySQL result ??


JTapp

Recommended Posts

Although I'm now bug-eyed, I started from scratch.  There are no more error messages and most of my data is getting returned.

I'm just not seeing variables 20-24 in the table at the bottom.  It's probably something fairly simple at this point....

Here's the code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<?php

$username = "*****";

$password = "******";

$hostname = "MYSQLHOST";

 

$dbhandle = mysql_connect($hostname, $username, $password)

  or die("Unable to connect to MySQL");

 

$selected = mysql_select_db("****",$dbhandle)

  or die("Could not select *********");

 

 

$id = $_GET['id'];

 

$query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.strDistrictName, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMailingAddress, a.strLodgeMailingAddress2, a.strLodgeMailingCity, a.strLodgeMailingPostCode, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error());

while ($row = @mysql_fetch_array($query))

 

{

$variable1=$row["strLodgeName"];

$variable2=$row["intLodgeNumber"];

$variable3=$row["strDistrictName"];

$variable4=$row["strLodgeWEB"];

$variable5=$row["strLodgeCounty"];

$variable6=$row["dtChartered"];

$variable7=$row["strLodgeMailingAddress"];

$variable8=$row["strLodgeMailingAddress2"];

$variable9=$row["strLodgeMailingCity"];

$variable10=$row["strLodgeMailingStateCode"];

$variable11=$row["strLodgeMailingPostCode"];

$variable12=$row["strLodgeEmail"];

$variable13=$row["strLodgePhone"];

$variable14=$row["strLodgeFax"];

$variable15=$row["strDrivingDirectons"];

$variable16=$row["dtMeetingTime"];

$variable17=$row["dtMealTime"];

$variable18=$row["strFloorSchool"];

$variable19=$row["strLodgeNews"];

$variable20=$row["strOfficerTitle"];

$variable21=$row["strFirstName"];

$variable22=$row["strLastName"];

$variable23=$row["BusinessPhone"];

$variable24=$row["PersEmail"];

 

//table layout for results

 

echo ("<tr>");

echo "<center>\n";

echo "<p>GRAND LODGE OF LOUISIANA - LODGE LOCATOR RESULTS\n</p>";

echo "Lodge Name: $variable1</p>";

echo "<p><b>Lodge Number:</b> $variable2</p>";

echo "<p><b>District Name:</b> $variable3</p>";

echo "<a href=\"$variable4\">Click Here To Go To The Lodge Website</a>";

echo "<p><b>Lodge County:</b> $variable5</p>";

echo "<p><b>Lodge Chartered On:</b> $variable6</p>";

echo "<p><b>Lodge Address:</b> $variable7, $variable8</p>";

echo '<p>' . $variable9 . $variable10 . $variable11 . '</p>';

echo "Click Here To Email The Lodge";

echo "<p>Lodge Phone Number: $variable13, Lodge FAX Number: $variable14</p>";

echo "<p>Lodge Driving Directions: $variable15</p>";

echo "<p>Lodge Lodge Meeting Time: $variable16</p>";

echo "<p>Lodge Lodge Meal Time: $variable17</p>";

echo "<p>Lodge Floor School: $variable18</p>";

echo "<p>Lodge News: $variable19</p>";

echo "<img src='{$row['link']}'>";

echo "</center>\n";

echo ("</tr>");

}

 

//query details table begins

 

 

echo "<center>\n";

echo "<H2>Roster of Lodge Officers</H2>\n";

echo "<table border='1'>

  <tr>

<th>Officer Title</th>

<th>Officer First</th>

<th>Officer Last</th>

<th>Officer Email</th>

<th>Officer Phone</th>

 

</tr>";

 

if (mysql_num_rows($query)) {

while ($row = mysql_fetch_array($query)){

$variable20=$row["strOfficerTitle"];

$variable21=$row["strFirstName"];

$variable22=$row["strLastName"];

$variable23=$row["PersEmail"];

$variable24=$row["BusinessPhone"];

 

//table layout for results

 

print ("<tr>");

echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n";

echo "<td class=\"td_id\">$variable20</td>\n";

echo "<td class=\"td_id\">$variable21</td>\n";

echo "<td class=\"td_id\">$variable22</td>\n";

echo "<td class=\"td_id\">$variable23</td>\n";

echo "<td class=\"td_id\">$variable24</td>\n";

print ("</tr>");

}

}

 

?>

</body>

</html>

Link to comment
Share on other sites

The reason your first query failed is because you had used the variable $metode in the query which was undefined.  You can use a blank search in MySQL, meaning "...WHERE column LIKE '%%'" won't trigger an error.  However, when PHP sees "...WHERE $metode LIKE '%%'" and doesn't have a value for $metode, you get "...WHERE LIKE '%%'" which will trigger a MySQL error.  Also, try cleaning up your code again.  Why do you set $variable1-24 when you can just use the originally indexed items of the array?  It would save you coding space, time, and size.

Link to comment
Share on other sites

I tried to change my statement "...WHERE $metode LIKE '%%'..." to "....WHERE column LIKE '%%'.." but it failed to return anything at all.  The change was made on my results.php form.

If no results were returned but you didn't get an error, that's just because nothing matched the query, which is something that'll be really tough for us to help you out with.

Link to comment
Share on other sites

Hmmm... I was getting variables 1-19 populated but was looking for variables 20-24 to be populated.

Then I applied your recommendation and I stopped getting variables 1-19 as well as 20-24.

The data is definitely there... I triple checked it in MySql....

 

The difference in the variables is 1-19 are coming from tblLodges and variables 20-24 are coming from tblOfficers.

Link to comment
Share on other sites

Well.. now I seem to be getting just about everything.. but a single problem remains.

My table (2nd query at bottom of code) is only reporting one row of results when there should be two or more. 

This is the section that has variables 20-24...

 

Does anybody have any thoughts on this?

 

Here is the latest code:

 

$id = $_GET['id'];

 

$query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.strDistrictName, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMailingAddress, a.strLodgeMailingAddress2, a.strLodgeMailingCity, a.strLodgeMailingPostCode, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error());

while ($row = @mysql_fetch_array($query)) {

$variable1=$row["strLodgeName"];

$variable2=$row["intLodgeNumber"];

$variable3=$row["strDistrictName"];

$variable4=$row["strLodgeWEB"];

$variable5=$row["strLodgeCounty"];

$variable6=$row["dtChartered"];

$variable7=$row["strLodgeMailingAddress"];

$variable8=$row["strLodgeMailingAddress2"];

$variable9=$row["strLodgeMailingCity"];

$variable10=$row["strLodgeMailingStateCode"];

$variable11=$row["strLodgeMailingPostCode"];

$variable12=$row["strLodgeEmail"];

$variable13=$row["strLodgePhone"];

$variable14=$row["strLodgeFax"];

$variable15=$row["strDrivingDirectons"];

$variable16=$row["dtMeetingTime"];

$variable17=$row["dtMealTime"];

$variable18=$row["strFloorSchool"];

$variable19=$row["strLodgeNews"];

$variable20=$row["strOfficerTitle"];

$variable21=$row["strFirstName"];

$variable22=$row["strLastName"];

$variable23=$row["BusinessPhone"];

$variable24=$row["PersEmail"];

 

//table layout for results

 

echo ("<tr>");

echo "<center>\n";

echo "<p>GRAND LODGE OF LOUISIANA - LODGE LOCATOR RESULTS\n</p>";

echo "Lodge Name: $variable1</p>";

echo "<p>Lodge Number: $variable2</p>";

echo "<p>District Name: $variable3</p>";

echo "<a href=\"$variable4\">Click Here To Go To The Lodge Website[/url]";

echo "<p>Lodge County: $variable5</p>";

echo "<p>Lodge Chartered On: $variable6</p>";

echo "<p>Lodge Address: $variable7, $variable8</p>";

echo '<p>' . $variable9 . $variable10 . $variable11 . '</p>';

echo "Click Here To Email The Lodge";

echo "<p>Lodge Phone Number: $variable13, Lodge FAX Number: $variable14</p>";

echo "<p>Lodge Driving Directions: $variable15</p>";

echo "<p>Lodge Lodge Meeting Time: $variable16</p>";

echo "<p>Lodge Lodge Meal Time: $variable17</p>";

echo "<p>Lodge Floor School: $variable18</p>";

echo "<p>Lodge News: $variable19</p>";

echo "<img src='{$row['link']}'>";

echo "</center>\n";

echo ("</tr>");

}

 

//query details table begins

 

 

echo "<center>\n";

echo "<H2>Roster of Lodge Officers</H2>\n";

echo "<table border='1'>

  <tr>

<th>Officer Title</th>

<th>Officer First</th>

<th>Officer Last</th>

<th>Officer Email</th>

<th>Officer Phone</th>

 

</tr>";

 

$query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.strDistrictName, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMailingAddress, a.strLodgeMailingAddress2, a.strLodgeMailingCity, a.strLodgeMailingStateCode, a.strLodgeMailingPostCode, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error());

if (mysql_num_rows($query)) {

while ($row = mysql_fetch_array($query)){

$variable20=$row["strOfficerTitle"];

$variable21=$row["strFirstName"];

$variable22=$row["strLastName"];

$variable23=$row["PersEmail"];

$variable24=$row["BusinessPhone"];

 

//table layout for results

 

print ("<tr>");

echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n";

echo "<td class=\"td_id\">$variable20</td>\n";

echo "<td class=\"td_id\">$variable21</td>\n";

echo "<td class=\"td_id\">$variable22</td>\n";

echo "<td class=\"td_id\">$variable23</td>\n";

echo "<td class=\"td_id\">$variable24</td>\n";

print ("</tr>");

}

}

?>

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.