Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Here's the code:Code: Select all
if ( $links == "Operating Systems" ){ $result=mysql_query ( "select * FROM Links WHERE LinkType = 'Operating Systems'" ); while ($row = mysql_fetch_array($result)){ printf (nl2br("<a class="red" href="http://$rowї3]" target="_blank">$rowї2]</a><p>$rowї4]</p><br>")); } } if ( $links == "Small Business Links" ){ $result=mysql_query ( "select * FROM Links WHERE LinkType = ('Small Business Links') AND (LinkShowHide = Hide)" ); while ($row = mysql_fetch_array($result)) { printf (nl2br("<a class="red" href="http://$rowї3]" target="_blank">$rowї2]</a><p>$rowї4]</p><br>")); } }
fetch array error when using logical operators
Moderator: General Moderators
fetch array error when using logical operators
I'm having some issues with a bit of code that you folks might be able to help me with. When I use the logical operator AND to retrieve rows with mysql_fetch_array it throws an exception. I'm enclosing two examples, one with the AND operator, and one without. The one without works fine, the one with the operator fails. The error I get is
try
Code: Select all
$query = "select * FROM Links WHERE LinkType='Small Business Links' AND LinkShowHide= 'Hide'";
$result=mysql_query($query) or die($query.' :'.mysql_error());- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Hi, I've played with your code a little and ended up with this which you might like to try:
I put the SQL statements into their own variables so that they can be echoed out in order to check for errors. I've added some error handling to the mysql_query() call using or die statements and mysql_error(). The problem was most likely with the way you had used parenthesis in the second SQL statement:
I've changed it so it now looks like this:
Finally I changed the printf() call to echo() which would be more appropriate for what you are trying to do.
Mac
Edit: meant to post this before I went to my meeting and managed to preview it instead so here it is an hour or so later, sort of expanding on what volka said.
Code: Select all
<?php
if ($links == 'Operating Systems') {
$sql = "SELECT * FROM Links WHERE LinkType = 'Operating Systems'";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql'</p>');
while ($row = mysql_fetch_array($result)) {
echo '<a class="red" href="http://'.$row[3].'" target="_blank">'.$row[2].'</a><p>'.nl2br($row[4]).'</p><br>';
}
}
if ($links == 'Small Business Links') {
$sql = "SELECT * FROM Links WHERE LinkType = 'Small Business Links' AND LinkShowHide = 'Hide'";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql'</p>');
while ($row = mysql_fetch_array($result)) {
echo '<a class="red" href="http://'.$row[3].'" target="_blank">'.$row[2].'</a><p>'.nl2br($row[4]).'</p><br>';
}
}
?>Code: Select all
select * FROM Links WHERE LinkType = ('Small Business Links') AND (LinkShowHide = Hide)Code: Select all
SELECT * FROM Links WHERE LinkType = 'Small Business Links' AND LinkShowHide = 'Hide'Mac
Edit: meant to post this before I went to my meeting and managed to preview it instead so here it is an hour or so later, sort of expanding on what volka said.