What I'm attempting is to have database driven links on my page. It is all ok except one thing and that is this error when my page comes up in the browser.


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/admin/public_html/index.php on line 114

Here is my code.

<html> 

<head> 

<style>

.root_td 
{ 

background-color: #000000; 

color: #FFCF00; 

font-family: Verdana; 

font-size: 8pt; 

font-weight: bold; 

height: 22; 

padding-left: 5; 

}

.child_td 

{ 

background-color: #D1D1D1; 

color: #000000; 

font-family: Verdana; 

font-size: 8pt; 

font-weight: bold; 

text-decoration: underline; 

height: 22; 

padding-left: 10; 

padding-right: 10; 

padding-bottom: 3; 

} 


body 

{ 

color: #000000; 

font-family: Verdana; 

font-size: 8pt; 

font-weight: normal; 

} 

a 

{ 

color: #000000; 

}

</style>

<script language="JavaScript">
function ShowLink(linkObject, imgObject) 
{ 

if(linkObject.style.display == '' || linkObject.style.display == 'inline') 
{ 

linkObject.style.display = 'none'; 

imgObject.src = 'plus.gif'; 

} 

else 

{ 

linkObject.style.display = 'inline'; 

imgObject.src = 'minus.gif'; 

} 

}

</script>

</head> 

<body bgcolor="#FFFFFF">

<table width="250" border="0" cellspacing="0" cellpadding="0"> 

<?php 
while($link = mysql_fetch_array($linkResult)) 

{ 

?>

<tr> 

<td class="root_td">
<img id="img_root_<?php echo $counter; ?>" onClick="ShowLink(td_root_<?php echo $counter; ?>, img_root_<?php echo $counter; ?>)" border="0" src="minus.gif" style="cursor:hand">

<?php echo $node[1]; ?>

</td> 

</tr> 

<tr> 

<td id="td_root_<?php echo $counter++; ?>" class="child_td"> 

<table width="100%">

<?php 



$sql = "select * from links where parentId = {$link[0]} order by title asc"; 
@$childResult = mysql_query($sql); 

while($child = mysql_fetch_row($childResult)) 

{ 

?> 

<tr> 

<td class="child_td"> 

<a href="<?php echo $child[2]; ?>"> 

<?php echo $child[1]; ?> 

</a> 

</td> 

</tr>

<?php 

} 

?>

</table> 

</td> 

</tr> 

<?php 

} 

?> 



</table>

</body> 

</html>

Any suggestions? Thanks

you first need to connect to the database first, place the following anywhere before anyof your database queries

$db = mysql_connect("localhost", $user, $pass) or die ("could not establish a database connection");
mysql_select_db($database, $db) or die ("could not access database");

if you will only have 1 active database connection then you could just use the following:

mysql_connect("localhost", $user, $pass) or die ("could not establish a database connection");
mysql_select_db($database) or die ("could not access database");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.