Jump to content

Recommended Posts

I an new to this, still learning all the way.

I have a table with more than 100 entries, each entry is different, but on one column I want to use 1 of three images to display in each entry.

Want to do it in LEGIT, 3 images, red, yellow and green light to show

This is my code, that I have, I do not know what more to give you

PHP

<?php

if (isset($_GET['COIN_ID'])) {

    $COINGECKO_COIN_ID = $_GET['COIN_ID'];

    $sql = mysqli_query($conn,"SELECT * FROM coingecko_coin_custom_informaton WHERE COINGECKO_COIN_ID = '$COINGECKO_COIN_ID' ");
    $row = mysqli_fetch_array($sql);

    do{

        $COINGECKO_COIN_ID = $row['COINGECKO_COIN_ID'];
        $COINGECKO_TOTAL_COIN = $row['COINGECKO_TOTAL_COIN'];   
        $COINGECKO_LEGIT = $row['COINGECKO_LEGIT'];
        $COINGECKO_LINK = $row['COINGECKO_LINK'];  
        
    }while($row = mysqli_fetch_array($sql));

}

 

Here is my html

 

<tr>
                                    <td><font color="#EFE1CE"><b><label for="firstNum1"><?php echo $coingecko_name; ?></label></b></FONT></td>
                                    <td style="color:#EFE1CE"><?php echo $COINGECKO_ID; ?></td>
                                    
                                    
                                    <td style="color:#EFE1CE"><?php echo $checkSqlRow["COINGECKO_LEGIT"]; ?></td>

                                    <td style="color:#EFE1CE"><?php echo $coingecko_rank; ?></td>

 

Your html code:

<?php
echo "
<tr>
<td><b><label for='firstNum1'>$coingecko_name</label></b></td>
<td style='color:#EFE1CE'>$COINGECKO_ID</td>
<td style='color:#EFE1CE'>{$checkSqlRow["COINGECKO_LEGIT"]}</td>
<td style='color:#EFE1CE'>$coingecko_rank</td>
";

A few var names that are not defined (to us).  And a bit cleaner just by using php to do your output.

Now - what is the problem?  You did not tell us.  And where is your attempt to make some kind of selection of the image you want to be chosen?

BTW.  Note that I removed your use of the deprecated 'font' tag.  Your use of CSS later on is much preferred nowadays.

Edited by ginerjm
  • Like 1
1 hour ago, ginerjm said:

Your html code:

<?php
echo "
<tr>
<td><b><label for='firstNum1'>$coingecko_name</label></b></td>
<td style='color:#EFE1CE'>$COINGECKO_ID</td>
<td style='color:#EFE1CE'>{$checkSqlRow["COINGECKO_LEGIT"]}</td>
<td style='color:#EFE1CE'>$coingecko_rank</td>
";

A few var names that are not defined (to us).  And a bit cleaner just by using php to do your output.

Now - what is the problem?  You did not tell us.  And where is your attempt to make some kind of selection of the image you want to be chosen?

BTW.  Note that I removed your use of the deprecated 'font' tag.  Your use of CSS later on is much preferred nowadays.

Thank you

I did not give my attempt, as I do not know on how to do the image (Have nor any idea on how to do it, as I am new to php, I did add a lot of new code to what I have received from a person .

 

What i trying to get is, I have a html table, with more than 100 tokens in the table.

1 of my columns id for (legit), at the moment I type in "Yes" / "No" or "not at the moment"( easy to do for each one, when I add it in my admin file), bur I wnt to use 3 images on it (red/ green and yellow(this is where I do not know how to use it, how do add it in my admin file. So when I update any one of the tokens, I can use any on of the three images.

 

we don't know what your data is and don't know what result you want to produce from that data, so, your description doesn't make any sense.

please post some sample data (not a picture of your data) and show or describe what result you want to produce from that data.

as to the posted php code -

  1. validate all input data before using it. what should your code do if $_GET['COIN_ID'] isn't set, is empty, or doesn't contain an integer value greater than zero? since this is a required input for the code to work, you need to setup a user message stating that a required coin id was not supplied, and then not run the rest of the code that's dependent on that input.
  2. don't copy variables to other variables for nothing. this just a waste of your time typing. just use the original variables.
  3. don't put external, unknown, dynamic values directly into an sql query statement. use a prepared query instead.
  4. if this query will match at most one row of data, just directly fetch it, no loop is needed. if this query can match a set of zero or more rows of data, you would need to fetch the data into an array, then test/loop over the array to produce the output. the current code overwrites each row of fetched data with the next row, leaving you with only the last row of data.
  5. generally, do/while loops are not used since you must test if there's data to fetch at all, requiring more code. the current code will produce php errors if the query didn't match a row, and leave you needing to still add missing logic at the point of  producing the output to display a message for the case where there is no matching data.

 

6 minutes ago, ginerjm said:

NO idea what you are asking.  So far It's all about a table, not php.

OK, will give the code,  did not do changes yet as you said I must change.

Let met try again to explain. See picture.

I am now confused do I use php for it in the table (Legit) one.

<table class="table-sortable mt32 customers-list" id="datatable">
			 <thead>
					<tr>
						<th height="50">Naam</th>
						<th height="50">Id</th>
						<th height="50">Bestaan Munt Nog</th>
						<th height="50">Rang</th>
						<th height="50">Skakel</th>
						<th height="50">Munt Skakel</th>
                        <th height="50">Blokketting</th>
						<th height="50">Waar</th>
						<th height="50">Beursie Nommer</th>
						<th height="50">Beursie</th>
						<th height="50">Geverifieer</th>
                        <th height="50">Prys</th>
						<th height="50">Dag</th>
						<th height="50">Week</th>
						<th height="50">Maand</th>
						<th height="50">Jaar</th>
						<th height="50">Munte</th>
						<th height="50">Usd</th>
						<th height="50">Zar</th>
					</tr>
			</thead>

			<tbody>
                <?php

                    $total_multiply1 = 0;
                    $total_multiply11 = 0;
                    $total_multiply111 = 0;


                    //Fetching CoinMarketCap table data
                    
                    if($fetchCoinMarketCapRowCount > 0){

                        foreach($decoded_json_coinMarketCap['data'] as $coinMarketCap) {
                            // echo "<script>alert('HELLO');</script>";
                            
                            $COINMARKETCAP_ID = $coinMarketCap['id'];
                            $COINMARKETCAP_name = $coinMarketCap['name'];
                            $COINMARKETCAP_symbol = $coinMarketCap['symbol'];
                            $COINMARKETCAP_slug = $coinMarketCap['slug'];
                    
                            $COINMARKETCAP_name = htmlentities($COINMARKETCAP_name, ENT_QUOTES, "UTF-8");
                    
                            $COINMARKETCAP_rank = $coinMarketCap['cmc_rank'];
                            $COINMARKETCAP_price = $coinMarketCap['quote']['USD']['price'];
                            
                            $COINMARKETCAP_24h_change = $coinMarketCap['quote']['USD']['percent_change_24h'];
                            $COINMARKETCAP_7d_change = $coinMarketCap['quote']['USD']['percent_change_7d'];
                            $COINMARKETCAP_30d_change = $coinMarketCap['quote']['USD']['percent_change_30d'];


                            $coinMarketCap24hColor = colorSet($COINMARKETCAP_24h_change);
                            $coinMarketCap7dColor = colorSet($COINMARKETCAP_7d_change);
                            $coinMarketCap30dColor = colorSet($COINMARKETCAP_30d_change);


                            $checkSql = mysqli_query($conn,"SELECT * FROM coinmarketcap_coin_custom_info WHERE COIN_SYMBOL = '$COINMARKETCAP_symbol' ") or die(mysqli_error($conn));
                            $checkSqlRow = mysqli_fetch_array($checkSql);
                            $checkSqlCount = mysqli_num_rows($checkSql);

                            $COINMARKETCAP_price = sprintf('%.16f', floatval($COINMARKETCAP_price));

                            do{
                                $multiply111 = $COINMARKETCAP_price * $checkSqlRow["TOTAL_COIN"];
                                
                                if($multiply111 != 0){
                                    $multiply111 = sprintf('%.16f', floatval($multiply111));
                                }
                                
                                $total_multiply111 += $multiply111; ?>

                                <tr>
                                    <td><font color="#EFE1CE"><b><label for="firstNum1"><?php echo $COINMARKETCAP_name; ?></label></b></FONT></td>
                                    <td style="color:#EFE1CE"><?php echo $COINMARKETCAP_symbol; ?></td>
									<td style="color:#EFE1CE"><?php echo $checkSqlRow["LEGIT"]; ?></td>
									<td style="color:#EFE1CE"><?php echo $COINMARKETCAP_rank; ?></td>

                                    <td>
                                        <a href="<?php echo $checkSqlRow["LINK"]; ?>" target="_blank">
                                         
											<img src="<?php echo $decoded_json_coinMarketCap_logo["data"]["$COINMARKETCAP_symbol"]["logo"]; ?>" width="32px"></img>
                                        </a>
                                    </td>
									
									<td>
                                        <a href="<?php echo $checkSqlRow["SITE"]; ?>" target="_blank">
										<img src="link.png" width="32px"></img>
                                         									
                                        </a>
                                    </td>
									<td style="color:#EFE1CE"><?php echo $checkSqlRow["BLOCKCHAIN"]; ?></td>
									<td style="color:#EFE1CE"><?php echo $checkSqlRow["WHERE_NOW"]; ?></td>
									<td style="color:#EFE1CE"><?php echo $checkSqlRow["WALLET_NO"]; ?></td>
									 <td style="color:#EFE1CE"><?php echo $checkSqlRow["WALLET"]; ?></td>
									  <td style="color:#EFE1CE"><?php echo $checkSqlRow["VERIFIED"]; ?></td>

                                    <td id="firstNum2" style="color:#EFE1CE"><?php echo $COINMARKETCAP_price; ?></td>

                                    <td id="num1For24H" style="color:<?php echo $coinMarketCap24hColor; ?>"><?php echo round($COINMARKETCAP_24h_change,2); ?></td>
                                    <td id="num1For7D" style="color:<?php echo $coinMarketCap7dColor; ?>"><?php echo round($COINMARKETCAP_7d_change,2); ?></td>
                                    <td id="num1For30D" style="color:<?php echo $coinMarketCap30dColor; ?>"><?php echo round($COINMARKETCAP_30d_change,2); ?></td>
                                    <td id="num1For365D" style="color:white">NULL</td>

                                    <td id="secondNum2" style="color:#EFE1CE; font-weight:bold"><?php echo $checkSqlRow["TOTAL_COIN"]; ?></td>
                                    
                                    <td><input class="total-usd glow" type="text" id="<?php echo $COINMARKETCAP_symbol; ?>1" name="result5" value="<?php echo $multiply111; ?>" style="color:lime; background-color:black; font-weight:bold"/></td>
							
									
								        <script type="text/javascript">

                                        $(document).ready(function() {

                                            var COINMARKETCAP_symbol = '<?=$COINMARKETCAP_symbol?>';
                                            var multiply111 = '<?=$multiply111?>';
                                            var valueInZAR = $("#gcw_valFpWbgYyUL1").val();
                                            var multiply222_total = multiply111 * valueInZAR;

                                            // alert(multiply22_total);
                                            if(multiply222_total!=0){
                                                multiply222_total = multiply222_total.toFixed(10);
                                            }

                                            $("#"+COINMARKETCAP_symbol).val(multiply222_total);
                                            // alert(COINMARKETCAP_symbol);


                                        });

                                    </script>

                                    <td><input class="total-usd glow" type="text" id="<?php echo $COINMARKETCAP_symbol; ?>" name="result6" style="color:lime; background-color:black; font-weight:bold"/></td>
                                </tr>


                                <?php

 

Screenshot_85.png

You do realize that php is case-sensitive and your usage of upper and lower variable names is gonna bite you right in the ass soon.  Strongly suggest to stop.

And now - good bye.  You're on your own.  You say you are still learning but you seem to have produced an awful lot of code so far.

4 minutes ago, ginerjm said:

You do realize that php is case-sensitive and your usage of upper and lower variable names is gonna bite you right in the ass soon.  Strongly suggest to stop.

And now - good bye.  You're on your own.  You say you are still learning but you seem to have produced an awful lot of code so far.

Yes thank you, did get this code from a professional php person ( he said he has written a lot for customers, and I have paid him for this  work).

 

Hope you feel better later on

Edited by hendrikbez

So if you got this code from someone and if you don't know what it is, why aren't you asking him?  Because he's not around anymore?  Good luck then. IMHO he is not a very good programmer or he wouldn't have used mixed cases like that.  Horrible practice. And certainly not such long variable names that make reading thru any code a tedious effort.

And in your example, I don't see ANY images.  And how do they fit into this grid/table of yours?

this code is very bad, and doesn't even contain any comments, useful or otherwise.

however, now that you have posted some information, your description makes sense. the wording for that column is in $checkSqlRow["LEGIT"].

is the stored wording consistent, i.e. are there only three values and are they always spelled and capitalized the same?

next, for each possible wording, you need to map the value to the image path/name. the simplest way of doing this is to store this mapping in an array variable, with the wording as the array index, and the image path/name as the array value. at the current point of echoing $checkSqlRow["LEGIT"], you would instead test if the value/index is in the array. if it is, get the image path/name and output it in an <img ...> tag. if it is not, you would either output the wording, some default text, such as n/a, or output a default image.

Looking at the screenshot and your code, it seems like the following variable is the one you will use to determine which of the 3 images to display.

$checkSqlRow["LEGIT"]

 

Your screenshot suggests this variable will contain one of the following values:

  • weet nie
  • nee
  • ja

 

One option would be to test for those values in an if / elseif statements to determine which image to display. For example, if the green image is to be displayed for "ja" and red for "nee", you could do something like this:

<?php
$checkSqlRow["LEGIT"] = strtolower($checkSqlRow["LEGIT"]);  //make sure the value is lower case before testing
if($checkSqlRow["LEGIT"]     == 'ja')       { echo '<img src="green.gif">';  }
elseif($checkSqlRow["LEGIT"] == 'nee')      { echo '<img src="red.gif">';    }
elseif($checkSqlRow["LEGIT"] == 'weet nie') { echo '<img src="yellow.gif">'; }
?>

 

Note that the image names (and the path) will need to be adjusted to whatever you are using.

  • Like 1
2 hours ago, cyberRobot said:

Looking at the screenshot and your code, it seems like the following variable is the one you will use to determine which of the 3 images to display.

$checkSqlRow["LEGIT"]

 

Your screenshot suggests this variable will contain one of the following values:

  • weet nie
  • nee
  • ja

 

One option would be to test for those values in an if / elseif statements to determine which image to display. For example, if the green image is to be displayed for "ja" and red for "nee", you could do something like this:

<?php
$checkSqlRow["LEGIT"] = strtolower($checkSqlRow["LEGIT"]);  //make sure the value is lower case before testing
if($checkSqlRow["LEGIT"]     == 'ja')       { echo '<img src="green.gif">';  }
elseif($checkSqlRow["LEGIT"] == 'nee')      { echo '<img src="red.gif">';    }
elseif($checkSqlRow["LEGIT"] == 'weet nie') { echo '<img src="yellow.gif">'; }
?>

 

Note that the image names (and the path) will need to be adjusted to whatever you are using.

Thank you, for information, it is working

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.