simun Posted May 19, 2009 Share Posted May 19, 2009 this script shows some news from mysql, i try to put limit 5 in query but it still show onley one news, please can someone help me? <?php $posebna_ponuda = $db->query("SELECT id FROM objects WHERE posebna_ponuda = 1 ORDER BY RAND() LIMIT 5"); if (is_array($posebna_ponuda)) { $posebna_ponuda_object = new S_Object($posebna_ponuda[0]['id']); $posebna_ponuda_object->gallery->getPhotos(); if (is_array($posebna_ponuda_object->gallery->photos)) { $main_photo_key = 1; foreach($posebna_ponuda_object->gallery->photos as $photoKey => $photo) { if ($photo['fields']['main']) { $main_photo_key = $photoKey; break; } } $photo = $posebna_ponuda_object->gallery->photos[$main_photo_key]; } foreach($__constants as $c => $constant) { if ($constant['database']['value'] == $posebna_ponuda_object->type) { $posebna_ponuda_object->link = $constant['link'][$__language]; break; } } ?> <div id="izdvojeno"> <?php if (is_array($photo)) { ?> <div style="border: none; border-width:0px;padding-top: 10px;"> <a href="/<?=$__language?>/<?=$posebna_ponuda_object->link?>/<?=$posebna_ponuda_object->id?>"><? ?><img style="border: #cccccc 1px solid; margin-right: 5px;" border="0px" alt="" src="/images/cache/objects/<?=$posebna_ponuda_object->id?>/<?=$photo['filename']?>/w-90.jpg" align="left" /><? ?></a> </div> <?php } ?> <a href="/<?=$__language?>/<?=$posebna_ponuda_object->link?>/<?=$posebna_ponuda_object->id?>" class="stylep"><?php echo substr($posebna_ponuda_object->{'opis_' . $__language},0,100)?></a> <div class="clear"></div> </div> <?php } ?> </div> Quote Link to comment Share on other sites More sharing options...
lordshoa Posted May 26, 2009 Share Posted May 26, 2009 What happens when you select everything ? $posebna_ponuda = $db->query("SELECT * FROM objects WHERE posebna_ponuda = "1" ORDER BY RAND() LIMIT 5"); Quote Link to comment Share on other sites More sharing options...
stevenheller7@gmail.com Posted June 4, 2009 Share Posted June 4, 2009 $posebna_ponuda = $db->query("SELECT id FROM objects WHERE posebna_ponuda = '1' ORDER BY RAND() LIMIT 5"); maybe try single quotes around the one. (I'm not a pro just an idea) (could be wrong) Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 You don't need quotes around numbers. Can you run this SQL for me? My guess is that you want to select 5 results, but only one has posebna_ponuda = 1. SELECT COUNT(*) FROM objects WHERE posebna_ponuda = 1; What does that SQL output? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.