Jump to content

php sql help


simun

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.