resource id #4 Why am I getting this?












4















I have a pretty basic forum template I am working on for testing purposes



When I create a topic, and press submit, the proccess updates the database but doesn't output on the screen. Why is this? and Why am I getting a Resource id #4 when I echo the $result from this code below:



<?php

$host="server"; // Host name
$username="usernamehere"; // Mysql username
$password=""; // Mysql password
$db_name="forum"; // Database name
$tbl_name="question"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending

$result=mysql_query($sql);
echo $result;
?>
<html>
<body>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>

<?php

// Start looping table row
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
</tr>

<?php
// Exit looping and close connection
}
mysql_close();
?>

<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
</tr>
</table>
</body>
</html>









share|improve this question

























  • because that's what $result is, a resource.

    – user557846
    Nov 2 '12 at 5:26








  • 1





    Just remove echo $result

    – Svetoslav
    Nov 2 '12 at 5:27











  • shouldn't the while loop take care of the resource #4 error? and if I just remove the echo $result..I'm still left with my data not being displayed in the table..

    – noob123
    Nov 2 '12 at 6:07
















4















I have a pretty basic forum template I am working on for testing purposes



When I create a topic, and press submit, the proccess updates the database but doesn't output on the screen. Why is this? and Why am I getting a Resource id #4 when I echo the $result from this code below:



<?php

$host="server"; // Host name
$username="usernamehere"; // Mysql username
$password=""; // Mysql password
$db_name="forum"; // Database name
$tbl_name="question"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending

$result=mysql_query($sql);
echo $result;
?>
<html>
<body>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>

<?php

// Start looping table row
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
</tr>

<?php
// Exit looping and close connection
}
mysql_close();
?>

<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
</tr>
</table>
</body>
</html>









share|improve this question

























  • because that's what $result is, a resource.

    – user557846
    Nov 2 '12 at 5:26








  • 1





    Just remove echo $result

    – Svetoslav
    Nov 2 '12 at 5:27











  • shouldn't the while loop take care of the resource #4 error? and if I just remove the echo $result..I'm still left with my data not being displayed in the table..

    – noob123
    Nov 2 '12 at 6:07














4












4








4








I have a pretty basic forum template I am working on for testing purposes



When I create a topic, and press submit, the proccess updates the database but doesn't output on the screen. Why is this? and Why am I getting a Resource id #4 when I echo the $result from this code below:



<?php

$host="server"; // Host name
$username="usernamehere"; // Mysql username
$password=""; // Mysql password
$db_name="forum"; // Database name
$tbl_name="question"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending

$result=mysql_query($sql);
echo $result;
?>
<html>
<body>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>

<?php

// Start looping table row
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
</tr>

<?php
// Exit looping and close connection
}
mysql_close();
?>

<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
</tr>
</table>
</body>
</html>









share|improve this question
















I have a pretty basic forum template I am working on for testing purposes



When I create a topic, and press submit, the proccess updates the database but doesn't output on the screen. Why is this? and Why am I getting a Resource id #4 when I echo the $result from this code below:



<?php

$host="server"; // Host name
$username="usernamehere"; // Mysql username
$password=""; // Mysql password
$db_name="forum"; // Database name
$tbl_name="question"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending

$result=mysql_query($sql);
echo $result;
?>
<html>
<body>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>

<?php

// Start looping table row
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
</tr>

<?php
// Exit looping and close connection
}
mysql_close();
?>

<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
</tr>
</table>
</body>
</html>






php mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 2 '12 at 5:41









Sami

5,20245084




5,20245084










asked Nov 2 '12 at 5:22









noob123noob123

23114




23114













  • because that's what $result is, a resource.

    – user557846
    Nov 2 '12 at 5:26








  • 1





    Just remove echo $result

    – Svetoslav
    Nov 2 '12 at 5:27











  • shouldn't the while loop take care of the resource #4 error? and if I just remove the echo $result..I'm still left with my data not being displayed in the table..

    – noob123
    Nov 2 '12 at 6:07



















  • because that's what $result is, a resource.

    – user557846
    Nov 2 '12 at 5:26








  • 1





    Just remove echo $result

    – Svetoslav
    Nov 2 '12 at 5:27











  • shouldn't the while loop take care of the resource #4 error? and if I just remove the echo $result..I'm still left with my data not being displayed in the table..

    – noob123
    Nov 2 '12 at 6:07

















because that's what $result is, a resource.

– user557846
Nov 2 '12 at 5:26







because that's what $result is, a resource.

– user557846
Nov 2 '12 at 5:26






1




1





Just remove echo $result

– Svetoslav
Nov 2 '12 at 5:27





Just remove echo $result

– Svetoslav
Nov 2 '12 at 5:27













shouldn't the while loop take care of the resource #4 error? and if I just remove the echo $result..I'm still left with my data not being displayed in the table..

– noob123
Nov 2 '12 at 6:07





shouldn't the while loop take care of the resource #4 error? and if I just remove the echo $result..I'm still left with my data not being displayed in the table..

– noob123
Nov 2 '12 at 6:07












5 Answers
5






active

oldest

votes


















9














You are getting resource id #4 because $result is an resource,you must extract the values contained in it by this way,



$result=mysql_query($sql);
$values = mysql_fetch_array($result);
var_dump($values);


More about resource variable



Update 2(From OP comments)



You are printing values using field name,In that case you will have to change to



while($rows=mysql_fetch_array($result,MYSQL_ASSOC))


Or you can directly use mysql_fetch_assoc(),which in your case will be



while($rows=mysql_fetch_assoc($result)){
echo $rows['id'];
}





share|improve this answer


























  • ok, my data shows in the var_dump but it won't show in the table in the above code. Why is this if the information is being passed?

    – noob123
    Nov 2 '12 at 5:45











  • have you enabled short tags on your server, replace <? with <?php and try

    – Sibu
    Nov 2 '12 at 5:49











  • I still get the same result..

    – noob123
    Nov 2 '12 at 6:31











  • @noob123 my mistake, i should have seen that earlier, check my updated answer

    – Sibu
    Nov 2 '12 at 6:40











  • I used the mysql_fetch_assoc in the code above but it doesnt work..I don't know what I'm doing wrong..

    – noob123
    Nov 2 '12 at 14:50



















4














Problem is in your code:



$result=mysql_query($sql);
echo $result;


$result is resource type, since mysql_query($sql) returns resource
Stop echoing $result.






share|improve this answer

































    2














    If you check the link - http://php.net/manual/en/function.mysql-query.php




    For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error




    Hence you are seeing the Resource#4



    . What is it you want to achieve?






    share|improve this answer
























    • I'm simply trying to output the data in the database into the table in the above code

      – noob123
      Nov 2 '12 at 5:40



















    0














    <?php

    $host="server";
    $username="usernamehere";
    $password="";
    $db_name="forum";
    $tbl_name="question";
    mysql_connect("$host", "$username", "")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
    // OREDER BY id DESC is order result by descending

    $result=mysql_query($sql);
    echo $result; //remove it
    ?>
    <html>
    <body>
    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
    <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
    <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
    <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
    <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
    </tr>

    <?php

    // Start looping table row
    while($rows=mysql_fetch_array($result)){

    echo"<tr>
    <td bgcolor=#FFFFFF>$rows['id']</td>
    <td bgcolor=#FFFFFF><a href='view_topic.php?id=$rows['id']'>$rows['topic']</a><BR></td>
    <td align=center bgcolor=#FFFFFF>$rows['view']</td>
    <td align=center bgcolor=#FFFFFF>$rows['reply']</td>
    <td align=center bgcolor=#FFFFFF>$rows['datetime'];</td>
    </tr>";


    // Exit looping and close connection
    }
    mysql_close();
    ?>

    <tr>
    <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
    </tr>
    </table>
    </body>
    </html>


    just check above code i think your problem should be done






    share|improve this answer

































      -2














      You don't have to use mysql_fetch_array(). If you want, try something like this:



      $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; //that's your query
      $result=mysql_query($sql);
      $rows=mysql_num_rows($result);
      $iteration=0;
      echo "<table>";

      while($iteration < $rows){
      $cell_in_your_html_table = mysql_result($result , $iteration , 'column_name_from_database');
      echo "<tr><td>".$cell_in_your_html_table."</td></tr>";
      $iteration++;
      }
      echo "</table>"





      share|improve this answer





















      • 1





        Welcome to Stack Overflow. Please use code block for your code snippet in answers. Please double check your answers (yours does clearly have a $num variable being null which make your code useless). Please use relevant and readable name for your variable (tada ? Is that the result of an magical trick ?). Please make sure you are actually replying the OP question.

        – b.enoit.be
        Apr 5 '15 at 23:23











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13189764%2fresource-id-4-why-am-i-getting-this%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9














      You are getting resource id #4 because $result is an resource,you must extract the values contained in it by this way,



      $result=mysql_query($sql);
      $values = mysql_fetch_array($result);
      var_dump($values);


      More about resource variable



      Update 2(From OP comments)



      You are printing values using field name,In that case you will have to change to



      while($rows=mysql_fetch_array($result,MYSQL_ASSOC))


      Or you can directly use mysql_fetch_assoc(),which in your case will be



      while($rows=mysql_fetch_assoc($result)){
      echo $rows['id'];
      }





      share|improve this answer


























      • ok, my data shows in the var_dump but it won't show in the table in the above code. Why is this if the information is being passed?

        – noob123
        Nov 2 '12 at 5:45











      • have you enabled short tags on your server, replace <? with <?php and try

        – Sibu
        Nov 2 '12 at 5:49











      • I still get the same result..

        – noob123
        Nov 2 '12 at 6:31











      • @noob123 my mistake, i should have seen that earlier, check my updated answer

        – Sibu
        Nov 2 '12 at 6:40











      • I used the mysql_fetch_assoc in the code above but it doesnt work..I don't know what I'm doing wrong..

        – noob123
        Nov 2 '12 at 14:50
















      9














      You are getting resource id #4 because $result is an resource,you must extract the values contained in it by this way,



      $result=mysql_query($sql);
      $values = mysql_fetch_array($result);
      var_dump($values);


      More about resource variable



      Update 2(From OP comments)



      You are printing values using field name,In that case you will have to change to



      while($rows=mysql_fetch_array($result,MYSQL_ASSOC))


      Or you can directly use mysql_fetch_assoc(),which in your case will be



      while($rows=mysql_fetch_assoc($result)){
      echo $rows['id'];
      }





      share|improve this answer


























      • ok, my data shows in the var_dump but it won't show in the table in the above code. Why is this if the information is being passed?

        – noob123
        Nov 2 '12 at 5:45











      • have you enabled short tags on your server, replace <? with <?php and try

        – Sibu
        Nov 2 '12 at 5:49











      • I still get the same result..

        – noob123
        Nov 2 '12 at 6:31











      • @noob123 my mistake, i should have seen that earlier, check my updated answer

        – Sibu
        Nov 2 '12 at 6:40











      • I used the mysql_fetch_assoc in the code above but it doesnt work..I don't know what I'm doing wrong..

        – noob123
        Nov 2 '12 at 14:50














      9












      9








      9







      You are getting resource id #4 because $result is an resource,you must extract the values contained in it by this way,



      $result=mysql_query($sql);
      $values = mysql_fetch_array($result);
      var_dump($values);


      More about resource variable



      Update 2(From OP comments)



      You are printing values using field name,In that case you will have to change to



      while($rows=mysql_fetch_array($result,MYSQL_ASSOC))


      Or you can directly use mysql_fetch_assoc(),which in your case will be



      while($rows=mysql_fetch_assoc($result)){
      echo $rows['id'];
      }





      share|improve this answer















      You are getting resource id #4 because $result is an resource,you must extract the values contained in it by this way,



      $result=mysql_query($sql);
      $values = mysql_fetch_array($result);
      var_dump($values);


      More about resource variable



      Update 2(From OP comments)



      You are printing values using field name,In that case you will have to change to



      while($rows=mysql_fetch_array($result,MYSQL_ASSOC))


      Or you can directly use mysql_fetch_assoc(),which in your case will be



      while($rows=mysql_fetch_assoc($result)){
      echo $rows['id'];
      }






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 2 '12 at 6:40

























      answered Nov 2 '12 at 5:25









      SibuSibu

      4,06211836




      4,06211836













      • ok, my data shows in the var_dump but it won't show in the table in the above code. Why is this if the information is being passed?

        – noob123
        Nov 2 '12 at 5:45











      • have you enabled short tags on your server, replace <? with <?php and try

        – Sibu
        Nov 2 '12 at 5:49











      • I still get the same result..

        – noob123
        Nov 2 '12 at 6:31











      • @noob123 my mistake, i should have seen that earlier, check my updated answer

        – Sibu
        Nov 2 '12 at 6:40











      • I used the mysql_fetch_assoc in the code above but it doesnt work..I don't know what I'm doing wrong..

        – noob123
        Nov 2 '12 at 14:50



















      • ok, my data shows in the var_dump but it won't show in the table in the above code. Why is this if the information is being passed?

        – noob123
        Nov 2 '12 at 5:45











      • have you enabled short tags on your server, replace <? with <?php and try

        – Sibu
        Nov 2 '12 at 5:49











      • I still get the same result..

        – noob123
        Nov 2 '12 at 6:31











      • @noob123 my mistake, i should have seen that earlier, check my updated answer

        – Sibu
        Nov 2 '12 at 6:40











      • I used the mysql_fetch_assoc in the code above but it doesnt work..I don't know what I'm doing wrong..

        – noob123
        Nov 2 '12 at 14:50

















      ok, my data shows in the var_dump but it won't show in the table in the above code. Why is this if the information is being passed?

      – noob123
      Nov 2 '12 at 5:45





      ok, my data shows in the var_dump but it won't show in the table in the above code. Why is this if the information is being passed?

      – noob123
      Nov 2 '12 at 5:45













      have you enabled short tags on your server, replace <? with <?php and try

      – Sibu
      Nov 2 '12 at 5:49





      have you enabled short tags on your server, replace <? with <?php and try

      – Sibu
      Nov 2 '12 at 5:49













      I still get the same result..

      – noob123
      Nov 2 '12 at 6:31





      I still get the same result..

      – noob123
      Nov 2 '12 at 6:31













      @noob123 my mistake, i should have seen that earlier, check my updated answer

      – Sibu
      Nov 2 '12 at 6:40





      @noob123 my mistake, i should have seen that earlier, check my updated answer

      – Sibu
      Nov 2 '12 at 6:40













      I used the mysql_fetch_assoc in the code above but it doesnt work..I don't know what I'm doing wrong..

      – noob123
      Nov 2 '12 at 14:50





      I used the mysql_fetch_assoc in the code above but it doesnt work..I don't know what I'm doing wrong..

      – noob123
      Nov 2 '12 at 14:50













      4














      Problem is in your code:



      $result=mysql_query($sql);
      echo $result;


      $result is resource type, since mysql_query($sql) returns resource
      Stop echoing $result.






      share|improve this answer






























        4














        Problem is in your code:



        $result=mysql_query($sql);
        echo $result;


        $result is resource type, since mysql_query($sql) returns resource
        Stop echoing $result.






        share|improve this answer




























          4












          4








          4







          Problem is in your code:



          $result=mysql_query($sql);
          echo $result;


          $result is resource type, since mysql_query($sql) returns resource
          Stop echoing $result.






          share|improve this answer















          Problem is in your code:



          $result=mysql_query($sql);
          echo $result;


          $result is resource type, since mysql_query($sql) returns resource
          Stop echoing $result.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 2 '12 at 5:38









          jogojapan

          54k977112




          54k977112










          answered Nov 2 '12 at 5:30









          ujjwalwahiujjwalwahi

          127313




          127313























              2














              If you check the link - http://php.net/manual/en/function.mysql-query.php




              For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error




              Hence you are seeing the Resource#4



              . What is it you want to achieve?






              share|improve this answer
























              • I'm simply trying to output the data in the database into the table in the above code

                – noob123
                Nov 2 '12 at 5:40
















              2














              If you check the link - http://php.net/manual/en/function.mysql-query.php




              For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error




              Hence you are seeing the Resource#4



              . What is it you want to achieve?






              share|improve this answer
























              • I'm simply trying to output the data in the database into the table in the above code

                – noob123
                Nov 2 '12 at 5:40














              2












              2








              2







              If you check the link - http://php.net/manual/en/function.mysql-query.php




              For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error




              Hence you are seeing the Resource#4



              . What is it you want to achieve?






              share|improve this answer













              If you check the link - http://php.net/manual/en/function.mysql-query.php




              For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error




              Hence you are seeing the Resource#4



              . What is it you want to achieve?







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 2 '12 at 5:28









              JoddyJoddy

              1,80511420




              1,80511420













              • I'm simply trying to output the data in the database into the table in the above code

                – noob123
                Nov 2 '12 at 5:40



















              • I'm simply trying to output the data in the database into the table in the above code

                – noob123
                Nov 2 '12 at 5:40

















              I'm simply trying to output the data in the database into the table in the above code

              – noob123
              Nov 2 '12 at 5:40





              I'm simply trying to output the data in the database into the table in the above code

              – noob123
              Nov 2 '12 at 5:40











              0














              <?php

              $host="server";
              $username="usernamehere";
              $password="";
              $db_name="forum";
              $tbl_name="question";
              mysql_connect("$host", "$username", "")or die("cannot connect");
              mysql_select_db("$db_name")or die("cannot select DB");
              $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
              // OREDER BY id DESC is order result by descending

              $result=mysql_query($sql);
              echo $result; //remove it
              ?>
              <html>
              <body>
              <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
              <tr>
              <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
              <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
              <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
              <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
              <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
              </tr>

              <?php

              // Start looping table row
              while($rows=mysql_fetch_array($result)){

              echo"<tr>
              <td bgcolor=#FFFFFF>$rows['id']</td>
              <td bgcolor=#FFFFFF><a href='view_topic.php?id=$rows['id']'>$rows['topic']</a><BR></td>
              <td align=center bgcolor=#FFFFFF>$rows['view']</td>
              <td align=center bgcolor=#FFFFFF>$rows['reply']</td>
              <td align=center bgcolor=#FFFFFF>$rows['datetime'];</td>
              </tr>";


              // Exit looping and close connection
              }
              mysql_close();
              ?>

              <tr>
              <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
              </tr>
              </table>
              </body>
              </html>


              just check above code i think your problem should be done






              share|improve this answer






























                0














                <?php

                $host="server";
                $username="usernamehere";
                $password="";
                $db_name="forum";
                $tbl_name="question";
                mysql_connect("$host", "$username", "")or die("cannot connect");
                mysql_select_db("$db_name")or die("cannot select DB");
                $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
                // OREDER BY id DESC is order result by descending

                $result=mysql_query($sql);
                echo $result; //remove it
                ?>
                <html>
                <body>
                <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
                <tr>
                <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
                <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
                <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
                <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
                <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
                </tr>

                <?php

                // Start looping table row
                while($rows=mysql_fetch_array($result)){

                echo"<tr>
                <td bgcolor=#FFFFFF>$rows['id']</td>
                <td bgcolor=#FFFFFF><a href='view_topic.php?id=$rows['id']'>$rows['topic']</a><BR></td>
                <td align=center bgcolor=#FFFFFF>$rows['view']</td>
                <td align=center bgcolor=#FFFFFF>$rows['reply']</td>
                <td align=center bgcolor=#FFFFFF>$rows['datetime'];</td>
                </tr>";


                // Exit looping and close connection
                }
                mysql_close();
                ?>

                <tr>
                <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
                </tr>
                </table>
                </body>
                </html>


                just check above code i think your problem should be done






                share|improve this answer




























                  0












                  0








                  0







                  <?php

                  $host="server";
                  $username="usernamehere";
                  $password="";
                  $db_name="forum";
                  $tbl_name="question";
                  mysql_connect("$host", "$username", "")or die("cannot connect");
                  mysql_select_db("$db_name")or die("cannot select DB");
                  $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
                  // OREDER BY id DESC is order result by descending

                  $result=mysql_query($sql);
                  echo $result; //remove it
                  ?>
                  <html>
                  <body>
                  <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
                  <tr>
                  <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
                  <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
                  <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
                  <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
                  <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
                  </tr>

                  <?php

                  // Start looping table row
                  while($rows=mysql_fetch_array($result)){

                  echo"<tr>
                  <td bgcolor=#FFFFFF>$rows['id']</td>
                  <td bgcolor=#FFFFFF><a href='view_topic.php?id=$rows['id']'>$rows['topic']</a><BR></td>
                  <td align=center bgcolor=#FFFFFF>$rows['view']</td>
                  <td align=center bgcolor=#FFFFFF>$rows['reply']</td>
                  <td align=center bgcolor=#FFFFFF>$rows['datetime'];</td>
                  </tr>";


                  // Exit looping and close connection
                  }
                  mysql_close();
                  ?>

                  <tr>
                  <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
                  </tr>
                  </table>
                  </body>
                  </html>


                  just check above code i think your problem should be done






                  share|improve this answer















                  <?php

                  $host="server";
                  $username="usernamehere";
                  $password="";
                  $db_name="forum";
                  $tbl_name="question";
                  mysql_connect("$host", "$username", "")or die("cannot connect");
                  mysql_select_db("$db_name")or die("cannot select DB");
                  $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
                  // OREDER BY id DESC is order result by descending

                  $result=mysql_query($sql);
                  echo $result; //remove it
                  ?>
                  <html>
                  <body>
                  <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
                  <tr>
                  <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
                  <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
                  <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
                  <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
                  <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
                  </tr>

                  <?php

                  // Start looping table row
                  while($rows=mysql_fetch_array($result)){

                  echo"<tr>
                  <td bgcolor=#FFFFFF>$rows['id']</td>
                  <td bgcolor=#FFFFFF><a href='view_topic.php?id=$rows['id']'>$rows['topic']</a><BR></td>
                  <td align=center bgcolor=#FFFFFF>$rows['view']</td>
                  <td align=center bgcolor=#FFFFFF>$rows['reply']</td>
                  <td align=center bgcolor=#FFFFFF>$rows['datetime'];</td>
                  </tr>";


                  // Exit looping and close connection
                  }
                  mysql_close();
                  ?>

                  <tr>
                  <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>
                  </tr>
                  </table>
                  </body>
                  </html>


                  just check above code i think your problem should be done







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 18 '17 at 11:39

























                  answered Aug 18 '17 at 11:11









                  Mustaqeem KhanMustaqeem Khan

                  11




                  11























                      -2














                      You don't have to use mysql_fetch_array(). If you want, try something like this:



                      $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; //that's your query
                      $result=mysql_query($sql);
                      $rows=mysql_num_rows($result);
                      $iteration=0;
                      echo "<table>";

                      while($iteration < $rows){
                      $cell_in_your_html_table = mysql_result($result , $iteration , 'column_name_from_database');
                      echo "<tr><td>".$cell_in_your_html_table."</td></tr>";
                      $iteration++;
                      }
                      echo "</table>"





                      share|improve this answer





















                      • 1





                        Welcome to Stack Overflow. Please use code block for your code snippet in answers. Please double check your answers (yours does clearly have a $num variable being null which make your code useless). Please use relevant and readable name for your variable (tada ? Is that the result of an magical trick ?). Please make sure you are actually replying the OP question.

                        – b.enoit.be
                        Apr 5 '15 at 23:23
















                      -2














                      You don't have to use mysql_fetch_array(). If you want, try something like this:



                      $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; //that's your query
                      $result=mysql_query($sql);
                      $rows=mysql_num_rows($result);
                      $iteration=0;
                      echo "<table>";

                      while($iteration < $rows){
                      $cell_in_your_html_table = mysql_result($result , $iteration , 'column_name_from_database');
                      echo "<tr><td>".$cell_in_your_html_table."</td></tr>";
                      $iteration++;
                      }
                      echo "</table>"





                      share|improve this answer





















                      • 1





                        Welcome to Stack Overflow. Please use code block for your code snippet in answers. Please double check your answers (yours does clearly have a $num variable being null which make your code useless). Please use relevant and readable name for your variable (tada ? Is that the result of an magical trick ?). Please make sure you are actually replying the OP question.

                        – b.enoit.be
                        Apr 5 '15 at 23:23














                      -2












                      -2








                      -2







                      You don't have to use mysql_fetch_array(). If you want, try something like this:



                      $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; //that's your query
                      $result=mysql_query($sql);
                      $rows=mysql_num_rows($result);
                      $iteration=0;
                      echo "<table>";

                      while($iteration < $rows){
                      $cell_in_your_html_table = mysql_result($result , $iteration , 'column_name_from_database');
                      echo "<tr><td>".$cell_in_your_html_table."</td></tr>";
                      $iteration++;
                      }
                      echo "</table>"





                      share|improve this answer















                      You don't have to use mysql_fetch_array(). If you want, try something like this:



                      $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; //that's your query
                      $result=mysql_query($sql);
                      $rows=mysql_num_rows($result);
                      $iteration=0;
                      echo "<table>";

                      while($iteration < $rows){
                      $cell_in_your_html_table = mysql_result($result , $iteration , 'column_name_from_database');
                      echo "<tr><td>".$cell_in_your_html_table."</td></tr>";
                      $iteration++;
                      }
                      echo "</table>"






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Apr 6 '15 at 16:22

























                      answered Apr 5 '15 at 23:02









                      oxy_moronoxy_moron

                      11




                      11








                      • 1





                        Welcome to Stack Overflow. Please use code block for your code snippet in answers. Please double check your answers (yours does clearly have a $num variable being null which make your code useless). Please use relevant and readable name for your variable (tada ? Is that the result of an magical trick ?). Please make sure you are actually replying the OP question.

                        – b.enoit.be
                        Apr 5 '15 at 23:23














                      • 1





                        Welcome to Stack Overflow. Please use code block for your code snippet in answers. Please double check your answers (yours does clearly have a $num variable being null which make your code useless). Please use relevant and readable name for your variable (tada ? Is that the result of an magical trick ?). Please make sure you are actually replying the OP question.

                        – b.enoit.be
                        Apr 5 '15 at 23:23








                      1




                      1





                      Welcome to Stack Overflow. Please use code block for your code snippet in answers. Please double check your answers (yours does clearly have a $num variable being null which make your code useless). Please use relevant and readable name for your variable (tada ? Is that the result of an magical trick ?). Please make sure you are actually replying the OP question.

                      – b.enoit.be
                      Apr 5 '15 at 23:23





                      Welcome to Stack Overflow. Please use code block for your code snippet in answers. Please double check your answers (yours does clearly have a $num variable being null which make your code useless). Please use relevant and readable name for your variable (tada ? Is that the result of an magical trick ?). Please make sure you are actually replying the OP question.

                      – b.enoit.be
                      Apr 5 '15 at 23:23


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13189764%2fresource-id-4-why-am-i-getting-this%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith