1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Resource id # 3 Error

Discussion in 'PHP' started by sash11, Feb 20, 2010.

  1. #1
    <?php

    if (isset($_REQUEST['submit'])) {
    echo "<p> hello</p>";

    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'shshsh11';

    mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

    $dbname = 'Studentt';
    mysql_select_db($dbname);
    $result = mysql_query("SELECT * FROM `allele`");
    print $result;





    } else {

    ?>

    <html>

    <body>

    <form action="wcode.php" method=POST>

    <P><strong>Available Queries</strong><br>

    <INPUT TYPE="radio" NAME="Microsatellite Primers">Microsatellite Primers<br>
    <INPUT TYPE="radio" NAME="Maps">Maps for specified loci, possibly on a specified chromosome<br>
    <INPUT TYPE="radio" NAME="Common loci">Loci in common between two maps<br>
    <INPUT TYPE="radio" NAME="Loci">Loci on more than 4 maps<br>

    <P><P><P><input name=submit type=submit value=submit>

    </form>

    </body>

    </html>

    <?php

    }

    ?>




    it gives following result

    hello
    Resource id #3

    what is Resource id #3
    how do we solve it?
    please help
     
    sash11, Feb 20, 2010 IP
  2. insert

    insert Peon

    Messages:
    148
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can't just print query object, you must loop it with for example mysql_fetch_assoc or mysql_fetch_obect...
     
    insert, Feb 20, 2010 IP
  3. skywebsol

    skywebsol Active Member

    Messages:
    161
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    $result = mysql_query("SELECT * FROM `allele`");
    $row=mysql_fetch_array($result);
    print_r($row); //print array
    echo $row['table field name']; // print field data
     
    skywebsol, Feb 20, 2010 IP
  4. Silver89

    Silver89 Well-Known Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    145
    #4
    You must loop through the rows, you could this this with:

    Replace:
    
    print $result;
    
    PHP:
    With

    
    while($row=mysql_fetch_row($result))
    {
          echo $row[0];
    }
    
    PHP:
    Also I think you just posted your php/mysql password .... might want to remove that ;)
     
    Silver89, Feb 20, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    Or better, change it.
     
    danx10, Feb 20, 2010 IP
  6. Silver89

    Silver89 Well-Known Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    145
    #6
    Don't think that's really necessary as he has 1 post at the site and doesn't mention any external urls?
     
    Silver89, Feb 20, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    True - but always good to be on the safe side. :)
     
    danx10, Feb 20, 2010 IP
  8. sash11

    sash11 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks a lot for your help. will try it all out. and yes i mentioned the changed password :p
     
    sash11, Feb 21, 2010 IP