SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I've done much more complicated things than this, what am I missing?

    I'm working on a super simple database and php script. The problem is I can't get it to work!
    I keep getting this error "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Library/Tenon/WebServer/WebSites/www.ABCAdvertising.net/abcadmin/dcloset.php on line 28", line 28 is "while ($row_shorts = mysql_fetch_assoc($result_shorts))".

    Here is the php page(just trying to get the shorts column to work right now).
    Code:
    <?PHP
    include('include/user_check.php');
    include('include/db_con.php');	
    ?>
    	 
     <html>
     <head>
     <title>D Closet</title>
     </head>
     <body>
     <table>
     <tr>
     <th colspan="2">SHORTS</th><th colspan="2">JEANS</th><th colspan="2">POLOS</th><th colspan="2">T-Shirts</th>
     </tr>
     <tr>
     <th>Amount</th><th>Color</th><th>Amount</th><th>Color</th><th>Amount</th><th>Color</th><th>Amount</th><th>Color</th>
     </tr>
    
    <?PHP
    $query = "SELECT type FROM dc";
     	$result_query = mysql_query($query);
    * 	while ($row_query = mysql_fetch_assoc($result_query))
     	{
     	$type = $row_query['type'];
    	}
    	$shorts = "SELECT color, number FROM dc WHERE '$type' = shorts";
    		$result_shorts = mysql_query($shorts);
    		while ($row_shorts = mysql_fetch_assoc($result_shorts))
    		{
    		$number_shorts = $row_shorts['number'];
    		$color_shorts = $row_shorts['color'];	
    	?>
     <tr>
     <td><?=$number_shorts; ?></td><td><?=$color_shorts; ?></td><td><?=$number_jeans; ?></td><td><?=$color_jeans; ?></td><td><?=$number_polos; ?></td><td><?=$color_polos; ?></td><td><?=$number_tshirts; ?></td><td><?=$color_tshirts; ?></td>
     </tr>
     <?PHP
     }
     ?>
     </table>
     </body>
     </html>
    Here is what the entire database table looks like

    type____color____number
    shorts__blue_____2
    jeans___black___3
    polos___white____4
    tshirts__green____1

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    The query is failing, add to your query line:
    PHP Code:
    $result_query mysql_query($query) or die(mysql_error()); 
    see what the message is.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still around then?

  4. #4
    SitePoint Zealot CalebMingle's Avatar
    Join Date
    Jul 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like spikeZ said add that and post us what the message is.

    Try this:

    PHP Code:
    $shorts "SELECT color, number FROM dc WHERE $type='shorts'"
    :: Caleb Mingle (@dentafrice)
    :: PHP Developer.
    :: g+: http://gplus.to/mingle

  5. #5
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when I do that i get this error"Unknown column 'shorts' in 'where clause'"

    so i changed it to this
    Code:
    <?PHP
    $query = "SELECT * FROM dc";
     	$result_query = mysql_query($query) or die(mysql_error());
      	while ($row_query = mysql_fetch_array($result_query))
     	{
     	$type = $row_query['type'];
    
    	$shorts = "SELECT * FROM dc WHERE '$type' = type";
    		$result_shorts = mysql_query($shorts) or die(mysql_error());
    		while ($row_shorts = mysql_fetch_assoc($result_shorts))
    		{
    		$number_shorts = $row_shorts['number'];
    		$color_shorts = $row_shorts['color'];
    		}	
    	?>
     <tr>
     <td><?=$number_shorts; ?></td><td><?=$color_shorts; ?></td><td><?=$number_jeans; ?></td><td><?=$color_jeans; ?></td><td><?=$number_polos; ?></td><td><?=$color_polos; ?></td><td><?=$number_tshirts; ?></td><td><?=$color_tshirts; ?></td>
     </tr>
     <?PHP
     }
     ?>
    now my page displays without any errors but it displays everything not just the shorts data
    Attached Images Attached Images

  6. #6
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i should have explained my pic
    2 blue shorts----1 black jeans----3 white polos----4 green tshirts

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I think I get where you are going.....
    PHP Code:
    $query "SELECT type FROM dc";
         
    $result_query mysql_query($query);
         
    $row_query mysql_fetch_assoc($result_query);
     
         
    $type $row_query['type'];

        
    $shorts "SELECT color, number FROM dc WHERE "$type ." = 'shorts'";
            
    $result_shorts mysql_query($shorts);
            while (
    $row_shorts mysql_fetch_assoc($result_shorts))
            {
            
    $number_shorts $row_shorts['number'];
            
    $color_shorts $row_shorts['color'];
                          } 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this
    Code:
    <?PHP
    $query = "SELECT type FROM dc";
     	$result_query = mysql_query($query) or die(mysql_error());
     	while ($row_query = mysql_fetch_array($result_query))
     	{
     	$type = $row_query['type'];
    /////////////////////////////just for show	
    	echo $type;
    ////////////////////////////end just for show	
    	if( $type == "shorts" )
    	{
    		//$shorts = "SELECT * FROM dc WHERE type='$type' GROUP BY type";
    		$shorts = "SELECT color, number FROM dc WHERE ". $type ." = 'shorts'";
    			$result_shorts = mysql_query($shorts) or die(mysql_error());
    			while ($row_shorts = mysql_fetch_assoc($result_shorts))
    			{
    			$number_shorts = $row_shorts['number'];
    			$color_shorts = $row_shorts['color'];
    			}
    	}
    ?>
     <tr>
     <td><?=$number_shorts; ?></td><td><?=$color_shorts; ?></td>
    gets me pic 2

    what i want is this

    ____SHORTS__________JEANS__________POLOS_________T-SHIRTS___
    numbS__colorS____numbJ__colorJ____numbP__colorP____numbT__colorT
    Attached Images Attached Images

  9. #9
    SitePoint Zealot CalebMingle's Avatar
    Join Date
    Jul 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why can't you do this:

    PHP Code:
    $shorts "SELECT * FROM dc WHERE "$type ."='shorts'";
    $result_shorts mysql_query($shorts);
    while(
    $row_shorts mysql_fetch_array($results_shorts))
    {
    $number_shorst $row_shorts['number'];
    $color_shorts $row_shorts['color'];

    Sorry thats messy code, I coded it in the quick reply box
    :: Caleb Mingle (@dentafrice)
    :: PHP Developer.
    :: g+: http://gplus.to/mingle

  10. #10
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why that won't work

    Code:
    <?PHP
    $shorts = "SELECT * FROM dc WHERE ". $type ."='shorts'";
    $result_shorts = mysql_query($shorts);
    while($row_shorts = mysql_fetch_array($result_shorts))
    {
    $number_shorts = $row_shorts['number'];
    $color_shorts = $row_shorts['color'];
    }			
    ?>
    gets me this error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Library/Tenon/WebServer/WebSites/www.website.net/admin/dcloset.php on line 22"

    lines 21 -23 are
    Code:
    $result_shorts = mysql_query($shorts);
    while($row_shorts = mysql_fetch_array($result_shorts))
    {

  11. #11
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually was just looking for a php db class yesterday, and I found this great class that is really easy to use:

    http://www.tgreer.com/class_db_php.html

    It even includes a super simple way to setup up caching for result sets. You can access individual cell values with drop dead easy syntax:
    Code:
    echo $data[row_number]['column_name'];
    You should check it out. I had it up and running in less than 10 mins and I am not the greatest at oop at all.

  12. #12
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks wow, I'll check it out

    in the mean time, myguess (codewalkers) solved it
    thanks everyone for helping

    Code:
    <?PHP
    include('include/user_check.php');
    include('include/db_con.php');	
    ?>
    
     <html>
     <head>
     <title>D Closet</title>
     </head>
     <body>
     <table>
     <tr>
     <th colspan="2">SHORTS</th><th colspan="2">JEANS</th><th colspan="2">POLOS</th><th colspan="2">T-Shirts</th>
     </tr>
     <tr>
     <th>Amount</th><th>Color</th><th>Amount</th><th>Color</th><th>Amount</th><th>Color</th><th>Amount</th><th>Color</th>
     </tr>
     <tr>
    <?PHP
    $query = "SELECT type FROM dc";
     	$result_query = mysql_query($query);
     	
     
    
    	while ($row_query = mysql_fetch_assoc($result_query))
     	{
     	         $type = $row_query['type']; 	
    	
    	        $shorts = "SELECT color, number FROM dc WHERE type = '$type'";
    		$result_shorts = mysql_query($shorts);
    		while ($row_shorts = mysql_fetch_assoc($result_shorts))
    		{
    				
    		$number = $row_shorts['number'];
    		$color = $row_shorts['color'];			
    		
    		print "<td>$number </td><td>$color</td>";
    		}
    	}
     ?>
     </tr>
     </table>
     </body>
     </html>


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
  •