simun Posted May 19, 2009 Share Posted May 19, 2009 helo, im trying to get some data from my sql base, but i cant get more then one 'news' heres my code <?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 style="padding: 14px;"> <?php if (is_array($photo)) { ?> <div> <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 } ?> anyone can help???? Link to comment https://forums.phpfreaks.com/topic/158716-php-sql-help/ Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 You need to use a while loop so as to loop through the rows contained in the MySQL resource result link. That is: $query = mysql_query("SELECT id FROM objects WHERE posebna_ponuda = 1 ORDER BY RAND() LIMIT 5"); while($row = mysql_fetch_assoc($query)){ //do whatever you'd like with each row of "news" -- $row contains an array containing 'id' -- $row['id'] } Link to comment https://forums.phpfreaks.com/topic/158716-php-sql-help/#findComment-837056 Share on other sites More sharing options...
simun Posted May 19, 2009 Author Share Posted May 19, 2009 thx for quick reply, but im a newbie in php, can u please insert your modification im my code tchanks Link to comment https://forums.phpfreaks.com/topic/158716-php-sql-help/#findComment-837060 Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 thanks for quick reply, but im a newbie in php, can u please insert your modification im my code tchanks I'd rather not. Link to comment https://forums.phpfreaks.com/topic/158716-php-sql-help/#findComment-837062 Share on other sites More sharing options...
simun Posted May 19, 2009 Author Share Posted May 19, 2009 ??? i tryed to include your sugestion in my code but nothing shows now :-\ Link to comment https://forums.phpfreaks.com/topic/158716-php-sql-help/#findComment-837070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.