SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A little help with PHP

    I've been doing a simple project for school but is is giving me this error:

    Code:
    ( ! ) Warning: mysql_result() expects parameter 1 to be resource, object given in C:\wamp\www\Bugs\Viewdata.php on line 43 
    Call Stack 
    # Time Memory Function Location 
    1 0.0008 379496 {main}( ) ..\Viewdata.php:0 
    2 0.0038 389728 mysql_result ( ) ..\Viewdata.php:43
    Here is the code:

    Code:
    <?php
    $dbc = mysqli_connect('localhost', 'root', '', 'bugsdb') 
        or die('Error connecting to MySQL server.');
    
    $query="SELECT * FROM bugs"
    	or die('Query to select all failed');
    	
    $result = mysqli_query($dbc, $query)
    	or die ('Result failed');
    	
    
    $num = mysqli_num_rows ($result)
    	or die ('numrows failed');
    	echo "Total records in Student table = ". $num;
    
    ?>
    
    <table border="1" cellspacing="6" cellpadding="2">
    <tr>
    <th><font face="Arial, Helvetica, sans-serif">Product ID</font></th>
    <th><font face="Arial, Helvetica, sans-serif">Procuct Name</font></th>
    <th><font face="Arial, Helvetica, sans-serif">Product Version</font></th>
    <th><font face="Arial, Helvetica, sans-serif"></font>Operating System</th>
    <th><font face="Arial, Helvetica, sans-serif">How Often does it Occur</font></th>
    <th><font face="Arial, Helvetica, sans-serif">Solution</font></th>
    <th><font face="Arial, Helvetica, sans-serif">Hardware</font></th>
    </tr>
    
    <?php
    $i=0;
    while ($i < $num) {
    
    $f1=mysql_result($result,$i,"field1");
    $f2=mysql_result($result,$i,"field2");
    $f3=mysql_result($result,$i,"field3");
    $f4=mysql_result($result,$i,"field4");
    $f5=mysql_result($result,$i,"field5");
    $f6=mysql_result($result,$i,"field6");
    $f7=mysql_result($result,$i,"field7");
    It seems that my $result is coming in with a wrong output, but the number of rows code seems to work fine. Any ideas?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    As you are using mysqli, should it not be:

    mysqli_result($result,$i,"field1");

  3. #3
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    As you are using mysqli, should it not be:

    mysqli_result($result,$i,"field1");
    Thank you for the fast reply.

    I have tried that before and got this error:

    Code:
    ( ! ) Fatal error: Call to undefined function mysqli_result() in C:\wamp\www\Bugs\Viewdata.php on line 43 
    Call Stack 
    # Time Memory Function Location 
    1 0.1841 380336 {main}( ) ..\Viewdata.php:0


    I am really lost...

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_result does not have an exact counterpart in "mysqli" so mysqli_result is not a valid function. You may use mysqli_fetch_field but I prefer to use the following:

    PHP Code:
        $row mysqli_fetch_array($result);

        
    $name $row['name'];
        
    $email $row['email'];
        
    $phone1 $row['phone1'];

        
    etc......... 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •