Log in

View Full Version : Resolved php syntax



john0611
03-12-2009, 05:19 PM
Hi all, Any ideas on the correct syntax with the Date here:confused:

<?php
// query db
$sql = mysql_query ("SELECT listingid, Title, Date FROM `track-listing` ORDER BY Date ASC");
// echo linked result from db
while ($row = mysql_fetch_assoc($sql)){
echo "<a href='track-listings.php?listingid={$row['listingid']}'>" . ucwords(strtolower($row['Title']['Date'])) . "</a><br>";
}
?>

open to any suggestions, John:)

JasonDFR
03-12-2009, 06:21 PM
ucwords(strtolower($row['Date'])) . "</a><br>";

john0611
03-12-2009, 11:56 PM
Here is the code, I am just not sure how to wright it correctly, without errors.

I need to be able to view both the title & the Date:)

<?php

// query db
$sql = mysql_query ("SELECT listingid, Title, Date, DATE_FORMAT(Date, '%d-%m-%Y') as Date FROM `track-listing` ORDER BY Date DESC");
// echo linked result from db
while ($row = mysql_fetch_assoc($sql)){
echo "<a href='track-listings.php?listingid={$row['listingid']}'>" . ucwords(strtolower($row['Title'])) . ucwords(strtolower($row['Date'])) "</a><br>";
}
?>

Schmoopy
03-13-2009, 12:16 AM
add a "." after echoing the $row['date'] variable:



<?php

// query db
$sql = mysql_query ("SELECT listingid, Title, Date, DATE_FORMAT(Date, '%d-%m-%Y') as Date FROM `track-listing` ORDER BY Date DESC");
// echo linked result from db
while ($row = mysql_fetch_assoc($sql)){
echo "<a href='track-listings.php?listingid={$row['listingid']}'>" . ucwords(strtolower($row['Title'])) . ucwords(strtolower($row['Date'])) . "</a><br>";
}
?>


This concatenates the string, you must form an echo like so:


echo "Hello " . $user . "!";

So it knows where that variable starts and ends and adds any extra string parts to the beginning and end.

You almost had it right :)