E
E
Evgeny Ivanov2018-06-14 07:51:49
PHP
Evgeny Ivanov, 2018-06-14 07:51:49

How to fix the result of a selection from the database?

There is a working code for fetching data from the database.

$result=mysql_query("SELECT `time`,`currency_name` FROM `$table_name` where `time`>UNIX_TIMESTAMP(SUBDATE(CURDATE(),$show_graph_date_begin)) AND `time`<UNIX_TIMESTAMP(SUBDATE(CURDATE(),$show_graph_date_end))  $id_code ") or die (mysql_error());
if ($select_amt >0)
{
for($select_amt; $select_amt>0; $select_amt--)
{
$row=mysql_fetch_assoc($result); 
$cryptocurrency_time=$row['time'];
$cryptocurrency_value=$row['currency_name'];
//....................

We select time and currency_name (time and currency) from the database and draw a graph.
As a result of the code, one unpleasant thing happens.
If there is a value in the currency_name column in the database - for example, a number, then the graph is drawn correctly.
If there is no number in the currency_name column in the database, then time is substituted instead of currency_name.
And, as I understand it (this is no longer accurate), instead of time - nothing. More specifically, the javascript graph itself takes time - setting its start date to 1970.
How to fix the result of a selection from the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PrAw, 2018-06-14
@logpol32

I have an idiotic question - what prevents you from normalizing the data in the database once, so as not to fence crutches?
Why did the name of the currency suddenly become a value?
Why in a field for storage of numerical values ​​in general the text managed to be stored???
At the moment, the situation seems to me like this:
#define TRUE FALSE //happy debugging
For a crutch to solve the problem:

if (!is_numeric($cryptocurrency_value)) continue;
if (!is_numeric($cryptocurrency_time)) continue;

and that's it, if we don't have a date or a number in the currency value - we just skip this entry.
Add in the loop just at the point of code break.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question