Hello,
If anyone could help me or something it would be greatly appreciated. I\'ve been getting help from the penguin (ner0) and we\'ve come up with this code and it\'s not working the way I want it and at the moment I can\'t get ahold of paul. So here goes the explaination of what it should be doing.
This code *should* display 3 of the latest entries from the database inside of a table. This will work for every category I have submitted into the database (The category is submitted inside the table the news is inserted into). I hope this all makes sense. Here is the code.
[code]<?php
$sql_host = "localhost";
$sql_user = "*";
$sql_pass = "**";
$sql_db = "news";
$conn = @mysql_connect($sql_host, $sql_user, $sql_pass) or die("could not connect. mysql said: <br /><br />" . mysql_error());
$select = mysql_select_db($sql_db) or die("cannot select database. mysql said:<br /><br />" . mysql_error());
$query = mysql_query("select * from `news` order by `cat` asc");
$table = array();
while ($temp=mysql_fetch_array($query))
{
$table[$temp[\'cat\']][] = $temp[\'id\'];
}
echo "<table border=1px>\n";
echo " <tr>\n";
// how many columns per row?
$col = 2;
$i = 0;
foreach($table as $key => $val)
{
if ($i === $col)
{
echo " </tr>\n";
echo " <tr>\n";
$i = ($i - 2);
}
echo " <td>\n";
echo " <b>category:</b>{$key}<br />\n";
//------------------
// for each id in this category...
//------------------
foreach ($val as $subval)
{
//------------
// fetch details based on the current id (we\'re looping thru\' \'em)
//------------
$query = mysql_query("select * from `news` where id=\'$subval\' limit 3");
$temp = mysql_fetch_array($query);
//------------
// output details:
//------------
echo " <i>title:</i> {$temp[\'title\']} <br />\n";
}
echo " </td>\n";
$i++;
}
echo "</table>\n";[/code]
Notice how I\'m using a query near the bottom of the script where it should LIMIT 3, but it isn\'t.
Thanks in advanced,
-Dren
[/font][/size]


