Jump to content

furiousweebee

Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

furiousweebee's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, that worked perfectly. And yeah, I don't know why the database was structured that way. It's a quotes module from CMS Made Simple and there was no way to display all records at once (only a random or sequential record). Pretty silly. Anyway thanks again - I really appreciate it.
  2. Howdy, I'm trying to display text from a table in a database. It's a list of quotes, so I just need to pull out the quote and the author name. However, the quote and name are not fields in the same record; they are separate records. Example data: quoteid name value 1 content You guys are great! Thanks for being awesome. 1 author John Jackson 2 content Gosh you're amazing! Always been so darn helpful! 2 author Peter Davis So, I just need to rip out the data from 'content' and 'author', and then group them together based on the quoteid. This is my code thus far: $testimonial_resource = mysql_query("SELECT name, value FROM quotes GROUP BY quoteid ORDER BY author ASC") or die(mysql_error()); while ($testimonial = mysql_fetch_assoc($testimonial_resource)) { echo '<p>'.$testimonial['value']'.<br /><strong>'.$testimonial['value'].'</strong></p>'; } Any help would be greatly appreciated for this novice. Cheers.
  3. Hi, I've created a page of links, each assigned a category. There are two tables - "favourites_links" and "favourites_categories". This is how the information currently appears: Category 1 Name Link 1 Link 2 Link 3 Category 2 Name Link 1 Link 2 Link 3 I have also set my code to automatically start a new column once a certain number of links have been reached, so that my columns end up approximately equal in height. The problem is, if the current column has finished but the current category is still listing its links, then the next column shows those links, but without the category title. What I would like to do is ensure that links ALWAYS stay with their parent category, so that in the end, all columns remain approximately equal in height, except for the last column, which can be any height. Here is my code: <?php $resource = mysql_query("SELECT l.id id, l.cat_id cat_id, c.title cat_title, l.title title, l.link link, l.home home, l.work work FROM favourites_links l INNER JOIN favourites_categories c ON l.cat_id = c.id ORDER BY cat_id") or die(mysql_error()); // count the rows $num_rows = mysql_num_rows($resource); // maximum number of rows to show per column $max_rows = ceil($num_rows / 3); // starting row count $row_count = 1; echo '<div class="column">'."\n"; while ($current_page = mysql_fetch_assoc($resource)) { if ($row_count <= $max_rows) { if (!isset($category) || $category != $current_page['cat_title']) { $category = $current_page['cat_title']; echo '<h2>'.$category.'</h2>'."\n"; } echo '<a href="http://'.$current_page['link'].'">'.$current_page['title'].' '.$row_count.'</a>'."\n"; } else { echo "\n".'</div>'."\n".'<div class="column">'."\n"; $row_count = 0; } $row_count++; } echo '</div>'."\n"; Any help would be greatly appreciated!
  4. Hi, I'm making a page of links, each assigned a category. There are two tables - "favourites_links" and "favourites_categories". This is how the links currently appear: Category 1 Name Link 1 Link 2 Link 3 Category 2 Name Link 1 Link 2 Link 3 What I want to do is break my page into columns. Basically, set a number of columns (e.g. 3), count the total records, and work out how many records to show per column. Each column should be enclosed in a <div class="column"> wrapper, which floats to the left. This is how my page should appear once this is done: Category 1Category 4Category 7 Category 2Category 5Category 8 Category 3Category 6Category 9 Here is my current code: $resource = mysql_query("SELECT l.id id, l.cat_id cat_id, c.title cat_title, l.title title, l.link link, l.home home, l.work work FROM favourites_links l INNER JOIN favourites_categories c ON l.cat_id = c.id ORDER BY cat_id") or die(mysql_error()); // count the rows $num_rows = mysql_num_rows($resource); // maximum number of rows to show per column $max_rows = ceil($num_rows / 3); // starting row count $row_count = 1; echo '<div class="column">'; while ($current_page = mysql_fetch_assoc($resource)) { if ($row_count < $max_rows) { if (!isset($category) || $category != $current_page['cat_title']) { $category = $current_page['cat_title']; echo '<h2>'.$category.'</h2>'; } echo '<a href="http://'.$current_page['link'].'">'.$current_page['title'].'</a>'."\n"; } else { echo '</div><div class="wrapper">'; $row_count++; } } echo '</div>'; Any help would be greatly appreciated!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.