Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am getting price values from mysql database table with the given php code
$sql="SELECT DISTINCT (price) FROM 'table' order by price asc";
$res=mysql_query($sql);
while($row=mysql_fetch_array($res))
{
$price=number_format($row[price]);
}
$price=implode(',',$price);
The result is 2,299,4,600,5,800,8,000,12,700,16,900,23,978,27,098
but i want to display the result as
$2,500 or less,$5,000 or less,$7,500 or less,$10,000 or less,$15,00 or less,$20,000 or less,$25,000 or less,$30,000 or less
Can anyone tell me how o fix this problem
$price = '$' . number_format(ceil($row['price']/2500.0)*2500) . ' or less';
The ceil function takes a floating-point number and returns the next-highest integer. By dividing by 2500.0 and then multiplying again, we get the next-highest multiple of 2500.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I stored the month name in database as string which looks like
Apr-2013
May-2013
...
How could i sort the table month wise ?
Any help is appreciated.
You will have to format the date in order to sort it:
select aDate from t
order by str_to_date(aDate,'%b-%Y')
This is very inefficient, though. I'd recommend you to update that field and make it a date field or at least two ints: one for the month and one for the year. Then, if you need to get the name of the month you could use the monthname(date) function.
SELECT
*
FROM
dates
ORDER BY
STR_TO_DATE(date, '%b-%Y')
SQL Fiddle
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can display my database dates when I am getting rows from select query? Here is my code:
mysql_connect(db_server, db_user, db_pass);
$result = mysql_db_query(db_name,"SELECT * FROM user ORDER BY user_id DESC LIMIT 5");
while ($row = mysql_fetch_array($result)) {
echo "<td>" . $row['sign_up_stamp'] . "</td>";
}
database outputs 2147483647
How can I display my the actual date instead of the database enumeration?
echo date('m/d/Y', 2147483647);
or for user variable specific:
echo date('m/d/Y', $row['sign_up_stamp']);
this mistake because of wrong field type in your database design.
put your field type to datetime or if you like to use time stamp you must format it with date functions in php
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$nr333 = mysql_query("SELECT COUNT(*) AS cnt FROM (
SELECT * FROM games
WHERE human = '".mysql_real_escape_string($_GET[human])."'
ORDER BY id DESC LIMIT 100
) tmp WHERE changed = 'y'", $link) or die(mysql_error());
$frecventa333 = mysql_num_rows($nr333);
so bassicaly i dont get any error but .. instead of getting the real number i get just 1:|
http://s017.radikal.ru/i414/1310/a2/37958f7cdb48.png
That's because COUNT returns only one row, always. But in that row you'll find field with all rows counted, in one integer.
Try to fetch that row.
And next thing you should do is checking PDO extension. It's better than deprecated mysql_* functions and isn't so hard to learn.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$result2 = $db->prepare('SELECT `lkey_member` FROM mxscript_slayer_licensekeys WHERE `lkey_key` = ?');
$result2->bindParam(1, $auth);
$result2->execute();
How can I print the value of lkey_member from result2?
First fetch it, then echo it. In this case you can use the fetchColumn function PDO has by specifying the index of the column you want to fetch (in this case the only one you are retrieving):
$lKeyMember = $result2->fetchColumn(0);
echo $lKeyMember;
As from http://www.php.net/manual/en/pdostatement.fetch.php
/* Exercise PDOStatement::fetch styles */
//..print("PDO::FETCH_ASSOC: ");
//..print("Return next row as an array indexed by column name\n");
$result = $result2->fetch(PDO::FETCH_ASSOC);
print_r($result);
$result[0] may be helpful
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am using mysql as database and saved time as time stamp of related posts in table, now i want to fetch the post made rrecently . How can i compare and fetch the post made recently?
you can fetch rows in descending order of your column (time_stamp).
ex:
SELECT * FROM Table_Name ORDER BY col_time_stamp DESC;
col_time_stamp : is the column
select top 1 * from posts order by timestamp desc
try this
SELECT * FROM Table_Name ORDER BY col_time_stamp DESC LIMIT 0;