Php & MySQL Programming ?s

Sogni

*gone*
Since I keep starting a buncha threads on the topic, I decided to try and make just one...

As you may or may not know, I've started playing with PHP 'n MySQL under Dreamweaver and have created a few apps to make my life easier (and to learn).

At the moment I'm playing with an app that shows me a table (list) of records, I click on a link that sends me to another page to edit that record, then it takes me back to the list of records...

Below is what I either can't figure out, or would like opinions on:
 
The table list of records has a column called "Status", and basically it has "Available, Active, Reserved, Remove".

How can I make the row change color depending on what the Status is?

For example, I want all "Remove" status to turn the row it's on to a red background, "Available" to blue, "Active" to normal (white), and "Serverd" in Yellow...

Any ideas?
TIA
 
use a CSS. specify four difference classes:
Code:
.statusAvail
	{
	background-color: blue;
	}
.statusRemove
	{
	background-color: red;
	}
.statusActive
	{
	background-color: white;
	}
.statusSeverd
	{
	background-color: yellow;
	}

I normally use HEX codes for colours, but its quicker to type those colours for these purposes.

Then just put a peice of code in to determine the class to use for each row.
Code:
<?php
echo '<tr class="status' . $row[status] . '"><td>Data</td></tr>';
This assumes you are using a table for outputting (it will work with almost any other HTML element that can have a background property though)
Also, $row is the array and [status] the key for the data in the current record of the'status' column. This assumes you are using a while loop (or simmilar) to access the data.


hope it helps.
 
CSS! Of Course!
Man, I just never understood PHP's power! That's awsome!
I did it a different way, but you gave me enough to figure it out. Thanks! :)

This is my TR Entry:
Code:
  <tr class="status<?php echo $row_stuff['status']; ?>">
 
Now I'm trying to sort the list via whatever column header clicked (id, name, address, status, exp)... I made each header text a link with simply "?sortby=id" (=name, =address, etc.), and when clicked the same page reloads with this new ?sortby in the URL...

But i have no idea how to get that into the record set to replace the current "sort by id" to sort by the "?sortby" from the URL...

Any ideas?
 
From the Status Column (see above app), I'd like to be able to list a few stats at the bottom of the page...

Available : #
Active : #
Remove : #

Sounds simple enough to me, but I can't find anything on this either in Dreamweaver, the 'web, or the PHP/MySQL book (for dummies) I have ATM...

TIA
 
Use a counter for each. in the loop to extract each record, include these lines:

Code:
$statusAvailCount++;
$statusRemoveCount++;

and dont forget to initialize each one to 0 BEFORE the loop starts.
then at the bottom just echo the numbers where you want them. alternatively you could get re-query the database to get the data, but i'd suggest the counter method
 
I did a temp fix to requery the database - so I'm requering it 10 times total on that page now! Shesh!

I knew there was a better way, but now I'm coded-out, will experiment with that tomorow. :)

Thanks.
 
It works!
Well, I used it on a secondary page that breaks down each status into it's own table (for trouble listing that need attention), and then gives me the count at the end.

I guess I have to throw in the variable of whatever I'm counting to use it on the main list (that displays all records of all status types). I'll tackle that later. :)
 
Ok, now I'm making a list of entries of future events sorting by date - but I need to expire by date so that entries older than the current date are not shown.

Not sure if I'm being clear... you know what I mean?

Like a band listing gig dates - but don't want to clutter the listing with gigs that alreay happened.

Thanks for the help. :)
 
Another date problem (I still haven't figured out the previous one).
I am calling a date from a database, and I'd like to format it like this for display:
Nov 26 2003

So far nothing I've tried works. I'm trying to do it like this:
Code:
<?php
$showdate = date('M n Y',$row_showsList['Date']);
?>

But that comes back with Dec 12 1969.

Any ideas?
 
It depends how your dates are stored in the database. Different data types need to be displayed in different ways..
 
It's stored as yyyy-mm-dd

I think I'm going to give up trying to reformat the date field and just create Month, Day and Year fields in the database. Saves many headaches. :p :)
 
I think your best bet, is to use a UNIX timestamp in your dB, and then use the php function date(), to format it for however you want. you can of course also use the unix timestamp to work out which records to show. (Get current timestamp, only show those greater than or equal to current timestamp)
 
Back
Top