Forum Moderators: coopster

Message Too Old, No Replies

img src within a php statement?

         

weeevil

11:14 am on Mar 12, 2007 (gmt 0)

10+ Year Member



I have a database with 2 boolean fields, and i want an image to display in the repeat region table if the value in that table is 1.

At the moment, they're being displayed regardless, and the extra space that both images are taking up in dreamweaver makes it that the gap between the entries in the rows are huge.

<?php if ($totalRows_RSResultsClassic > 0)
{ // Show if recordset not empty?>
<img src="images/classic.gif" width="50" height="25">
<?php if ($totalRows_RSResultsNew > 0)
{ // Show if recordset not empty?>
<img src="images/hot.gif" width="50" height="25">
<?php } // Show if recordset not empty?>
<?php } // Show if recordset not empty?>

I've tried different logics ( == 1 <> 0 etc.) but nothing seems to be working.

Any help would be grand!

Scally_Ally

11:20 am on Mar 12, 2007 (gmt 0)

10+ Year Member



Can you show us how you are setting the variables

$totalRows_RSResultsClassic

and

$totalRows_RSResultsNew

Ally

weeevil

11:31 am on Mar 12, 2007 (gmt 0)

10+ Year Member



You mean the SQL statement?

SELECT *
FROM films
WHERE NewReleases = '1'

SELECT *
FROM films
WHERE Classic = '1'

weeevil

11:33 am on Mar 12, 2007 (gmt 0)

10+ Year Member



the statement inside the php code is:

mysql_select_db($database_concord, $concord);
$query_RSResultsClassic = "SELECT * FROM films WHERE Classic = '1'";
$RSResultsClassic = mysql_query($query_RSResultsClassic, $concord) or die(mysql_error());
$row_RSResultsClassic = mysql_fetch_assoc($RSResultsClassic);
$totalRows_RSResultsClassic = mysql_num_rows($RSResultsClassic);

mysql_select_db($database_concord, $concord);
$query_RSResultsNew = "SELECT * FROM films WHERE NewReleases = '1'";
$RSResultsNew = mysql_query($query_RSResultsNew, $concord) or die(mysql_error());
$row_RSResultsNew = mysql_fetch_assoc($RSResultsNew);
$totalRows_RSResultsNew = mysql_num_rows($RSResultsNew);

Scally_Ally

12:26 pm on Mar 12, 2007 (gmt 0)

10+ Year Member



That is because both record sets have more than 1 row, so both if statements are being satisfied.

try something like

<?php if($row_RSResultsClassic["classic"]==1){?>

<img src="images/classic.gif" width="50" height="25">

<?php }?>

This will check whether the row has a value of 1, not whether the query has returned any rows.

Ally

weeevil

9:29 am on Mar 13, 2007 (gmt 0)

10+ Year Member



This seems to be eliminating the massive gaps, but now no images are being displayed.

I assume the SQL statement is correct? as it's pretty SQL 101, it's just not displaying the image

Scally_Ally

12:11 pm on Mar 13, 2007 (gmt 0)

10+ Year Member



You are returning an associative array with all the values from the relevant rows and columns.
Each of the array keys relates to your column titles in your database. Try looking to see if you are checking for the correct name.

The problem looks to be that you are checking for "classic" but should really be checking for "Classic"

Ally

weeevil

10:47 am on Mar 14, 2007 (gmt 0)

10+ Year Member



I have found the problem,

The capitalised name for Classic was one, and the repeat region was looking at a different record set, so i just used that recordset instead, thanks for the help!