Log in

View Full Version : how to differentiate rows



mtokoly
07-31-2009, 12:06 AM
after calling an array, how do i do different each row?

i would like to show the first image in the gallery and hide the other images


<?php
$query = "SELECT * FROM residential, res_images WHERE residential.id = $id AND prop_id = $id";
$result = @mysqli_query ($db, $query);
$num_rows = mysqli_num_rows($result);

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$path = "archive/res/$id";
$image_name = $row['image_name'];

if (blah blah) {
echo "<a href='$path/$image_name' rel='lightbox-test'><img src='$path/$image_name' width='140px' /></a>";
} else {
echo "<a href='$path/$image_name' rel='lightbox-test' class='hidden'></a>";
}
}

mysqli_free_result ($result);
mysqli_close($db);
?>

JShor
07-31-2009, 02:09 PM
Not too sure what you're looking to do,can you be more specific? From what I understood,you're trying to keep only the first image,and no other row results after that will have the image -- only data.

If that's the case,this should work for you:


<?php
$query = "SELECT * FROM residential, res_images WHERE residential.id = $id AND prop_id = $id";
$result = @mysqli_query ($db, $query);
$num_rows = mysqli_num_rows($result);

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$path = "archive/res/$id";
$image_name = $row['image_name'];

if ($firstImgCalled == 'true') {
echo "<a href='$path/$image_name' rel='lightbox-test'><img src='$path/$image_name' width='140px' /></a>";
} else {
echo "<a href='$path/$image_name' rel='lightbox-test' class='hidden'></a>";
}

$firstImgCalled = "true"; // this declaration will stop all other imgs from showing via the if...else statement.
}

mysqli_free_result ($result);
mysqli_close($db);
?>


HTH:)