Helpful Information
 
 
Category: MySQL and other databases
data output help

Hi all

I have a script that inputs a link into a database.

the date, li class, url, title and comment are added tot he database.

Outputting these values is fine, but what i want to do is output each set of links under the day they were added. like so


Tuesday 12th
link1
link2
link3
link4

Monday 11th
link 1
link2
link3
link4


all i keep getting is


tuesday 12th
link
tuesday 12th
link


can anyone help point me int he right direction?

I think we'd need the script as well.

<?php
$con = mysql_connect("*****","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("*****", $con);
$result = mysql_query("SELECT * FROM info ORDER BY id DESC");

while($row = mysql_fetch_array($result))
{
$date = $row["date"];
$liclass = $row["class"];
$url = $row["url"];
$title = $row["title"];
$comment = $row["comment"];


echo "<li class='$liclass'><a href='$url' target='_blank'>$title</a>.<br /> $comment </li>"; ; echo "\n";

}
mysql_close($con);
?>
<?php
echo '</ul>';
?>


so far that is all i have managed. basically the script will be a link archive. only one month is visible on the page and each day of that month, previous months are then archived.

<?php
$con = mysql_connect("*****","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("*****", $con);
$result = mysql_query("SELECT * FROM info ORDER BY id DESC");

$dateChk = 0;
while($row = mysql_fetch_array($result))
{
$date = $row["date"];
$liclass = $row["class"];
$url = $row["url"];
$title = $row["title"];
$comment = $row["comment"];
echo "<ul>";
If($dateChk != $date)
{
echo "$date<br><li class='$liclass'><a href='$url' target='_blank'>$title</a>.<br /> $comment </li><br>";
echo "\n";
}
else
{
echo "<li class='$liclass'><a href='$url' target='_blank'>$title</a>.<br /> $comment </li><br>";
echo "\n";
}
$dateChk = $date;
}
mysql_close($con);
?>
<?php
echo '</ul>';
?>

Basically it is your code itself. I've only introduced a new variable

$dateChk = 0;
if you check the while condition and the if statement in it you'll get the correct idea.

Though i haven't checked but if your code is working then this should also work.

Hi

that script works fine. the only problem i seem to be having is that each days date and list of links needs to be in a different UL

the script above will print everything inside a single UL. how do i go about creating the following?

<framset>
<legend>Thursday 14th</legend>
<ul>
<li>Link here</li>
<li>Link here</li>
</ul>
</framset>

<framset>
<legend>Wednesday 13th</legend>
<ul>
<li>Link here</li>
<li>Link here</li>
</ul>
</framset>










privacy (GDPR)