SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting images.. but from the wrong folder?

    Hi all

    I have the code below which selects my images and displays them from the selected folder.

    folders:

    /thumbs/290907 - the old version
    /thumbs/venue290907 - the new version

    PHP Code:
    echo ....<img src="thumbs/' . $row['venue_id'] . '' .$row['subdir'] .'/'. $row['photo_id'] . '.jpg" title="Views: ' . $row['views'] . '">'; 

    the full code:

    Which should select /thumbs/venue290907 - the new version but still selects the old version /thumbs/290907

    PHP Code:
    $date mysql_real_escape_string($_GET['date']);
        
    $venue_id mysql_real_escape_string($_GET['venue_id']);
        
    $event_id mysql_real_escape_string($_GET['event_id']);
        
    $sql "SELECT photo_id, DATE_FORMAT(date, '%d%m%y') AS subdir, views, caption FROM photos 
        WHERE (event_id='
    $event_id' AND date='$date')
        OR (venue_id='
    $venue_id' AND date='$date')
        OR (event_id='
    $event_id' AND venue_id='$venue_id' AND date='$date')";
        
    $result = @mysql_query($sql) or die('Error: ' mysql_error());
        for (
    $i 0$row mysql_fetch_array ($result); $i++) {
        if((
    $i != 0) and (($i 8) == 0))
        echo
    '<p></p>';
        echo 
    '<a href="photo/' $row['photo_id'] . '" class="thumb"><img src="thumbs/' $row['venue_id'] . '' .$row['subdir'] .'/'$row['photo_id'] . '.jpg" title="Views: ' $row['views'] . '"></a>';
        } 
    what am i doing wrong?

    Thanks

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    is there definately a venue being pulled from the database as I cant see the field in your query.......

    (as in you havent selected venue_id from the database to then use in the link..)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks spike this is the page receiving the query the venue_id has already been sent from another page thats why I have the $venue_id = mysql_real_escape_string($_GET['venue_id']); etc or do I need to select the venue aswell?

    Thanks

    UPDATE SELECT .., venue_id, aswell you mean?

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    well the $row['venue_id'] would look for the venue_id coming from the database so if you wanted to use the incoming variable it should be:
    PHP Code:
     echo '<a href="photo/' $row['photo_id'] . '" class="thumb"><img src="thumbs/' $venue_id '' .$row['subdir'] .'/'$row['photo_id'] . '.jpg" title="Views: ' $row['views'] . '"></a>'
    or select it from the database
    SELECT .., venue_id, aswell you mean?
    exactly
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you have validated that $venue_id has been received by the page and is of the correct form, then there's no need to retrieve it from the database. That said, if it's a $_GET variable then you might first want to check that the requested file folder actually exists. (You may be doing this already - it's not shown in your code snippet).

    FWIW ... is the last OR clause in the query not redundant? If you find the event and date, or venue and date, then checking for event and venue and date is pointless as you will have already caught the data row by one of the previous checks.
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Guys

    yes spike, the incoming variable thats what I thought! we all ready have the data so whats the point increasing database read time and increasing memory requirements to store the result? Correct? Wouldn't that be the same for date then? I just need to format the date in the subdir format to work correctly.. ../thumbs/.. or just leave it like it is?

    siteguru, thanks
    FWIW ... is the last OR clause in the query not redundant? If you find the event and date, or venue and date, then checking for event and venue and date is pointless as you will have already caught the data row by one of the previous checks.
    I suppose it is redundant, but I need to cover all the possible query's being passed over from the other page to this page, including:

    event/date, venue/date, event/venue/date

    I thought once a match has been made, then the other conditions get ignored?

    Or is there a better way? event, venue, event/venue will always have the date(if that helps).

    PHP Code:
    $date mysql_real_escape_string($_GET['date']);
        
    $venue_id mysql_real_escape_string($_GET['venue_id']);
        
    $event_id mysql_real_escape_string($_GET['event_id']);
        
    $sql "SELECT photo_id, DATE_FORMAT(date, '%d%m%y') AS subdir, views, caption FROM photos 
        WHERE (event_id='
    $event_id' AND date='$date')
        OR (venue_id='
    $venue_id' AND date='$date')
        OR (event_id='
    $event_id' AND venue_id='$venue_id' AND date='$date')";
        
    $result = @mysql_query($sql) or die('Error: ' mysql_error());
        for (
    $i 0$row mysql_fetch_array ($result); $i++) {
        if((
    $i != 0) and (($i 8) == 0))
        echo
    '<p></p>';
        echo 
    '<a href="photo/' $row['photo_id'] . '" class="thumb"><img src="thumbs/' $venue_id '' .$row['subdir'] .'/'$row['photo_id'] . '.jpg" title="Views: ' $row['views'] . '"></a>';
        } 
    Cheers

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    ... WHERE (event_id='$event_id' OR venue_id='$venue_id') AND date='$date'
    That should do the same thing and cover all the bases.
    Ian Anderson
    www.siteguru.co.uk

  8. #8
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks siteguru

    So that will cover:

    /event/date
    /venue/date
    event/venue/date

    My main concern would be event/venue getting selected together, would that still work even though a OR is in between? I thought AND was needed to select both? Or can both variables get selected here with out any problem just with OR?

    Thanks just trying to understand this properly here.. cheers

  9. #9
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    My suggestion should be the same as ...

    Code:
    ... WHERE 
    (event_id='$event_id' AND date='$date') OR 
    (venue_id='$venue_id' AND date='$date')
    A check for all 3 parameters is not necessary as if all 3 exist then that row will have been captured by both of the previous checks. (This does NOT mean the same row will be returned twice! The data you get in the recordset will be correct).

    Edit: here's a logic table that should hopefully help you understand what's happening with the query ... a * means there is data in that field in the database table.

    Code:
    Event   Venue   Date   Match?
      *               *      Y
      *       *       *      Y
      *       *              N
              *       *      Y
                             N
      *       *       *      Y
      *       *              N
      *       *       *      Y
      *       *       *      Y
      *               *      Y
      *       *       *      Y
      *       *       *      Y
              *       *      Y
      *       *              N
      *       *       *      Y
      *       *       *      Y
                      *      N
      *       *       *      Y
              *              N
      *       *       *      Y
    Ian Anderson
    www.siteguru.co.uk

  10. #10
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers siteguru, great example thanks

    I understand now what your saying, all making sense cheers..

    Ok 2 more things:

    1. as I mention to spike at the top of post 6 about the date and GET?

    2. because I'll be selecting different images from different folders depending on the query, how will I combat the -
    PHP Code:
    thumbs/' . $event_id . ''. $venue_id . '' .$row['subdir'] .'
    ' it currently works if no event is present and selects all the thumbnails from the venue and date, but I was just wondering will I need some sort of condition to select the right folders when needed, or will this one be ok and just ignore the NULL values when it needs to?

    PHP Code:
    require_once('includes/mysql_connect.inc.php');
        
    $date mysql_real_escape_string($_GET['date']);
        
    $venue_id mysql_real_escape_string($_GET['venue_id']);
        
    $event_id mysql_real_escape_string($_GET['event_id']);
        
    $sql "SELECT photo_id, DATE_FORMAT(date, '%d%m%y') AS subdir, views, caption FROM photos 
        WHERE (event_id='
    $event_id' OR venue_id='$venue_id') AND date='$date'";
        
    $result = @mysql_query($sql) or die('Error: ' mysql_error());
        for (
    $i 0$row mysql_fetch_array ($result); $i++) {
        if((
    $i != 0) and (($i 8) == 0))
        echo
    '<p></p>';
        echo 
    '<a href="photo/' $row['photo_id'] . '" class="thumb"><img src="thumbs/' $event_id ''$venue_id '' .$row['subdir'] .'/'$row['photo_id'] . '.jpg" title="Views: ' $row['views'] . '"></a>';
        } 
    Cheers
    Last edited by computerbarry; Oct 27, 2007 at 08:47.


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
  •