Forums

PHP

This topic is locked

Update Record If Statement

Posted 18 Apr 2007 00:27:26
1
has voted
18 Apr 2007 00:27:26 Gaz B posted:
Dear Forum

I 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>
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

*****

&lt;body&gt;

&lt;h1&gt;Publication Search Results&lt;/h1&gt;
&lt;?php do { ?&gt;
&lt;p&gt;&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt; / &lt;?php echo $row_rs_pubsearch['pubtype']; ?&gt; / &lt;?php echo $row_rs_pubsearch['pubyear']; ?&gt;&lt;br&gt;
&lt;?php echo $row_rs_pubsearch['title']; ?&gt;&lt;br&gt;
&lt;?php echo $row_rs_pubsearch['authors']; ?&gt;&lt;br&gt;
&lt;?php if ($row_rs_pubsearch['pubtype'] == "journal" {
&lt;a href="journal_edit.php?recordID=&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt;"&gt;Edit Publication&lt;/a&gt;;
} else if ($row_rs_pubsearch['pubtype'] == "book" {
&lt;a href="book_edit.php?recordID=&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt;"&gt;Edit Publication&lt;/a&gt;;
} else if ($row_rs_pubsearch['pubtype'] == "chapter" {
&lt;a href="chapter_edit.php?recordID=&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt;"&gt;Edit Publication&lt;/a&gt;;
} else if ($row_rs_pubsearch['pubtype'] == "report" {
&lt;a href="report_edit.php?recordID=&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt;"&gt;Edit Publication&lt;/a&gt;;
} else {
&lt;a href="paper_edit.php?recordID=&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt;"&gt;Edit Publication&lt;/a&gt;;
}
?&gt;
&lt;a href="journal_edit.php?recordID=&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt;"&gt;Edit Publication&lt;/a&gt;
&lt;?php } while ($row_rs_pubsearch = mysql_fetch_assoc($rs_pubsearch)); ?&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;/body&gt;
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>
&lt;?php do { ?&gt;
&lt;p&gt;&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt; / &lt;?php echo $row_rs_pubsearch['pubtype']; ?&gt; / &lt;?php echo $row_rs_pubsearch['pubyear']; ?&gt;&lt;br&gt;
&lt;?php echo $row_rs_pubsearch['title']; ?&gt;&lt;br&gt;
&lt;?php echo $row_rs_pubsearch['authors']; ?&gt;&lt;br&gt;

echo '$row_rs_pubsearch['pubtype'] : '.$row_rs_pubsearch['pubtype'].'&lt;br /&gt;'; // that will tell you the pubtype

&lt;?php if ($row_rs_pubsearch['pubtype'] == "journal" {
&lt;a href="journal_edit.php?recordID=&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt;"&gt;Edit Publication&lt;/a&gt;;
} else if ($row_rs_pubsearch['pubtype'] == "book" {
&lt;a href="book_edit.php?recordID=&lt;?php echo $row_rs_pubsearch['PubID']; ?&gt;"&gt;Edit Publication&lt;/a&gt;;
} 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> &lt;a href="/mgt_area/updater2.php?p_id=&lt;?php echo $one_time; // ?&gt;"&gt;&lt;?php echo $row_rsPropertiesIManage['p_name']; ?&gt;&lt;/a&gt;</font id=code></pre id=code>

Reply to this topic