Hi I am having a problem displaying the 24 H volume name in coinmarketcap api it roduces an error when i call it but other values are working perfectly it may bebecause the 24h volume starts with a number. I want to know how will i get it. Thank you. Here is my current code
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<th>Name</th>
<th>Symbol</th>
<th>Rank</th>
</tr>
<?php
ini_set('max_execution_time', 300);
// $tick = file_get_contents('https://api.coinmarketcap.com/v1/ticker/bitcoin/');
$url ='https://api.coinmarketcap.com/v1/ticker/?start=0&limit=1000';// path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data); // decode the JSON feed
// echo $characters[0]->name;
foreach ($characters as $character) {
echo '<tr>';
echo '<td>' . $character->name . '</td>';
echo '<td>' . $character->symbol . '</td>';
echo '<td>' . $character->rank . '</td>';
echo '<td>' . $character->price_usd . '</td>';
echo '<td>' . $character->price_btc . '</td>';
echo '<td>' . $character->total_24h_volume_usd . '</td>';
echo '<td>' . $character->market_cap_usd . '</td>';
echo '<td>' . $character->available_supply . '</td>';
echo '<td>' . $character->total_supply . '</td>';
echo '<td>' . $character->max_supply . '</td>';
echo '<td>' . $character->percent_change_1h . '</td>';
echo '<td>' . $character->percent_change_24h . '</td>';
echo '<td>' . $character->percent_change_7d . '</td>';
echo '<td>' . $character->last_updated . '</td>';
echo '</tr>';
}
?>
</tbody>sdsdf
</table>
</body>
</html>
In order to access fields named in that fashoin you need to wrap them with {''}. So you need to write $character->{'24h_volume_usd'}.
Related
May i ask how to convert an array to JSON format,
I have tried to used the following method, but fail to do so, any idea?
Here's my current result:
["B型肝炎疫苗下一個注射期为2017-06-30 ","96709394"]
["疫苗名稱4下一個注射期为2017-06-30 ","96709394"]
What i want :
{"B型肝炎疫苗下一個注射期为2017-06-30 ","96709394"},
{"疫苗名稱4下一個注射期为2017-06-30 ","96709394"}
Thank you
while($row = mysql_fetch_array( $result )) {
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['patientid'] . '</td>';
echo '<td>' . $row['vaccineid'] . '</td>';
echo '<td>' . $row['vaccinename1'] . '</td>';
echo '<td>' . $row['totalnoofinjection'] . '</td>';
echo '<td>' . $row['nthinjection'] . '</td>';
echo '<td>' . $row['date'] . '</td>';
echo '<td>' . $row['nextdate'] . '</td>';
echo '<td>' . $row['skip'] . '</td>';
echo '<td>' . $row['traditionalmessage'] ."<br />";
echo '<td>' . $row['traditionalmessage'] . '</td>';
echo '<td>' . $row['telMobile'] . '</td>';
$data_array = [$row['traditionalmessage'],$row['telMobile']];
foreach($data_array as $key => $value){
$new_data_array[urlencode($key)] = urlencode($value);
}
$data_json_url = json_encode($new_data_array);
$data_json = urldecode($data_json_url);
echo $data_json;
<!doctype html>
<?php
?>
<html>
<head>
<title>Midterm Review</title>
</head>
<body>
<h3>Tools Not Currently in Stock</h3>
<?php
$conn = mysqli_connect(This part works );
mysqli_select_db(this part works);
$query = "SELECT * FROM `midterm` WHERE stock='0'";
$result = mysqli_query($conn, $query);
echo '<table>';
echo '<tr><th>ID</th><th>Part Number</th><th>Description</th><th>Stock</th><th>Price</th><th>Received</th></tr>';
foreach ($result as $row) {
$row = mysqli_fetch_array($result);
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
echo '</table>';
};
mysqli_close($conn);
?>
<!--<form method="post" action="midterm_confirmation.php">
<label>Part Number: </label><input type="text" name="partNumber" /><br />
<label>Description: </label><input type="text" name="description" /></br />
<label>Stock: </label><input type="number" name="stock" /><br />
<label>Price: </label><input type="text" name ="price" /></br />
<label>Received Date: </label><input type="text" name="receivedDate" /></br />
<input type="Submit" value="Add to Stock">
</form> -->
</body>
</html>
Basically my end result is that I am getting one table row, instead the two I am getting. Any suggestions? The table I have populates everything but is only running once, instead of posting for each line I have where stock is equal to zero.
See the snippet below. P.S. Don't mix templates and database layer, it's a bad smell...
<?php
// establish connection to $conn variable
$query = mysqli_query($conn, "SELECT * FROM `midterm` WHERE stock='0'");
echo '<table>';
echo '<tr><th>ID</th><th>Part Number</th><th>Description</th><th>Stock</th><th>Price</th><th>Received</th></tr>';
while ($row = mysqli_fetch_assoc($query)) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
}
echo '</table>';
mysqli_close($conn);
?>
The problem is in closing of </table> It should be kept outside the loop.
while ($row = mysqli_fetch_assoc($query)) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
// echo '</table>';// this is wrong.
};
echo '</table>';// this is correct. closing table inside loop is wrong, do it outside the loop.
You can simply use a while loop to do it like below:
<?php
// establish connection to $conn
$query = mysqli_query($conn, "SELECT * FROM `midterm` WHERE stock='0'");
echo '<table>';
echo '<tr><th>ID</th><th>Part Number</th><th>Description</th><th>Stock</th><th>Price</th><th>Received</th></tr>';
while ($row = mysqli_fetch_assoc($query)) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
}
echo '</table>'; // this should be outside the loop
mysqli_close($conn);
?>
Or if you want to use a foreach then write an extra function for it:
<?php
function mysql_fetch_all($result) {
$rows = array();
while ($row = mysql_fetch_array($result)) {
$rows[] = $row;
}
return $rows;
}
// establish connection to $conn
$query = mysqli_query($conn, "SELECT * FROM `midterm` WHERE stock='0'");
echo '<table>';
echo '<tr><th>ID</th><th>Part Number</th><th>Description</th><th>Stock</th><th>Price</th><th>Received</th></tr>';
foreach (mysql_fetch_all($result) as $row){
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
}
echo '</table>'; // this should be outside the loop
mysqli_close($conn);
?>
I have table called reservations. It displays reservations made by users. I want highlight records in current date using end date.
Php code
$result2 = mysql_query("SELECT * FROM reservations WHERE hotel_id = '1' ORDER BY end");
while ($row = mysql_fetch_array($result2)) {
echo '<tr>';
echo '<td class="contacts">' . $row['fname'] . ' ' . $row['lname'] . '</td>';
echo '<td class="contacts">' . $row['start'] . '</td>';
echo '<td class="contacts">' . $row['end'] . '</td>';
echo '<td class="contacts">' . $row['qty'] . '</td>';
echo '</td>';
echo '<td class="contacts">' . $row['room_type'] . '</td>';
echo '<td class="contacts">' . '<a href=out.php?id=' . $row["res_id"] . '>' . 'Check Out' . '</a>' . '</td>';
echo '</tr>';
}
I'd do that at frontend side, but if you want to compute than in PHP, you will need to compare the date from $row and current date and add a class or a style tag to the .
Like so:
$rowHasCurrentDate = $row['date'] == date('Y-m-d');
echo '<tr' + ($rowHasCurrentDate ? ' class="highlight-row"' : "") + '>';
instead of
echo '<tr>';
You can replace the 'class="highlight-row"' with 'style="background-color:red"' if you want to do it without touching frontend side at all.
The example is kinda spaghetti-code, but you can move this logic somewhere else after you get it working.
I am assuming that your start date is current date. This is css thing, i have given you solution to you.
<html>
<head>
<style>
.currdate
{
background-color:red; //change this color to whatever you wish to change to
}
</style>
</head>
<body>
<?php
$result2 = mysql_query("SELECT * FROM reservations WHERE hotel_id = '1' ORDER BY end");
while ($row = mysql_fetch_array($result2)) {
echo '<tr>';
echo '<td class="contacts">' . $row['fname'] . ' ' . $row['lname'] . '</td>';
echo '<td class="contacts currdate">' . $row['start'] . '</td>';
echo '<td class="contacts">' . $row['end'] . '</td>';
echo '<td class="contacts">' . $row['qty'] . '</td>';
echo '</td>';
echo '<td class="contacts">' . $row['room_type'] . '</td>';
echo '<td class="contacts">' . '<a href=out.php?id=' . $row["res_id"] . '>' . 'Check Out' . '</a>' . '</td>';
echo '</tr>';
}
?>
<body>
</html>
I have a PHP Script which lists all Applications from a Databse in a HTML Table. In an own row I want two buttons. Accept and decline
Accept should set the status to "accepted" for the id i klicked on accept.
The Same for decline.
This should update the status in the mysql database.
My Script at the moment:
echo '<table border="1">';
echo '<tr>
<th>ID</th>
<th>Name</th>
<th>Alter</th>
<th>E-Mail</th>
<th>KD</th>
<th>Steam</th>
<th>Spiele</th>
<th>Status</th>
<th>Accept</th>
<th>Decline</th>
</tr>';
while($row = mysql_fetch_object($ergebnis))
{
echo '<tr>';
echo '<td>' . $row->id . '</td>';
echo '<td>' . $row->name . '</td>';
echo '<td>' . $row->age . '</td>';
echo '<td>' . $row->mail . '</td>';
echo '<td>' . $row->kd . '</td>';
echo '<td>' . $row->steam . '</td>';
echo '<td>' . $row->spiele . '</td>';
echo '<td>' . $row->status . '</td>';
echo '</tr>';
}
echo '</table>';
I want my script to be dynamic, so I don't have to refresh the page after every change. Is it possible to do this with jQuery or Ajax? If yes, how do I do it?
change <tr> to <tr class="clickable" data-id="' . $row->id . '">
attach an event handler to tr.clickable
$('tr.clickable').on('click', function(element) {
$.get('changeStatus.php?' + $(element).data('id'));
});
improve the code above
how can i do if this row is empty then it will showing another row
suppose name row is blank
echo '<td>' . $row['name'] . '</td>';
so if name row is blank then it will show echo '<td>' . $row['companyname'] . '</td>'; row
please help me how can i fix this
thanks
echo "<tr>";
echo '<td>' . $row['buildingname'] . '</td>';
echo '<td>' . $row['area'] . '</td>';
echo '<td>' . $row['city'] . '</td>';
echo '<td>' . $row['flatno'] . '</td>';
echo '<td>' . $row['name'] . '</td>';
echo '<td>' . $row['mobileno'] . '</td>';
echo '<td>' . $row['agreementdates'] . '</td>';
echo '<td>' . $row['agreementdatee'] . '</td>';
echo "</tr>";
Try
if(empty( $row['name'])){
$tbl = '<td>' . $row['companyname'] . '</td>';
}else{
$tbl = '<td>' . $row['name'] . '</td>';
}
echo $tbl;
try this i think this is working.
echo '<td>' . empty($row['name']) ? $row['companyname'] : $row['name'] . '</td>';
try this:
echo "<tr>";
if(!empty($row['buildingname'])) {
echo '<td>' . $row['buildingname'] . '</td>';
}
if(!empty($row['area'])) {
echo '<td>' . $row['area'] . '</td>';
}
if(!empty($row['city'])) {
echo '<td>' . $row['city'] . '</td>';
}
if(!empty($row['flatno'])) {
echo '<td>' . $row['flatno'] . '</td>';
}
if(!empty($row['name'])) {
echo '<td>' . $row['name'] . '</td>';
}
if(!empty($row['mobileno'])) {
echo '<td>' . $row['mobileno'] . '</td>';
}
if(!empty($row['agreementdates'])) {
echo '<td>' . $row['agreementdates'] . '</td>';
}
echo "</tr>";