You are here: Re: Storing array in a row « PHP Programming Language « IT news, forums, messages
Re: Storing array in a row

Posted by Jerry Stuckle on 11/19/03 11:47

guitarromantic@gmail.com wrote:
> Jerry Stuckle wrote:
>
>
>>First of all, don't store review_type. You can find out if it has multiple
>>reviews by a simple
>>
>> SELECT COUNT(*) FROM multip_reviews WHERE id='1234'
>
>
> My reason for using review_type is that we already have a secondary
> review type (in this case it uses the same database structure, only the
> review body is part of our "200 words or less" feature, and I like to
> mark that visually on the review index).
>

Hmmm, it still isn't a good idea to duplicate information. What happens if for
some reason it gets out of synchronization? It does happen, for one reason or
another, like someone modifying the code and not realizing what needs to be
changed. Then you'll have other problems. And you can still mark it visually
in the review index.

>
>
>>As for inserting multiple values, it's pretty simple. You need to build the
>>query in your foreach loop. First you need to get all of your variables for a
>>single review into an array, i.e. assuming you have your form fields as author1,
>>author2, score1, score2 and review1, review2, etc.: (warning - not tested)
>
>
> Apologies if this is a stupid question, but would this method only
> allow 2 authors to be used when adding a review? Occasionally we use 3,
> there's no single number. Just so I can get my head around this, what
> are the numbers 5 and 6 doing in that code?
>

No, you just continue your numbering mechanism as many as you want. However, an
alternative is to enter one review per page, submit it and come back to the same
page for the next review. Then you don't have to worry about how many reviews
to enter. But if you do submit several per page you'll need to validate the
input (which you really need to do anyway).

>
>>Now that the data is sorted, you can build an insert VALUES clause ($id has the
>>review id)
>>
>> $insert = '';
>> foreach($data as $value) {
>> if ($insert != '') // add a comma if not the first one
>> $insert .= ', ';
>> $insert .= "($id, $value['author'], $value['score'], '$value['review'])";
>
>
> Using this code I get a "Parse error: syntax error, unexpected
> T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or
> T_NUM_STRING" on the final line of the above code. I took out the ' by
> $value, same result.
>

As I said - untested and not guaranteed. And I don't guarantee its valid. But
the problem is there should be another single quote after the last right square
bracket.

> Thanks again for all the help thus far, I'll have to credit you
> somewhere on the site (scenepointblank.com) when this eventually goes
> live!
>
> Matt
>


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

 

Navigation:

[Reply to this 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

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