SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    What is wrong with my Query?

    Code:
    function show_join() { 
    	//$result = mysql_query("SELECT * FROM Persons");
    	$userid = $this->session->userdata('user_id');
    	$result = $this->db->query("SELECT swap.swapid, swap.offering FROM swap, users_swap WHERE users_swap.user_id = '$userid' AND users_swap.swap_id = swap.swapid");
    		echo "<table border='1'>
    		<tr>
    			<th>swapid</th>
    			<th>offering</th>
    		</tr>";
    		
    		while($row = mysql_fetch_array($result))
    		  {
    			  echo "<tr>";
    			  echo "<td>" . $row['swap.swapid'] . "</td>";
    			  echo "<td>" . $row['swap.offering'] . "</td>";
    			  echo "</tr>";
    		  }
    		echo "</table>";
    }
    The error was,
    Code:
    Message: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
    ?

    tnx in advanced.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    that's a php error message which says that the query failed

    either that, or it returned no rows and you're trying to fetch those non-existing rows

    that's just a guess on my part, since i don't do php (this is the mysql forum)

    run the query outside of php, i.e. right in mysql, to see what it does
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    @r937

    I already tested it and the SELECT is fine.
    You are right it's PHP error.

    fixing...


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
  •