On Sun, Mar 8, 2009 at 4:52 PM, PJ <af.gour...@videotron.ca> wrote:
> Ashley Sheridan wrote:
>> On Sun, 2009-03-08 at 10:25 -0500, PJ wrote:
>>> My mysql table contains data. But I don't know how to verify what
>>> exactly is the data... is it an array, an integer, an alphanumeric
>>> character or what?
>>> vardump($whatever) returns null; the structure of the table is no null
>>> for the column fields and has been filled like this:
>>> $autoid = 1;
>>> $test = $_POST['categoriesIN']; // this can be several selections from form
>>> $tstring = implode(',' , $test);
>>> echo $tstring.'<br />';
>>> $insert_category = "INSERT INTO book_categories (book_id, categories_id)
>>> VALUES ($autoid, $tstring.)";
>>> mysql_query($insert_category,$db);
>>> retrieval of data is:
>>> from SELECT ...snip...
>>> LEFT JOIN book_publisher as abc ON b.id = abc.bookID
>>> LEFT JOIN publishers AS c ON abc.publishers_id = c.id
>>> LEFT JOIN book_categories AS d ON b.id = d.book_id
>>> LEFT JOIN categories AS e ON d.categories_id = e.id
>>> I have included the publisher stuff - it works, whereas the category
>>> stuff does not...
>> Surely if it is your table, you already know what types of data each
>> field contains?
> I did and do.. I just was not getting the output I was expecting...so I
> panicked and looked for ways to verify all... bit, by bit I went over
> all my little lessons of the past weeks and ...  of course, taking my
> sweet time and lack of knowledge it took me a while to figure out that
> the problem was a missing SELECT table.column from the query. When I
> found the error, everything fell into place.
> But there remains the problem of how to select and display several
> categories from the query. If there isi only one category, there is no
> problem; with more than one I can't figure out how to retrieve it
> without the output showing as many entries for the same book as there
> are categories. Everything is output (echoed) correctly but the books
> are echoed in their entirety along with the category... what could I
> post to analyse the prolem.  I'm sure it's something simple, like
> imploding the array so it isn't repeated... ??

I think you'll probably have to use an ORDER BY clause in your query,
and only output a new book name when it changes during iteration. For

1. grab book categories (book id, book name, category id, category
name) with a JOIN
2. set last book name to "" (empty string)
3. for each row in the result set
3a. if book name is different than last book name, output it
3b. output category
3c. next


// Todd

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to