justuptime.com - monitor your servers & websites

creating 2 column results mysql php

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

He has: 31 posts

Joined: Jan 2004

HI all..

OK what I'm trying to do is instead of a single row of results show 2 or even 3 rows of database results.

some say its simple but being self taught the only help i get is from example scripts and here.

my page is below if someone can help it would be appreciated.

if (file_exists('../library/config.php')) {
include("../library/config.php");
} else {
include("library/config.php");
}

if (file_exists('../library/opendb.php')) {
include("../library/opendb.php");
} else {
include("library/opendb.php");
}
$ASC = 'ASC';
$query="SELECT * FROM gallery_category ORDER BY category_name ASC";
$result=mysql_query($query);

if (!$result==1) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}

while ($gal = mysql_fetch_assoc($result)) {
myarray=array();
$j=1;
while (next-record-loop)
{
myarray+=array($j=>array('category_id'=>category_id, 'category_name'=>category_name, 'cat_description'=>cat_description));
$j++;
}
echo "";
echo $gal['category_name'];
echo "
";
echo nl2br($gal['cat_description']);
echo "";
}
themesidebox3();
if (file_exists('../library/closedb.php')) {
include("../library/closedb.php");
} else {
include("library/closedb.php");
}

Busy's picture
Modrater

He has: 6,148 posts

Joined: May 2001

Some of the code above you dont need

if (file_exists('../library/opendb.php')) {
include("../library/opendb.php");
} else {
include("library/opendb.php");
}
$ASC = 'ASC';
$query="SELECT * FROM gallery_category ORDER BY category_name ASC";
$result=mysql_query($query);

if (!$result==1) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}

while ($gal = mysql_fetch_assoc($result)) {
myarray=array();
$j=1;
while (next-record-loop)
{

myarray+=array($j=>array('category_id'=>category_id, 'category_name'=>category_name, 'cat_description'=>cat_description));
$j++;
}

I have made the extra bits bold. you don't need the inner while loop. if you want to limit the results, say you have 100 items in your database but only want 10, you'd use limit and even offset

LIMIT 10 // gets first ten results
LIMIT 5,10 // gets 5 results starting at 10 (really 9 as mysql starts at 0)

<?bhb if(broken){ echo("It wasn't me Smiling "); } ?>
Learn HTML the ez way - EzHTML.net

Some people are like slinkies, they dont really serve any purpose but they still bring a smile to your face when you push them down the stairs ...

He has: 31 posts

Joined: Jan 2004

the highlighted line below is causing a pharse error now...

Parse error: parse error, unexpected '=' in /**/**/**/**/**/**/**/index.php on line 31

been sat here looking at other scripts and example sites and still cant figure this one out..

---------------------------------------------------------------------
if (!$result==1) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}

while ($gal = mysql_fetch_assoc($result)) {
[****line 31***]myarray=array();[***line 31***]]
myarray+=array($j=>array('category_id'=>category_id, 'category_name'=>category_name, 'cat_description'=>cat_description));

echo "";
echo $gal['category_name'];
echo "
";
echo nl2br($gal['cat_description']);
echo "";
------------------------------------------------------------------

mairving's picture
Moderator

They have: 2,256 posts

Joined: Feb 2001

Looks like the while loop was opened { but not closed }.

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

He has: 31 posts

Joined: Jan 2004

mairving wrote: Looks like the while loop was opened { but not closed }.

no it does have closure it is just below the last line in the code above.

}

this is not easy like some people say Sad

Busy's picture
Modrater

He has: 6,148 posts

Joined: May 2001

myarray=array();

should be

$myarray=array();

(needs the dollar sign) but really that bit and the following bit

myarray+=array($j=>array('category_id'=>category_id, 'category_name'=>category_name, 'cat_description'=>cat_description));

can/should be removed as they aren't doing anything, the results are coming from the database query loop.

If you leave it, the myarray+= needs a dollar sign too.
just comment it out for now even

// single line comment
/* multi
line
comment */
# to end of line comment (not recommend if you edit in different editors)

<?bhb if(broken){ echo("It wasn't me Smiling "); } ?>
Learn HTML the ez way - EzHTML.net

Some people are like slinkies, they dont really serve any purpose but they still bring a smile to your face when you push them down the stairs ...