MYSQL table structure: id , name , status , color
how can i use PHP to get some data from my database(mysql) ,the php script will look for table rows that have "good" in the "status" column. Then echo those rows which have good in status(P/S out into a JS file. It also get the color from each row (with status=good) and ptu it into javascript(jQUery)
I did a little research on how to use php to generate javascript.
Here's a php script, it's not working btw:
<?php
header("content-type: application/x-javascript");
include 'connect.php';
$sql = "SELECT * FROM users WHERE status ='good'";
$query = mysql_query($sql)or die(mysql_error());
$rows = array();
while($row = mysql_fetch_array( $query )){
$rows[] = $row;
echo "$('a[href*=\"row[username]\"]').css('color', 'row[color]');\n";
}
?>
The out put is (which wont work):
$('a[href*="row[username]"]').css('color', 'row[color]');
The connect.php is working(connects to database) , just the script is not working.
(BTW: The file name of this is usercolor.js.php , is it correct?) I hope someone could guide me.
Thanks and have a wonderful day.
just the script is not working.- in what way is it not working? No output, the javascript is invalid, etc etc - give us a clue!