Hi all,
Please excuse my limited technical knowledge of PHP, so far i have only
created PHP sites using Dreamweaver, i find know that i need features
outside of it's capabilities.
I am trying to create a 'related articles' selection page. The
administrator, after creating an article, can select older articles to
include on the final displayed page.
As the number of older articles increases, so will the number of
possible relataed articles, so i am making a dynamic checkbox as the
selection. This is all covered in Dreamweavers features, but, what i
then need to be able to do is create a new record in the
'related_articl es' table for each article selected when the form is
submitted.
I found this post below, which is more or less exactly what i want to
do, i just wasn't sure that this was php code, looks like asp. Would
someone be kind enough to show me how to change it to php code, or even
write the code for me? ANY help at all would be much appreciated. http://groups.google.ca/group/macrom...41afa2366e40e2
Thanks,
Gavin 7 14617 GJ*******@gmail .com wrote: I am trying to create a 'related articles' selection page. The administrator, after creating an article, can select older articles to include on the final displayed page.
Is this the best way to do it? You could generate a list of related
articles dynamically, based on article's publication date and topic
(which, of course, means that you need to keep track of topics in your
database).
As the number of older articles increases, so will the number of possible relataed articles, so i am making a dynamic checkbox as the selection. This is all covered in Dreamweavers features, but, what i then need to be able to do is create a new record in the 'related_articl es' table for each article selected when the form is submitted.
So what seems to be the problem? You receieve several ID numbers or
URLs via POST, and run one or more INSERT queries with this data.
I found this post below, which is more or less exactly what i want to do, i just wasn't sure that this was php code, looks like asp. Would someone be kind enough to show me how to change it to php code, or even write the code for me?
Well, so far you haven't even mentioned what database you are using...
Cheers,
NC
Hi,
Maybe i should re-phrase my question. I'm using php with a MySQL
database, and i would like to know how to insert a new record into a
table for each checked item on one form.
The reason i want to create a relation in this way, is because i want
to be able to choose which article appears as a related link regardless
of it's category/date/etc. So what seems to be the problem? You receieve several ID numbers or URLs via POST, and run one or more INSERT queries with this data.
No problem with this, it's just this is what i'm not sure of how to do.
Thanks, Gavin GJ*******@gmail .com wrote: Maybe i should re-phrase my question. I'm using php with a MySQL database, and i would like to know how to insert a new record into a table for each checked item on one form.
OK, let's say you have a form:
<form method="POST" action="insert. php">
<input type="checkbox" name="id[]" value="32">Arti cle #32<br>
<input type="checkbox" name="id[]" value="38">Arti cle #38<br>
<input type="checkbox" name="id[]" value="45">Arti cle #45<br>
<input type="checkbox" name="id[]" value="59">Arti cle #59<br>
<input type="Submit">
</form>
Now, let's assume the user checked articles #32 and #59. These values
will be available to insert.php as fields in $_POST['id'], which in
this case will be an array. So in insert.php you can write:
$query = 'INSERT INTO related_article s (id) VALUES (' .
implode('), (', $_POST['id']) . ')';
$result = mysql_query($qu ery)
or die('Could not execute INSERT query');
That's it, really...
Cheers,
NC
Thanks for the reply NC, the trouble is i don't want the field to be an
array, i want each item that is selected to be inserted into a new row.
So if #32 and #59 were selected, #32 would be inserted into a row, then
a new row would be created to insert #59 into... and so on if there
were more articles selected.
NC wrote: GJ*******@gmail .com wrote:
Maybe i should re-phrase my question. I'm using php with a MySQL database, and i would like to know how to insert a new record into a table for each checked item on one form.
OK, let's say you have a form:
<form method="POST" action="insert. php"> <input type="checkbox" name="id[]" value="32">Arti cle #32<br> <input type="checkbox" name="id[]" value="38">Arti cle #38<br> <input type="checkbox" name="id[]" value="45">Arti cle #45<br> <input type="checkbox" name="id[]" value="59">Arti cle #59<br> <input type="Submit"> </form>
Now, let's assume the user checked articles #32 and #59. These values will be available to insert.php as fields in $_POST['id'], which in this case will be an array. So in insert.php you can write:
$query = 'INSERT INTO related_article s (id) VALUES (' . implode('), (', $_POST['id']) . ')'; $result = mysql_query($qu ery) or die('Could not execute INSERT query');
That's it, really...
Cheers, NC
It also violates first normal form for relational databases.
Rather, something like (for simplicity, no error checking shown):
foreach ($_POST['id']) as $id) {
mysql_query("IN SERT INTO related_table (article_id, related_id) " .
"VALUES ($origId, $id)");
$origId is the original article id, $_POST['id'] is the id(s) of the related
article(s).
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== === GJ*******@gmail .com wrote: Thanks for the reply NC, the trouble is i don't want the field to be an array,
Then tell us a little more about your form, so we can give you advice
appropriate to your situation... Also, why don't you want the field to
be an array?
i want each item that is selected to be inserted into a new row.
This is exactly what this piece of code does. It creates one record
for each selected item. Obviously, the data in the example are
incomplete (the ID of the article to which selected articles are
related is missing, which is probably what prompted Jerry Stuckle's
comment about it violating first normal form for relational databases),
but it was only meant to show you the sequence of steps... Well, let's
try it again, this time with more data...
Let's say you have a form:
<form method="POST" action="insert. php">
<input type="checkbox" name="id[]" value="32">Arti cle #32<br>
<input type="checkbox" name="id[]" value="38">Arti cle #38<br>
<input type="checkbox" name="id[]" value="45">Arti cle #45<br>
<input type="checkbox" name="id[]" value="59">Arti cle #59<br>
<input type="hidden" name="referer" value="123">
<!-- This is the ID of the "referring" article -->
<input type="Submit">
</form>
Then, let's assume the user checked articles #32 and #59. These
values will be available to insert.php as fields in $_POST['id'], which
in this case will be an array. So in insert.php you can write:
$ref = $_POST['referer'];
$query = 'INSERT INTO related_article s (id, referer) VALUES (' .
implode(", $ref), (", $_POST['id']) . ", $ref)";
$result = mysql_query($qu ery)
or die('Could not execute INSERT query');
Here's the query that is going to be executed:
INSERT INTO related_article s (id, referer)
VALUES (32, 123), (59, 123);
This query will create two records in related_article s, one linking
article #32 to article #123, the other linking article #59 to article
#123.
The advantage over Jerry Stuckle's solution is that all necessary
records are created in one query, although I must admit that this
advantage is probably trivial.
Cheers,
NC
Thanks NC
This is exactly what i wanted, sorry if it took a few posts to get
here. Much appreciated.
Gavin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sans Spam |
last post by:
Greetings! I have a table that contains all of the function
permissions within a given application. These functions are different
sections of a site and each has its own permissions (READ, WRITE,
UPDATE, DELETE) which are controlled by a web frontend and the table
records are manipulated to control the permissions.
Example:
The Press Release section record would look like this:
Username: John Doe
Function Name: Press Release
|
by: PT |
last post by:
I got a problem. And thats.....
First of all, I got these three tables.
------------------- ------------------ ----------------------
tblPerson tblPersonSoftware tblSoftware
------------------- ------------------ ----------------------
PID PName PID* SID* SID SWName
--- ----- --- --- --- ------
1 Thomas 1 1 ...
|
by: Joe |
last post by:
Hey,
I'm going to give some background on my situation in case anyone can
point out a way around my problem altogether... for the problem
itself, please skip to the bottom of the post. thanks.
I've been having some problems with database performance... Several
threads are constantly attempting INSERTs of new records into a large
table - that is hundreds of thousands of records -large by my account
:-) The table has a VARCHAR field...
|
by: george |
last post by:
This is like the bug from hell. It is kind of hard to explain, so
please bear with me.
Background Info: SQL Server 7.0, on an NT box, Active Server pages
with Javascript, using ADO objects.
I'm inserting simple records into a table. But one insert command is
placing 2 or 3 records into the table. The 'extra' records, have the
same data as the previous insert incident, (except for the timestamp).
|
by: Mike Hnatt |
last post by:
My goal is to get data from an XML file into a couple of tables in an Access
database. The XML file is a little complex so I need control over what I do
(I can't just read it into a dataset).
The way I have it now is ennumerating through my XML file and for each
record, running an INSERT INTO SQL statement to put the values in the
database.
Is this going to be okay with 50 or so records (hitting the database with 50
or so INSERT...
| |
by: shank |
last post by:
I'm trying to use online samples for submitting multiple records from ASP
into a stored procedure. Failing! Through the below form, a user could be
submitting many records at a time. I'm not getting any records inserted. For
troubleshooting, I cut the form down to 1 textbox and when submitted it
populated 5 rows of the same data. So I know I'm connected, but not getting
the LOOP and NEXT correct? How do I set this up so many records can be...
|
by: Bob Alston |
last post by:
I have a routine to copy data to new versions of my app via insert into
sql statements. Unfortunately, due to evolution of my app, sometimes
the new version has more restrictive editing than an older version that
I am updating. Thus I get this message. It tells me only how many
records have errors, not which errors or which records.
Anyone have a nice solution to identifying the specific records involved?
Maybe even the specific...
|
by: =?Utf-8?B?TG9zdEluTUQ=?= |
last post by:
Hi All :)
I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView.
True DBGrid has a MultipleLines property that controls whether individual
records span multiple lines. Is there an equivalent property for the
DataGridView? I have searched, but have not found one.
I would like the user to be able to see all the columns of the table on one
screen - thus eliminating the need to use the horizontal scroll bar to view...
|
by: chumlyumly |
last post by:
Hello scripters -
OS: Mac OSX
Language: PHP w/ MySQL database
I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The tables are all linked with the field 'member_id', which is an auto-increment field in the parent table ('members').
I've been able to input multiple records into the other three tables 'specialty_groups', 'committee_interest' and 'committee_member'...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |