need help, probly something simple


building a lil site for my boss taking a html template and making it php so everything is stored in a db and i can then have it easily editable for him, anyway here is my problem

my crappy code
[php]mysql_select_db($database_local, $local);
// sample query, get members
$query = mysql_query(“select name from faq_cat”);

// count total number of items to show
$total = mysql_num_rows($query);

// initiate row counter
$counter = 3;

// initiate columns contents
$column_1 = ‘’;
$column_2 = ‘’;
$column_3 = ‘’;
$column_4 = ‘’;
$column_5 = ‘’;
$column_6 = ‘’;
$column_7 = ‘’;
$column_8 = ‘’;
$column_9 = ‘’;
while($row = mysql_fetch_assoc($query)){

// caluculate column for current element from total items to be showed number of     columns and current item
$column = get_column($total, 9, $counter);

if($column == 1){
    $column_1 .= $row['name'];

if($column == 2){
    $column_2 .= $row['name'];
if($column == 3){
    $column_3 .= $row['name'];

if($column == 4){
    $column_4 .= $row['name'];

if($column == 5){
    $column_5 .= $row['name'];
if($column == 6){
    $column_6 .= $row['name'];

if($column == 7){
    $column_7 .= $row['name'];

if($column == 8){
    $column_8 .= $row['name'];
if($column == 9){
    $column_9 .= $row['name'];


// show content in two table comments
echo “<div id=“content”>
<div class=“row-1”>
<div class=“indent”>
<div class=“wrapper”>
<div class=“box”>
<div class=“corner-top-left png”>
<div class=“corner-top-right png”>
<div class=“border-top png”><img src=“images/3page-title1.gif” alt=”" />

<div class=“box-content”>
<div class=“row-3”>
<div class=“wrapper”>
<div class=“col-1”>
<ul class=“list no-padding”>

  • <a href="#">$column_1

  • <a href="#">$column_2

  • <a href="#">$column_3

  • <div class=“col-2”>
    <ul class=“list no-padding”>
  • <a href="#">$column_4

  • <a href="#">$column_5

  • <a href="#">$column_6

  • <div class=“col-3”>
    <ul class=“list no-padding”>
  • <a href="#">$column_7

  • <a href="#">$column_8

  • <a href="#">$column_9

  • ";

    i dont see anything wrong, but for some reason im only getting 1 row in the first column and the last row just conjoins i guess with the other rows.

    heres what its supposed to look like, which yes i know to do what i want i need to learn ajax aswell.

    and heres how it looks now


    Ajax has nothing to do with this issue. Also, it is silly to do all that coding just for nine items.
    Wherever your editing page it, limit it to nine items. Then, if you dump a FAQ, just write “” to the DB.
    In this manner, you always have 9 FAQ’s. You can rename them inside the database, or blank them out
    to “”… Then, in the code you showed us, you would just pull the entire nine items into an array.
    This array, let’s call it “$columns”. To display each you would just
    echo $columns[1], $columns[4], $columns[7]
    $columns[2]. $columns[5], $columns[8]
    $columns[3], $columns[6], $columns[9]
    in your display page… (If #9 is blank, it would not show anything to click on, easy)
    And, no silly “if column_1== something” code. Just one load into an array and all done…
    No setting columns="", no parsing thru them, just something like:

    while(($columns[] = mysql_fetch_assoc($query)) || array_pop($columns));

    I think doing things that way would be faster and easier…


    see my problem is idk how to do all that :frowning: realy i just want to make the site dynamic with php thats all im trying to do


    got it!

    new code:


    <?php include ("Connections/local.php"); include ("includes/gc.php"); mysql_select_db($database_local, $local); // sample query, get members $query = mysql_query("SELECT name FROM faq_cat"); $n_columns = 3; // count total number of items to show $total = mysql_num_rows($query); $num_per_column = ceil($total/$n_columns); // initiate columns contents $rows = array(); while($row = mysql_fetch_assoc($query)){ $rows[] = $row; } ?>
    <?php for($i=0; $i<$n_columns; $i++) : ?>
      <?php foreach(array_slice($rows, $num_per_column*$i, $num_per_column) as $j => $row): ?>
    • <?php echo $row['name']; ?>
    • <?php endforeach; ?>
    <?php endfor; ?>

    now to read up on dynamic content so i can make the catagorys clickable so then the questions appear then once u click on the question it shows anser, unless someone can help with that part here lol sounds like its gunna b a bitch


    Perhaps you just do not understand what I was saying. Your code that you posted went thru a TON of manipulations to create $column_1, $column_2, etc… Not needed. Then it used these like this:

                      <li><a href=\"#\">$column_1</a></li>
                      <li><a href=\"#\">$column_2</a></li>
                      <li><a href=\"#\">$column_3</a></li>

    I gave you one line of code that would load all the names into an array called $columns.
    Then, all you have to do is change the above to be like this:

  • <a href="#">$column[1]

  • <a href="#">$column[2]

  • <a href="#">$column[3]
  • Did that make sense. Normally a dynamic page that pulls it’s data out of a database would be created by a program. You normally wouldn’t pull the data and put it into variables and then stick them into an already created page. You would do it in a program that would have only one

  • <a href=> and loop as many times as needed to display all the data. If there are 7 items, it would repeat 7 times and the extra two spots would be left blank when it runs out of data. But, it still looks like your way would work if you just take out the separate column variables and just use an array…

  • #6

    sorry im totally new at php site coding, only thing i did in php before was just security/ custom encryptions etc for people since i specialize in computer securty.
    anychance anyone can help me make the page so when a catagory is clicked it displays the questions and if a question is clicked it then shows the anser?
    im kinda lost alot of this stuff doesnt make sense :frowning:


    No problem! Glad you “GOT IT”!!! Always a nice warm fuzzy feeling when you get the bugs out of your code! LOL… Glad we could help. Come back with the next problem… (Always seems to be one more …)

    CYA in the bitstream…