Reply to Re: Storing array in a row

Your name:

Reply:


Posted by Jerry Stuckle on 05/11/06 07:18

guitarromantic@gmail.com wrote:
> Hey everyone,
>
> I run a site with staff-submitted reviews, and most of them are written
> by one author. However, we also do "multiple" reviews. Up until now I
> just had a userid for a 'Multiple' account and submitted them under
> that, but this makes it harder to print lists of all the reviews by one
> person, so ideally I wanna make a multiple select form so we can just
> select all the contributors and have the values saved in the database -
> in one row (something like "56,34,21" etc).
>
> I've coded a multiple select form with all the authors of articles for
> my site on, and I want to store the results of this in one row so I can
> grab them as an array later - how can I go about doing this? I just
> googled and came across using <select name="author[]"> in my HTML, and
> then using serialize() to process it, but it fails. When I run the
> following code, the value for 'multiplearray' remains at 0 whether I
> select single OR multiple values on the form:
>
> <?php
> $dbhost = ###
> $dbuser = ###
> $dbpass = ###
> $dbname = ###
>
> $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
> connecting to mysql');
> mysql_select_db($dbname);
>
> if(isset($_POST['save']))
> {
>
> $author = serialize($_POST['author']);
>
> $query = "INSERT INTO review_test (multiplearray) VALUES
> ('$author')";
> mysql_query($query) or die('Error ,query failed');
> echo "Query successful!";
> }
>
> echo "<form name='test' method='post' action=''>";
>
> $query2 = "SELECT Staff_id, displayname FROM users WHERE
> userlevel !=0
> ORDER BY username";
> $result2 = mysql_query($query2) or die('Error : ' .
> mysql_error());
>
> echo "<select name='author[]' id='author[]' multiple='multiple'
> size='10'>";
> while($row2 = mysql_fetch_array($result2, MYSQL_NUM))
> {
> list($Staff_id, $displayname) = $row2;
> echo "<option value='$Staff_id'>$displayname</option>";
> }
>
> echo "</select>";
> echo "<br><br><input name='save' type='submit' id='save' value='Post
> Review'>";
> echo "</form>";
>
> ?>
>
>
> -----
>
> Matt
>

Matt,

Another table is definitely the way to go. Conistst of two columns - testid and
reviewerid - plus anything else you might have specific to that reviewer on that
test.

Do some searches on "Database Normalization". It will definitely help you much
more in the long run.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация