0

I have an issue with my while loop that I'm using. I'm trying to display several modules on my webpage, each of them are stored within my database.

I run the following mysql query.

$modules = mysql_query("SELECT * FROM category WHERE active = '1' ORDER BY ordering ASC"); and then while($allmodules = mysql_fetch_array($modules)) {

This then returns the relevant data that I'm looking for, all that works fine.

I am able to display these 'modules' on the webpage easily, but I'm trying to store them in other DIVs which will then create rows. So I can have 3 rows of modules on the webpage to help positioning and so on.

I'm using <div id="module-row"> 3 times over. When I'm not using PHP I can get it to work. I want to insert the first module I fetch from the while statement in to the first 'module-row' DIV and the second one in the second 'module-row' DIV and the third module, in the third DIV.

That way I'll have one module in each row. I then want to continue it, so the fourth module will then be placed in the first 'module-row' DIV and so on.

2
  • 1
    Remember: two HTML elements on the same page should never have identical id's Commented Jun 22, 2012 at 18:03
  • When I tested without the PHP I used different ID's but I weren't sure where I stand with the PHP loop. Commented Jun 22, 2012 at 18:04

3 Answers 3

2

Your question is a little fuzzy, but it sounds like you're having trouble inserting the fetched data into the appropriate DIV tags.

ID attributes are assumed to be unique, i.e. once an ID is used, it is not used again on that page. Try replacing the ID attribute with a class attribute, like so <div class="module-row">, then access the divs by class name instead of ID.

Sign up to request clarification or add additional context in comments.

1 Comment

I understand. Say I had <div id="module-row1">,<div id="module-row2"> and <div id="module-row3"> with the same CSS properties. How would I take the first result from the loop and place it within the module-row1 DIV? and then how would I place the second within the `module-row2' DIV. Hopefully that's cleared it up a little.
1

If your table has an id and data column, it'd look something like this:

while($allmodules = mysql_fetch_assoc($modules)) {
    echo '<div class="module-row'.$allmodules['id'].'">'.$allmodules['data'].'</div>';
}

Comments

0

If your table has an id and data column, it'd look something like this:

while($allmodules = mysql_fetch_assoc($modules)) {
    echo '<div class="module-row'.$allmodules['id'].'">'.$allmodules['data'].'</div>';
}

the answer on above is true but i suggest use php query, use require_once function before you have to include insert_db.php belong to [head] so become just use

echo [div class="require_one $database_name"] *please change symbol [div] be <...> ... is div tag

note : remeber if you use sql query to your page it can risk for security system.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.