How do I Use operators in MYSQL or What did I do Wrong Using them?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Evans
    New Member
    • Nov 2010
    • 9

    #1

    How do I Use operators in MYSQL or What did I do Wrong Using them?

    I have been creating a photo database and am now on the backend. I have written a back end that allows the user to grab photos from a certain time frame.

    When I get to the page that displays those photos, the if statements and loops work but the query does not. I have checked the mysql page for using greater and less than signs and AND and did so correctly.


    My error is Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in C://XXXX.php on line 58

    Basically, I am thinking the problem is that the query is not working as it should. The categories in my database match with date, year; month used in the queries. Could someone tell me what is wrong?

    The Code is Below. I appreciate all and any help. Thanks.

    Code:
    <?php
    session_start();
    ?>
    <html>
    <body>
    <?php
    if(isset($_session['user']));
    {
    function edit()
    {
    
    }
    
    function delete()
    {
    
    }
    
    $category=$_POST['timestamp'];
    $server=//myserver;
    $user= //myuser;
    $password= //mypass;
    $db=mysql_connect($server,$user,$password);
    mysql_select_db("admin_pictures",$db);
    echo "<table name='results'>";
    echo "<tr>";
    $d=1;
    $a=3;
    $l=0;
    $query='NAN';
    $qyears='NAN';
    $day=date('z');
    $difdays=$day-$category;
    $year=date('Y');
    $month=date('m');
    
    if($category != 'month')
    {
    if($difdays > 0)
    {
    $query="SELECT * FROM admin_pictures WHERE date < '$difdays' AND year = '$year'";
    }
    else if($difdays < 1)
    {
    $query="SELECT * FROM admin_pictures WHERE date < 30 AND year = '$year'";
    }
    $qyears="SELECT * FROM admin_pictures WHERE year = '$year'";
    }
    
    else if($category == 'month')
    {
    $query="SELECT * FROM admin_pictures WHERE month = '$month'";
    }
    
    if($query !='NAN')
    {
    $res=mysql_query($query);
    $check=mysql_num_rows($res);
    
    for($i=0;$i<$nums;$i++)
    {
    $l=$l+1;
    if($l==6)
    {
    $l=0;
    echo "</tr>";
    echo "<tr>";
    }
    $mrow=mysql_fetch_assoc($check);
    $picture=$mrow['image'];
    $id=$mrow['image_id'];
    list($width,$height)=getimagesize($picture);
    $ratio=$width/180;
    $width=$width/$ratio;
    $height=$height/$ratio;
    echo "<td>";
    echo "<center>";
    echo "<img src=$picture alt=$id height=$height width=$width/>";
    echo "<br />";
    echo "<input type='checkbox' value=$id name='boxes' />";
    echo "<br />";
    echo "</center>";
    echo "</td>";
    }
    
    if($qyears != 'NAN')
    {
    $res=mysql_query($qyears);
    $check=mysql_num_rows($res);
    
    for($i=0;$i<$nums;$i++)
    {
    $l=$l+1;
    if($l==6)
    {
    $l=0;
    echo "</tr>";
    echo "<tr>";
    }
    $mrow=mysql_fetch_assoc($res);
    $picture=$mrow['image'];
    $id=$mrow['image_id'];
    list($width,$height)=getimagesize($picture);
    $ratio=$width/180;
    $width=$width/$ratio;
    $height=$height/$ratio;
    echo "<td>";
    echo "<center>";
    echo "<img src=$picture alt=$id height=$height width=$width/>";
    echo "<br />";
    echo "<input type='checkbox' value=$id name='boxes' />";
    echo "<br />";
    echo "</center>";
    echo "</td>";
    }
    }
    }
    }
    ?>
    </body>
    </html>
    Again thanks. Let me know if you need anything else.
    Last edited by Scott Evans; Dec 30 '10, 01:09 AM. Reason: probably not enough information
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Add the following after immediately after you call mysql_query() and it should give you some insight.
    Code:
    echo mysql_error();

    Comment

    • Scott Evans
      New Member
      • Nov 2010
      • 9

      #3
      thanks i'll try that

      Comment

      Working...