473,799 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with if statement. Please help!

Hi there,

If you look at the code below, you will see that I am using a template
in order to display some photos on my website.
I also have "previous" and "next" buttons/link which increment the
PhotoId in my table so you can easily navigate.

I only have 35 rows in this particular table, but when you get to the
35th picture, clicking on next takes you to 36 which does not exist.
Same when you are on id 1 and click previous.

I am trying to prevent this with my poor excuse of an "if" statement,
but it doesn't seem to do the trick.

Please advise.

Regards,
Ciprian
<html>
<head>
<?php
$db = mysql_connect(" localhost","use r","pass");
mysql_select_db ("mydb",$db) ;
$request = "SELECT * FROM photos WHERE PhotoId=".$Phot oId;
$result = mysql_query ($request,$db);
$photos =mysql_fetch_ob ject($result);
mysql_free_resu lt($result);
?>
<title>Photos 2004 - <?php echo $photos->PhotoDesc ?> </title>
</head>

<body>
<table width="600" border="0" cellspacing="0" cellpadding="2"
align="center">
<tr>
<td align="center">
<img src="<?php echo $photos->PhotoFileNam e ?>" alt="<?php echo
$photos->PhotoDesc ?>" title="<?php echo $photos->PhotoDesc ?>"
border="0">
</td>
</tr>
<tr>
<td align='center'>
<?php echo $photos->PhotoDesc ?>
</td>
</tr>
<tr>
<td align='center'>
<a href='index.php ?PhotoId=<?php echo $photos->PhotoId-1
?>'>Previous</a> | <a href="index.php ?PhotoId=1">Ind ex</a> | <a
href='index.php ?PhotoId=<?php echo $photos->PhotoId+1 ?>'>Next</a>
</td>
</tr>
</table>
<?php
if (&PhotoId > 35)
print "1";
?>
</body>
</html>
Jul 17 '05 #1
6 1937
Ciprian Ilie wrote:
Hi there,

If you look at the code below, you will see that I am using a template
in order to display some photos on my website.
I also have "previous" and "next" buttons/link which increment the
PhotoId in my table so you can easily navigate.

I only have 35 rows in this particular table, but when you get to the
35th picture, clicking on next takes you to 36 which does not exist.
Same when you are on id 1 and click previous.

I am trying to prevent this with my poor excuse of an "if" statement,
but it doesn't seem to do the trick.

Please advise.

Regards,
Ciprian
<html>
<head>
<?php
$db = mysql_connect(" localhost","use r","pass");
mysql_select_db ("mydb",$db) ;
$request = "SELECT * FROM photos WHERE PhotoId=".$Phot oId;
$result = mysql_query ($request,$db);
$photos =mysql_fetch_ob ject($result);
mysql_free_resu lt($result);
?>
<title>Photo s 2004 - <?php echo $photos->PhotoDesc ?> </title>
</head>

<body>
<table width="600" border="0" cellspacing="0" cellpadding="2"
align="center">
<tr>
<td align="center">
<img src="<?php echo $photos->PhotoFileNam e ?>" alt="<?php echo
$photos->PhotoDesc ?>" title="<?php echo $photos->PhotoDesc ?>"
border="0">
</td>
</tr>
<tr>
<td align='center'>
<?php echo $photos->PhotoDesc ?>
</td>
</tr>


You have to put your if() inside the <tr> for navigation

<tr>
<td align='center'>
<?php
// print "Previous" link if PhotoID>1
if ($PhotoID>1) { ?>
<a href='index.php ?PhotoId=<?php echo $photos->PhotoId-1; ?>'>Previous</a>
<?php } ?>
| <a href="index.php ?PhotoId=1">Ind ex</a> |
<?php
// print "Next" link if PhotoID<35 (really should not be a constant here)
if ($PhotoID<35) { ?>
<a href='index.php ?PhotoId=<?php echo $photos->PhotoId+1 ?>'>Next</a>
<?php } ?>
</td>
</tr>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Hi Pedro,

Thanks a lot for your help, but it still does not look right.
The "previous" link is missing alltogether, regardless of the fact the
PhotoId is bigger than 1, and the "Next" link is always present even
if the PhotoId is 35 or 36 etc

Any advice? I could really do with getting this sorted

Regards,
Ciprian
Jul 17 '05 #3
Ciprian Ilie wrote:
The "previous" link is missing alltogether, regardless of the fact the
PhotoId is bigger than 1, and the "Next" link is always present even
if the PhotoId is 35 or 36 etc


Maybe there's some confusion here with 'standard' variables and
objects ???

is it $PhotoID or $Photo->PhotoID?
I'm not used to using objects. When I see too many '->' I get all
nervous. Maybe I said something that led you astray. If I did, I am
truly sorry.

Please repost your relevant code, and I'm sure you'll be helped to
understand why it doesn't work the way you want.
PS: don't assume we all know what this is about.
Keep some of the previous post (what is related to the new one)
to let us in on what you're talking about [I had to repull the
old posts to understand what you were talking about] :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #4
Try this modified code. Hope it will work (Not Tested)

As you are using PhotoId which i think will be a autoincrement field
so you can not rely on its continuity, as some rows might get deleted
with time.

So, you are required to fetch the previous and next ids from database.

There are better and more efficient solutions, which you can try, but
this is the easiest i guess.

[SNIP]

<html>
<head>
<?php
$db = mysql_connect(" localhost","use r","pass");
mysql_select_db ("mydb",$db) ;
$request = "SELECT PhotoId FROM photos WHERE PhotoId < '$PhotoId'
ORDER BY PhotoId DESC";
if($row =mysql_fetch_ob ject(mysql_quer y ($request,$db)) )
$prevId = $cntrow->PhotoId;
else
$prevId = '';

$request = "SELECT PhotoId FROM photos WHERE PhotoId > '$PhotoId'
ORDER BY PhotoId";
if($row =mysql_fetch_ob ject(mysql_quer y ($request,$db)) )
$nextId = $cntrow->PhotoId;
else
$nextId = '';

$request = "SELECT * FROM photos WHERE PhotoId=".$Phot oId;
$result = mysql_query ($request,$db);
$photos =mysql_fetch_ob ject($result);
mysql_free_resu lt($result);

?>
<title>Photos 2004 - <?php echo $photos->PhotoDesc ?> </title>
</head>

<body>
<table width="600" border="0" cellspacing="0" cellpadding="2"
align="center">
<tr>
<td align="center">
<img src="<?php echo $photos->PhotoFileNam e ?>" alt="<?php echo
$photos->PhotoDesc ?>" title="<?php echo $photos->PhotoDesc ?>"
border="0">
</td>
</tr>
<tr>
<td align='center'>
<?php echo $photos->PhotoDesc ?>
</td>
</tr>
<tr>
<td align='center'>
<?php
if(!empty($prev Id))
{
?>
<a href='index.php ?PhotoId=<?php echo $prevId?>'>Prev ious</a> |
<?
}
?>
<a href="index.php ?PhotoId=<?php echo $photos->PhotoId?>">Ind ex</a>
<?php
if(!empty($next Id))
{
?>
| <a href='index.php ?PhotoId=<?php echo $nextId?>'>Next </a>
<?
}
?>

</td>
</tr>
</table>
</body>
</html>

[/SNIP]
Pedro Graca <he****@hotpop. com> wrote in message news:<c0******* ******@ID-203069.news.uni-berlin.de>...
Ciprian Ilie wrote:
The "previous" link is missing alltogether, regardless of the fact the
PhotoId is bigger than 1, and the "Next" link is always present even
if the PhotoId is 35 or 36 etc


Maybe there's some confusion here with 'standard' variables and
objects ???

is it $PhotoID or $Photo->PhotoID?
I'm not used to using objects. When I see too many '->' I get all
nervous. Maybe I said something that led you astray. If I did, I am
truly sorry.

Please repost your relevant code, and I'm sure you'll be helped to
understand why it doesn't work the way you want.
PS: don't assume we all know what this is about.
Keep some of the previous post (what is related to the new one)
to let us in on what you're talking about [I had to repull the
old posts to understand what you were talking about] :)

Jul 17 '05 #5
Thanks again for all your help, but this does not work.
Would have liked to get some useful advise of where am I going wrong
rather than code which is not working and I haven't got a clue how to
debug

Cheers
Jul 17 '05 #6
Ciprian Ilie wrote:
Thanks again for all your help, but this does not work.
Would have liked to get some useful advise of where am I going wrong
rather than code which is not working and I haven't got a clue how to
debug


As I said before, you need to test for 1 and 35 individually right
before printing (or not) the 'Previous' and 'Next' link.

So, if you're at PhotoID 19 you want to display

<link to Photo 18> | <index> | <link to Photo 20>

but if you're viewing Photo 1 you want that to be

<index> | <link to Photo 2>

and similarly for Photo 35

<link to Photo 34> | <index>

It's easy to identify the parts that need special treatment, namely the
"<link to previous Photo> | " and the " | <link to next Photo>"
So your pseudo code could be something like

if (ok to print link to previous photo) print "<previous link> | "
print "<index>"
if (ok to print link to next photo) print " | <next link>"

Now you just have to come up with a working way of saying that in PHP :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5650
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their first name, last name, email, etc. The data are then sent to a PHP script (reg.php). The data are then inserted into a table (reg) in MS SQL server. I have declared the variables like this: if (!(isset($_POST))) { $FirstName = "" ;
2
8458
by: J.Bijleveld | last post by:
Hello colleagues, At this moment we have a real big problem using a .NET application with an Oracle database (v8.1.6). I hope someone has encountered this problem before and is able to help me with it. The problem is that we *Sometimes* get the ORA-24338 error when executing a query. This problem occurs random, sometimes twice a day, sometimes not at all. In the eventlog we get an exception like this one (stacktrace):
6
2575
by: Allan | last post by:
Please help, below is my problem. Let's say I have 2 tables, a Products table and a Colors table that go as follow: Table Products prodID Name 1 shirt 2 tshirt
7
11923
by: CharlesEF | last post by:
Hi All, I have run into another problem that is eating my lunch. Should be simple but I am having one heck of a time. Please look at this SELECT statement: SELECT FROM States WHERE ] = "US"; is the SQL column name (because it sarts with 2?). As the statement is shown I get the error message: Unclosed quotation mark before the character
10
3722
by: Chih-Hsu Yen | last post by:
I encountered a strange problem about switch-case statement. switch(cmd) { case 1: statements; break; case 2: statements; break; ... .... case 11: S1; S2; S3; statements;
2
1571
by: NITIN MUNJAL | last post by:
I am trying to implement a simple way to authenticate users before entering my webpage. I have two textboxes one each for username and password. On the button click I call the function authenticate() which is written below. It queries to an access database db.mdb which has 3 fields id, usernames and passwords. However this doesnt seem to work as I seem to get an exception always on the line maked by *** and the print statement in the catch...
4
5606
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" & request.form(strSerialNum) & "', " sql01 = sql01 & "Description = '" & request.form(strDesc) & "', " sql01 = sql01 & "Location = '" & request.form(strLoc) & "', "
5
2617
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import namespace="System.Data" %> <%@ import namespace="System.Data.SqlClient" %> <script language="c#" runat="server"> public void Page_Load(object sender, EventArgs e) {
0
1977
by: Filemaxor | last post by:
I have gotten my code to be able to allow people to add new text to a .txt document and able to call up files so the user can see whats in it. The problem i'm having is getting the for loop to work correctly so that i can allow certain indexes to be removed without completely deleting everything else. This is what i have so far. Code is below It's in the e part of the code and I have //remed the location of the for loop containg the...
9
1477
by: John | last post by:
Hello all. I am a PHP newbie and am having an issue using the && in an if statement. here is the code: if ($_REQUEST == "1" && date("Y-m-d") < $rowWork) { die("<h1>The earlybird special has ended.</h1>"); }
0
10259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.