how to make query filtered

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eiwans
Forum Newbie
Posts: 4
Joined: Thu Mar 04, 2010 1:19 am

how to make query filtered

Post by eiwans »

Hi Guys, Im trying to list portfolio which only has large image, no error but i dont know where is my mistake.

<div id="slideshow">
<?php include('connection.php');
$dbtableSlide = "x_portfolio_db";
$querySlide = "SELECT * FROM $dbtableSlide WHERE imgLarge = true";
$resultSlide = mysql_query($querySlide);
if (!$resultSlide) {
echo "there was an problem";
} else {
$num_resultsSlide = mysql_num_rows($resultSlide);
}?>

<ul id="portfolio">
<?php for($i=0; $i < $num_resultsSlide; $i++) {
$row = mysql_fetch_array($resultSlide);?>
<li><a href="portfolio.php"><img src="<?php echo $row['imgLarge']?>" alt="Latest work" /></a></li>
<?php } ?>
</ul>
</div>

Thanks
Last edited by eiwans on Mon Apr 05, 2010 3:06 am, edited 1 time in total.
kasim.badami
Forum Newbie
Posts: 4
Joined: Wed Mar 24, 2010 5:50 am

Re: Loop only have large image

Post by kasim.badami »

Code: Select all

<ul id="portfolio">
<?php for($i=0; $i < $num_resultsSlide; $i++) {
$row = mysql_fetch_array($resultSlide);?>
<li><a href="portfolio.php"><img src="<?php echo $row['imgLarge']?>" alt="Latest work" /></a></li>
<?php } ?>
</ul>
</div>
Try mysql_fetch_assoc instead of mysql_fetch_array, this might solve your problem.
User avatar
Architek
Forum Commoner
Posts: 44
Joined: Wed Jul 01, 2009 5:01 am
Location: Portland OR

Re: how to make query filtered

Post by Architek »

does your sql return fine its just not being parsed out of the array correctly?

I might throw single quotes around the value of true like follows...

Code: Select all

$querySlide = "SELECT * FROM $dbtableSlide WHERE imgLarge = 'true'";
eiwans
Forum Newbie
Posts: 4
Joined: Thu Mar 04, 2010 1:19 am

Re: how to make query filtered

Post by eiwans »

When i
echo $resultSlide ---> 6
echo $num_resultsSlide ----> 0

dont understand...
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: how to make query filtered

Post by lunarnet76 »

just in case you should use

Code: Select all

while($row=mysql_fetch_array($resultSlide)){
?>	
<li><a href="portfolio.php"><img src="<?php echo $row['imgLarge']?>" alt="Latest work" /></a></li>
<?php
}
instead of

Code: Select all

for($i=0; $i < $num_resultsSlide; $i++) {
$row = mysql_fetch_array($resultSlide);?>	
<li><a href="portfolio.php"><img src="<?php echo $row['imgLarge']?>" alt="Latest work" /></a></li>
<?php }
but otherwise your code works so it must code from your

Code: Select all

$querySlide = "SELECT * FROM $dbtableSlide WHERE imgLarge = 'true'";
or from a stupid mistake like a wrong field name : imgLarge instead of imglarge, the database is case insensitive, but php is!
User avatar
Architek
Forum Commoner
Posts: 44
Joined: Wed Jul 01, 2009 5:01 am
Location: Portland OR

Re: how to make query filtered

Post by Architek »

I know many times I have returned picture variables but forgot to state a folder path for the src

<img src="images/<?php echo $row['imgLarge']?>" alt="Latest work" />
eiwans
Forum Newbie
Posts: 4
Joined: Thu Mar 04, 2010 1:19 am

Re: how to make query filtered

Post by eiwans »

Still no luck :(, Its brings up 6 files (correct) but the file path comes up blank.

http://dl.dropbox.com/u/2527203/Screen% ... 202010.png
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: how to make query filtered

Post by lunarnet76 »

do a print_r($row), what does it gives you!?
Post Reply