Forums
This topic is locked
Update Record If Statement
18 Apr 2007 00:27:26 Gaz B posted:
Dear ForumI hope someone may be able to help me with something, what i'm trying to develop is a small publications application using PHP/MySQL, I have created the Insert Record successfully, and am now trying to set up a system whereby users can amend a record if necessary. I have a search form which displays a limited results page with only a few fields - where I need help is depending on the type of publication depends which page is opened displaying data on the form.
So basically if a publication value is A then user is taken to page1.php, if publication is B then user is taken to page2.php and so on - I have 5 publication values.. (the reason for this is the user has different fields to complete depending upon the publication).
This is all new to me, and am pleased with what I have achieved so far, just need some support, so any help would be greatfully received.
Many thanks is advance
Gaz
Replies
Replied 20 Apr 2007 20:29:27
20 Apr 2007 20:29:27 Alan C replied:
HI
as you would expect there are lots of ways to go about this . . .
a conditional if elseif
if publication_type == 'a' {
}
elseif publication_type =='b' {
}
elseif publication_type =='c'{
}
etc
a switch on publication type - that may would allow you to share some of the common coding
or different pages altogether for each of the publication types - that way you can easily change one without interfering with the others, but . . . if a lot of the coding is common you could end up with 5 very similar forms to maintain.
On balance I think I would go with one page that had conditional statements for the particular fields that were special for that publication
Hope that helps - you'll probably get different views from other people <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
as you would expect there are lots of ways to go about this . . .
a conditional if elseif
if publication_type == 'a' {
}
elseif publication_type =='b' {
}
elseif publication_type =='c'{
}
etc
a switch on publication type - that may would allow you to share some of the common coding
or different pages altogether for each of the publication types - that way you can easily change one without interfering with the others, but . . . if a lot of the coding is common you could end up with 5 very similar forms to maintain.
On balance I think I would go with one page that had conditional statements for the particular fields that were special for that publication
Hope that helps - you'll probably get different views from other people <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replied 23 Apr 2007 22:26:26
23 Apr 2007 22:26:26 Gaz B replied:
Hi Alan
Many thanks for responding to my post, I have tried doing the If Else If condition but for some reason it doesn't seem to work, maybe its the way i've done it, I have pasted my code below to see if anyone has any ideas.
I like the sound of the one page with conditions, but to be honest would not know where to begin, any help/examples would be greatfully received.
Thanks
Gaz
*****
<body>
<h1>Publication Search Results</h1>
<?php do { ?>
<p><?php echo $row_rs_pubsearch['PubID']; ?> / <?php echo $row_rs_pubsearch['pubtype']; ?> / <?php echo $row_rs_pubsearch['pubyear']; ?><br>
<?php echo $row_rs_pubsearch['title']; ?><br>
<?php echo $row_rs_pubsearch['authors']; ?><br>
<?php if ($row_rs_pubsearch['pubtype'] == "journal" {
<a href="journal_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "book" {
<a href="book_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "chapter" {
<a href="chapter_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "report" {
<a href="report_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else {
<a href="paper_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
}
?>
<a href="journal_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>
<?php } while ($row_rs_pubsearch = mysql_fetch_assoc($rs_pubsearch)); ?>
<p> </p>
</body>
Many thanks for responding to my post, I have tried doing the If Else If condition but for some reason it doesn't seem to work, maybe its the way i've done it, I have pasted my code below to see if anyone has any ideas.
I like the sound of the one page with conditions, but to be honest would not know where to begin, any help/examples would be greatfully received.
Thanks
Gaz
*****
<body>
<h1>Publication Search Results</h1>
<?php do { ?>
<p><?php echo $row_rs_pubsearch['PubID']; ?> / <?php echo $row_rs_pubsearch['pubtype']; ?> / <?php echo $row_rs_pubsearch['pubyear']; ?><br>
<?php echo $row_rs_pubsearch['title']; ?><br>
<?php echo $row_rs_pubsearch['authors']; ?><br>
<?php if ($row_rs_pubsearch['pubtype'] == "journal" {
<a href="journal_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "book" {
<a href="book_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "chapter" {
<a href="chapter_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "report" {
<a href="report_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else {
<a href="paper_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
}
?>
<a href="journal_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>
<?php } while ($row_rs_pubsearch = mysql_fetch_assoc($rs_pubsearch)); ?>
<p> </p>
</body>
Replied 01 May 2007 17:45:38
01 May 2007 17:45:38 Alan C replied:
I can't see anything obvious wrong with that code, it's doing the right things - what you might try is putting in an echo statement to see what is being done, then you can monitor what is going on. Also look at the url line as you move your mouse over the links to see if there is anything being shown - sorry if I'm telling you things you already do <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
perhaps something like this . . .
<pre id=code><font face=courier size=2 id=code>
<?php do { ?>
<p><?php echo $row_rs_pubsearch['PubID']; ?> / <?php echo $row_rs_pubsearch['pubtype']; ?> / <?php echo $row_rs_pubsearch['pubyear']; ?><br>
<?php echo $row_rs_pubsearch['title']; ?><br>
<?php echo $row_rs_pubsearch['authors']; ?><br>
echo '$row_rs_pubsearch['pubtype'] : '.$row_rs_pubsearch['pubtype'].'<br />'; // that will tell you the pubtype
<?php if ($row_rs_pubsearch['pubtype'] == "journal" {
<a href="journal_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "book" {
<a href="book_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "chapter" {</font id=code></pre id=code>
that might help to see just what's going on, here's one that I know works and does something similar, setting up a link
<pre id=code><font face=courier size=2 id=code> <a href="/mgt_area/updater2.php?p_id=<?php echo $one_time; // ?>"><?php echo $row_rsPropertiesIManage['p_name']; ?></a></font id=code></pre id=code>
perhaps something like this . . .
<pre id=code><font face=courier size=2 id=code>
<?php do { ?>
<p><?php echo $row_rs_pubsearch['PubID']; ?> / <?php echo $row_rs_pubsearch['pubtype']; ?> / <?php echo $row_rs_pubsearch['pubyear']; ?><br>
<?php echo $row_rs_pubsearch['title']; ?><br>
<?php echo $row_rs_pubsearch['authors']; ?><br>
echo '$row_rs_pubsearch['pubtype'] : '.$row_rs_pubsearch['pubtype'].'<br />'; // that will tell you the pubtype
<?php if ($row_rs_pubsearch['pubtype'] == "journal" {
<a href="journal_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "book" {
<a href="book_edit.php?recordID=<?php echo $row_rs_pubsearch['PubID']; ?>">Edit Publication</a>;
} else if ($row_rs_pubsearch['pubtype'] == "chapter" {</font id=code></pre id=code>
that might help to see just what's going on, here's one that I know works and does something similar, setting up a link
<pre id=code><font face=courier size=2 id=code> <a href="/mgt_area/updater2.php?p_id=<?php echo $one_time; // ?>"><?php echo $row_rsPropertiesIManage['p_name']; ?></a></font id=code></pre id=code>