database driven link layout

Reply

Join Date: Feb 2005
Posts: 11
Reputation: supersonic is an unknown quantity at this point 
Solved Threads: 0
supersonic supersonic is offline Offline
Newbie Poster

database driven link layout

 
0
  #1
Feb 13th, 2005
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.

  1.  
  2. <html>
  3.  
  4. <head>
  5.  
  6. <style>
  7.  
  8. .root_td
  9. {
  10.  
  11. background-color: #000000;
  12.  
  13. color: #FFCF00;
  14.  
  15. font-family: Verdana;
  16.  
  17. font-size: 8pt;
  18.  
  19. font-weight: bold;
  20.  
  21. height: 22;
  22.  
  23. padding-LEFT: 5;
  24.  
  25. }
  26.  
  27. .child_td
  28.  
  29. {
  30.  
  31. background-color: #D1D1D1;
  32.  
  33. color: #000000;
  34.  
  35. font-family: Verdana;
  36.  
  37. font-size: 8pt;
  38.  
  39. font-weight: bold;
  40.  
  41. text-decoration: underline;
  42.  
  43. height: 22;
  44.  
  45. padding-LEFT: 10;
  46.  
  47. padding-RIGHT: 10;
  48.  
  49. padding-bottom: 3;
  50.  
  51. }
  52.  
  53.  
  54. body
  55.  
  56. {
  57.  
  58. color: #000000;
  59.  
  60. font-family: Verdana;
  61.  
  62. font-size: 8pt;
  63.  
  64. font-weight: normal;
  65.  
  66. }
  67.  
  68. a
  69.  
  70. {
  71.  
  72. color: #000000;
  73.  
  74. }
  75.  
  76. </style>
  77.  
  78. <script language="JavaScript">
  79. function ShowLink(linkObject, imgObject)
  80. {
  81.  
  82. if(linkObject.style.display == '' || linkObject.style.display == 'inline')
  83. {
  84.  
  85. linkObject.style.display = 'none';
  86.  
  87. imgObject.src = 'plus.gif';
  88.  
  89. }
  90.  
  91. ELSE
  92.  
  93. {
  94.  
  95. linkObject.style.display = 'inline';
  96.  
  97. imgObject.src = 'minus.gif';
  98.  
  99. }
  100.  
  101. }
  102.  
  103. </script>
  104.  
  105. </head>
  106.  
  107. <body bgcolor="#FFFFFF">
  108.  
  109. <table width="250" border="0" cellspacing="0" cellpadding="0">
  110.  
  111. <?php
  112. while($link = mysql_fetch_array($linkResult))
  113.  
  114. {
  115.  
  116. ?>
  117.  
  118. <tr>
  119.  
  120. <td class="root_td">
  121. <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">
  122.  
  123. <?php echo $node[1]; ?>
  124.  
  125. </td>
  126.  
  127. </tr>
  128.  
  129. <tr>
  130.  
  131. <td id="td_root_<?php echo $counter++; ?>" class="child_td">
  132.  
  133. <table width="100%">
  134.  
  135. <?php
  136.  
  137.  
  138.  
  139. $sql = "select * from links where parentId = {$link[0]} order by title asc";
  140. @$childResult = mysql_query($sql);
  141.  
  142. while($child = mysql_fetch_row($childResult))
  143.  
  144. {
  145.  
  146. ?>
  147.  
  148. <tr>
  149.  
  150. <td class="child_td">
  151.  
  152. <a href="<?php echo $child[2]; ?>">
  153.  
  154. <?php echo $child[1]; ?>
  155.  
  156. </a>
  157.  
  158. </td>
  159.  
  160. </tr>
  161.  
  162. <?php
  163.  
  164. }
  165.  
  166. ?>
  167.  
  168. </table>
  169.  
  170. </td>
  171.  
  172. </tr>
  173.  
  174. <?php
  175.  
  176. }
  177.  
  178. ?>
  179.  
  180.  
  181.  
  182. </table>
  183.  
  184. </body>
  185.  
  186. </html>

Any suggestions? Thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: database driven link layout

 
0
  #2
Feb 14th, 2005
you first need to connect to the database first, place the following anywhere before anyof your database queries


  1. $db = mysql_connect("localhost", $user, $pass) OR die ("could not establish a database connection");
  2. 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:
  1. mysql_connect("localhost", $user, $pass) OR die ("could not establish a database connection");
  2. mysql_select_db($database) OR die ("could not access database");
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC