...

View Full Version : mysql database,row and dvide



arvind
06-10-2006, 10:17 PM
I need to get the amount of rows of the table in mysql datbase, and then devide them through 3, and print them in each of them separately.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php

$testDB = mysql_connect('localhost', 'root', '');
$naamDB = 'test';
@mysql_select_db($naamDB) or die ( " kan database niet vinden ");

for ($i = 0 ; $i < 10 ; $i++)
{
$resultaat = mysql_query("SELECT * FROM test WHERE id = $i ");
if (!$resultaat) {
die('Ongeldige query: ' . mysql_error());
}

while($a = mysql_fetch_row($resultaat)) {


$teller = count($a[0]);
print $a[0];
}

}



// print "<TD>$a</TD>";
//$result = mysql_fetch_array(mysql_query("SELECT * FROM test WHERE id = $i "));




?>

<body>
</body>

chump2877
06-10-2006, 10:41 PM
what exactly you need to do isnt clear, but you'll at least need to use some aplication of mysql_num_rows() : http://us3.php.net/manual/en/function.mysql-num-rows.php

arvind
06-11-2006, 12:59 AM
I got a db called 'test'. I want to calculate how many entry's it has, then devide the result of that into 3, and print 3 times for each the result.

arvind
06-11-2006, 03:24 PM
anyone?

chump2877
06-11-2006, 04:19 PM
and print 3 times for each the result.

print what 3 times??? :eek:

arvind
06-11-2006, 05:20 PM
when i divide the entry's of the mysql db into 3 pieces, i want to print each piece seperatly next to each other.

chump2877
06-11-2006, 07:24 PM
I think you want something like this, but I'm really having a hard time understanding what you want exactly:


<table>
<tr>

<?

$query = "SELECT * FROM table";
$result = mysql_query($query);

$num_rows = mysql_num_rows($result);
$column_count = round($num_rows / 3);
$count = 1;

if ($num_rows >= 1)
{
while ($row = mysql_fetch_assoc($result))
{
if ($count == 1)
{
echo '<td>';
}

echo '<p>' . $row['data'] . '</p>';

if ($count == $column_count)
{
echo '</td>';
$count = 0;
}

if ($count == $num_rows)
{
echo '</td>';
}

$count++;
}
}

?>

</tr>
</table>

arvind
06-12-2006, 11:10 AM
Hi,

this is what I made of it, altough, I can't make the following work:

- I asked all from ontwikkelacties, now I want to print everything from 'ontwikkelacties'. Dived into 3 seperated rows.


<table>
<tr>

<?
$database = 'ambrosia';
mysql_connect('localhost', 'ambrosia', 'popeye');
@mysql_select_db($database) or die( "Kan database niet vinden");

$query = mysql_fetch_array(mysql_query("SELECT * FROM ontwikkelacties WHERE id = '1'"));
//$result = mysql_query($query);
//echo $query['tekst'];

$link =mysql_connect('localhost', 'ambrosia', 'popeye');
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM ontwikkelacties", $link);
$num_rows = mysql_num_rows($result);

//echo "$num_rows Rows\n";


//$num_rows = mysql_num_rows($result);
$column_count = ceil($num_rows / 3);
$count = 1;
echo $column_count;

chump2877
06-12-2006, 01:40 PM
<table>
<tr>

<?

$database = 'ambrosia';
$link = mysql_connect('localhost', 'yourUsername', 'yourPassword');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $link) or die( "custom error message");

$query = "SELECT * FROM ontwikkelacties";
$result = mysql_query($query);

$num_rows = mysql_num_rows($result);
$column_count = round($num_rows / 3);
$count = 1;

if ($num_rows >= 1)
{
while ($row = mysql_fetch_assoc($result))
{
if ($count == 1)
{
echo '<td>';
}

echo '<p>' . $row['data'] . '</p>';

if ($count == $column_count)
{
echo '</td>';
$count = 0;
}

if ($count == $num_rows)
{
echo '</td>';
}

$count++;
}
}

?>

</tr>
</table>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum