elsewhile equivelant?

Hi,

I have a problem that got ZERO response in the “general help” section, so I’m posting it here, as this seems like a small problem.

I have an image gallery that should first check the “feature” column in the db, in order to show featured images first. But, after retrieving feature images (or if there are none), I want the code to continue collecting the remaining images in the gallery (that are not marked as feature - blank field).

I have constructed two $sql queries, one for each:[php]
//gather featured items if avail
$fsql = “SELECT * FROM sale_items WHERE gallery_name = ‘cutting_edge_name’ AND feature != ‘’ ORDER BY feature ASC LIMIT $startRow,”.GALMAX; //GALMAX set to limit results per page
$fresult = mysql_query($sql) or die(‘Problem attaining feature items’);
//then get the remaining images
$sql = “SELECT * FROM sale_items WHERE gallery_name = ‘cutting_edge_name’ AND feature = ‘’ ORDER BY image_id ASC LIMIT $startRow,”.GALMAX;
$result = mysql_query($sql) or die(‘Problem attaining sale items’);
[/php]

My problem is in not knowing exactly how to display the results in a flowing manner. I want to use the following code - which is intended to display only one set of results, and the first result at that, using $row. My question is, what’s the best way for me display a $row[‘filename’] result from the second $sql statement, if the first one is empty?
[php]//display image on click, or get first result from db if !$_GET
if (isset($_GET[‘image’])) {
$mainImage = $_GET[‘image’];
}
else {
$mainImage = $row[‘filename’]; //THIS VALUE IS WHERE I NEED TO DISPLAYONE VAL OR THE OTHER
}[/php]

My first question to you is why you have two different queries that basically do the same.
One gets the result with features and the other without.
Now you want when there is no feature you get the image_id.
if you just select the whole table and loop over it and then check the conditions?

[PHP]
$sql = “SELECT * FROM sale_items WHERE gallery_name = ‘cutting_edge_name’ ORDER BY image_id ASC LIMIT $startRow,”.GALMAX;
$result = mysql_query($sql) or die(‘Problem attaining sale items’);
while($row = mysql_fetch_assoc($result)) {
if($row[‘feature’] == ‘’) {
// do your feature stuff here
}
else {
//do your image_id stuff here
}
}
[/PHP]
p.s.
You have a small mistake by getting $sql instead of $fsql in your first query :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service