The way the databases are setup currently is I have a table with the directory categories:
category_id
category_name
In the table that holds the business information I have a row: category_id
which holds the numerical id number of the category instead of the name.
I tried the code below but the result was that it only displayed the last business that joined instead of all in the last 30 days.
Expand|Select|Wrap|Line Numbers
- include('includes/dbconnect.php');
- $query = "SELECT * FROM directory WHERE submitted > SUBDATE(NOW(), INTERVAL 30 DAY) ORDER BY id DESC";
- $result = mysql_query($query);
- $num = mysql_num_rows($result);
- if ($num == 0)
- {
- echo "";
- }
- else
- {
- echo "
- <br><br>
- <strong>Recent Business Additions:</strong> (within last 30 days)<br><br>
- <center>
- <div style='width:75%; text-align:left; border:1px solid #136D86; padding:10px; background-color:#E8E8FF;'>
- ";
- while ($row= mysql_fetch_array($result))
- {
- $id = $row["id"];
- $category_id = $row["category_id"];
- $name = stripslashes($row["name"]);
- $address = stripslashes($row["address"]);
- $city = $row["city"];
- $state_id = $row["state_id"];
- $zip = $row["zip"];
- $phone = $row["phone"];
- $url = $row["url"];
- $bus_desc = nl2br(stripslashes($row["bus_desc"]));
- $show_desc = $row["show_desc"];
- $show_web = $row["show_web"];
- $query = "SELECT category_name FROM d_category WHERE category_id = $category_id";
- $result = mysql_query($query);
- while ($row= mysql_fetch_array($result))
- {
- $category_name = $row["category_name"];
- if ($url && $show_web == '1')
- {
- echo "<a href='http://$url' target='_blank'><strong>$name</strong></a><br>";
- }
- else
- {
- echo "<strong>$name</strong><br>";
- }
- echo "Category: $category_name<br>";
- if ($address)
- {
- echo "$address<br>
- $city, $state_id $zip<br>
- $phone<br>
- ";
- }
- else
- {
- echo "
- $city, $state_id $zip<br>
- $phone<br>
- ";
- }
- if ($url && $show_web == '1')
- {
- echo "<a href='http://$url' target='_blank'>$url</a><br><br>";
- }
- else
- {
- echo "<br>";
- }
- $count++ ;
- }
- }
- }
- echo "</div></center>";
Thanks.